/
infoScreen.ino
221 lines (164 loc) · 7.85 KB
/
infoScreen.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
/*info screen*/
#define infoScrnRgnSize 4
ActionRegion infoScrnARgn[infoScrnRgnSize];
//#define returnRgn 0 already defined.
#define nameRgn 1
#define ipRgn 2
#define resetRgn 3
#define fwRgn 4
TimeRelease resetEnableDelay;
bool infoRgnPushed(int x, int y){
if(resetEnableDelay.check()|| !resetEnableDelay.isRunning()){
for (uint8_t rgn = 0; rgn < infoScrnRgnSize; rgn++) {
if(infoScrnARgn[rgn].contains(x,y,true)){ //true here causes the hooked event to fire if this return true.
#ifdef _debugopra
Serial.print("infoRgnPushed: ");
Serial.println(rgn); //finished test event text assertion
#endif
return true; //could remove this so that if you have over laping items, it can call all of them as pressed. Need to make sure to return true somehow though.
}
}
}else{
#ifdef _debugopra
//Serial.println("Delaying");
#endif
}
return false;
}
void infoScrnARgn_hm(){//send user to home screen.
#ifdef _debugopra
Serial.println("infoScrnARgn_hm");
#endif
currentScreen = 0;
initHomeScreen();
}
void infoScrnARgn_Rst(){
//set reset trigger.
#ifdef _debugopra
Serial.println("infoScrnARgn_Rst");
#endif
resetTimeDelay.set(500UL); //need to give it more time so that the web page shows the message.
needReset = true;
}
void setInfoScreenText(){
//update text on info screen.
Serial.println("setInfoScreenText()");
//setup text regions
tft.setTextDatum(TL_DATUM); // Use top left corner as text coord datum
tft.setTextColor(TFT_YELLOW); // Set the font colour
String displayString = "";
String leadDisplayString = "";
tft.setTextDatum(TL_DATUM); // Use top left corner as text coord datum
tft.setTextColor(TFT_YELLOW); // Set the font colour
//infoScrnARgn[0] has no text!
leadDisplayString = "HostName: "; displayString = String(wificonfig.hostname);
tft.fillRect(infoScrnARgn[nameRgn].region.x, infoScrnARgn[nameRgn].region.y, infoScrnARgn[nameRgn].region.w, infoScrnARgn[nameRgn].region.h, TFT_BLACK);
tft.setTextColor(TFT_WHITE); // Set the font colour
infoScrnARgn[nameRgn].region.w = tft.drawString(leadDisplayString,infoScrnARgn[nameRgn].region.x,infoScrnARgn[nameRgn].region.y); //return is the new length of the displayed text.
tft.setTextColor(TFT_YELLOW); // Set the font colour
infoScrnARgn[nameRgn].region.w += tft.drawString(displayString,infoScrnARgn[nameRgn].region.x + infoScrnARgn[nameRgn].region.w,infoScrnARgn[nameRgn].region.y); //return is the new length of the displayed text.
leadDisplayString = "IP: ";displayString = IpAddress2String(WiFi.localIP());
tft.setTextColor(TFT_WHITE); // Set the font colour
infoScrnARgn[ipRgn].region.w = tft.drawString(leadDisplayString,infoScrnARgn[ipRgn].region.x,infoScrnARgn[ipRgn].region.y); //return is the new length of the displayed text.
tft.setTextColor(TFT_YELLOW); // Set the font colour
infoScrnARgn[ipRgn].region.w += tft.drawString(displayString,infoScrnARgn[ipRgn].region.x + infoScrnARgn[ipRgn].region.w,infoScrnARgn[ipRgn].region.y); //return is the new length of the displayed text.
leadDisplayString = "FW: ";displayString = CONFIG_VERSION;
tft.setTextColor(TFT_WHITE); // Set the font colour
infoScrnARgn[fwRgn].region.w = tft.drawString(leadDisplayString,infoScrnARgn[fwRgn].region.x,infoScrnARgn[fwRgn].region.y); //return is the new length of the displayed text.
tft.setTextColor(TFT_YELLOW); // Set the font colour
infoScrnARgn[fwRgn].region.w += tft.drawString(displayString,infoScrnARgn[fwRgn].region.x + infoScrnARgn[fwRgn].region.w,infoScrnARgn[fwRgn].region.y); //return is the new length of the displayed text
leadDisplayString = "Reset Pendant";displayString = "";
//tft.setTextColor(TFT_WHITE); // Set the font colour
infoScrnARgn[resetRgn].displayText(&tft,leadDisplayString,TFT_BLACK,TFT_WHITE);
#ifdef _debugopra
infoScrnARgn[nameRgn].drawRegion(&tft,TFT_YELLOW); // turn this on to debug visually the regions. draws a box around the button
infoScrnARgn[ipRgn].drawRegion(&tft,TFT_YELLOW); // turn this on to debug visually the regions. draws a box around the button
infoScrnARgn[resetRgn].drawRegion(&tft,TFT_YELLOW); // turn this on to debug visually the regions. draws a box around the button
#endif
}
bool loadInfoScreenRgns(){
const char* sourceFile = "/infoscrn.json";
bool fileExists = SPIFFS.exists(sourceFile);
char tmpSRgn[13];
strlcpy(tmpSRgn, "001001240280", 13); //<< plug in the same value you would have from your file if you want to change this at this level.
Region tmpRgn = getRegionFromString(tmpSRgn);
infoScrnARgn[returnRgn].TextRgn = false;
infoScrnARgn[returnRgn].init(tmpRgn);
if(!fileExists){
#ifdef _debugopra
Serial.println("[WARNING]: Config file:");Serial.print(sourceFile);Serial.println(" not found");
#endif
}
#ifdef _debugopra
Serial.print("Loading:");Serial.println(sourceFile);
#endif
File configfile = SPIFFS.open(sourceFile,"r");
DynamicJsonDocument doc(1024);
DeserializationError error = deserializeJson(doc, configfile);
if (error){Serial.println("[ERROR]: deserializeJson() error in lvlscrn.json");Serial.println(error.c_str());}
#ifdef _debugopra
Serial.println("Rendering Screen Regions");
#endif
strlcpy(tmpSRgn, doc["R"] | "001001240280", 13);
tmpRgn = getRegionFromString(tmpSRgn);
infoScrnARgn[returnRgn].TextRgn = false;
infoScrnARgn[returnRgn].init(tmpRgn);
//Name
strlcpy(tmpSRgn, doc["N"] | "005090150020", 13);
tmpRgn = getRegionFromString(tmpSRgn);
infoScrnARgn[nameRgn].TextRgn = false;
infoScrnARgn[nameRgn].init(tmpRgn);
//Ip Address
strlcpy(tmpSRgn, doc["IP"] | "005115150020", 13);
tmpRgn = getRegionFromString(tmpSRgn);
infoScrnARgn[ipRgn].TextRgn = false;
infoScrnARgn[ipRgn].init(tmpRgn);
//Reset Restart
strlcpy(tmpSRgn, doc["RS"] | "001290240040", 13);
tmpRgn = getRegionFromString(tmpSRgn);
infoScrnARgn[resetRgn].TextRgn = false;
infoScrnARgn[resetRgn].init(tmpRgn);
//Firmware Version
strlcpy(tmpSRgn, doc["FW"] | "005140150020", 13);
tmpRgn = getRegionFromString(tmpSRgn);
infoScrnARgn[fwRgn].TextRgn = false;
infoScrnARgn[fwRgn].init(tmpRgn);
#ifdef _debugopra
for (uint8_t rgn = 0; rgn < infoScrnRgnSize; rgn++) {
Serial.println(infoScrnARgn[rgn].getRegionDebug());
infoScrnARgn[rgn].drawRegion(&tft,TFT_YELLOW); //Draws a box around the region
}
#endif
configfile.close();
return true;
}
void initInfoScreen(){
#ifdef _debugopra
Serial.println("Running initInfoScreen, Screen 4");
#endif
Serial.println("SetResetdelay");
resetEnableDelay.set(500); //delay to stop a user from clicking the reset button by mistake when trying to navigate to the info screen.
tft.fillScreen(TFT_BLACK); // Clear screen
//drawBmp("/info.bmp", 0, 0); //no bmp for this screen.
loadInfoScreenRgns();
setInfoScreenText();
//setup buttons
for (uint8_t rgn = 0; rgn < infoScrnRgnSize; rgn++) {
//infoScrnARgn[rgn].init(infoBtnRgs[rgn]);
if(rgn == 0){//0 return home
infoScrnARgn[rgn].setReleaseAction(infoScrnARgn_hm);
}else if(rgn == 1){//1 this will not get hit anyway since region 0 will cover all text and it will be the first region checked.
//Name
}else if(rgn == 2){//2 this will not get hit anyway since region 0 will cover all text and it will be the first region checked.
//IP Address
}else if(rgn == 3){//3 reboot/reset
infoScrnARgn[rgn].setReleaseAction(infoScrnARgn_Rst);
}else if(rgn == 4){//4 firmware version
//Firmware
}
#ifdef _debugopra
infoScrnARgn[rgn].drawRegion(&tft,TFT_YELLOW); // turn this on to debug visually the regions. draws a box around the button
#endif
}
}
/****End info screen***/