23
23
// remix, transform, build upon the material and distributed for any purposes
24
24
// only if provided appropriate credit to the author and link to the original article.
25
25
26
- void handle_NotFound (){
26
+ void handle_NotFound () {
27
27
server.send (404 , " text/plain" , " Not found" );
28
28
}
29
29
30
30
void configAction () {
31
-
31
+
32
32
String offsetS1 = server.arg (" offsetS1" );
33
33
String offsetS2 = server.arg (" offsetS2" );
34
34
String satsForFix = server.arg (" satsForFix" );
35
- String displayGPS = server.arg (" displayGPS" );
36
- String displayBoth = server.arg (" displayBoth" );
37
- String displayVELO = server.arg (" displayVELO" );
38
- String swapSensors = server.arg (" swapSensors" );
35
+ String displaySimple = server.arg (" displaySimple" ) == " on" ? " on" : " off" ;
36
+ String displayGPS = server.arg (" displayGPS" ) == " on" ? " on" : " off" ;
37
+ String displayVELO = server.arg (" displayVELO" ) == " on" ? " on" : " off" ;
38
+ String displayLeft = server.arg (" displayLeft" ) == " on" ? " on" : " off" ;
39
+ String displayRight = server.arg (" displayRight" ) == " on" ? " on" : " off" ;
40
+ String swapSensors = server.arg (" swapSensors" ) == " on" ? " on" : " off" ;
39
41
String obsUserID = server.arg (" obsUserID" );
40
42
String hostname = server.arg (" hostname" );
41
-
43
+
42
44
// String confirmation = server.arg("confirmation");
43
-
44
- /* displayTest->clear();
45
+
46
+ /* displayTest->clear();
45
47
displayTest->drawString(64, 36, "displayConfig");
46
48
displayTest->drawString(64, 48, displayGPS);*/
47
- if (displayGPS == " on" )
49
+ if (displayGPS == " on" )
48
50
config.displayConfig |= DisplaySatelites;
49
51
else
50
52
config.displayConfig &= ~DisplaySatelites;
51
53
52
- if (displayBoth == " on" )
53
- config.displayConfig |= DisplayBoth ;
54
+ if (displaySimple == " on" )
55
+ config.displayConfig |= DisplaySimple ;
54
56
else
55
- config.displayConfig &= ~DisplayBoth;
57
+ config.displayConfig &= ~DisplaySimple;
58
+
56
59
57
- if (displayVELO == " on" )
60
+ if (displayVELO == " on" )
58
61
config.displayConfig |= DisplayVelocity;
59
62
else
60
63
config.displayConfig &= ~DisplayVelocity;
61
64
62
- if (swapSensors == " on" )
65
+ if (displayLeft == " on" )
66
+ config.displayConfig |= DisplayLeft;
67
+ else
68
+ config.displayConfig &= ~DisplayLeft;
69
+
70
+ if (displayRight == " on" )
71
+ config.displayConfig |= DisplayRight;
72
+ else
73
+ config.displayConfig &= ~DisplayRight;
74
+
75
+ if (swapSensors == " on" )
63
76
config.swapSensors = 1 ;
64
77
else
65
78
config.swapSensors = 0 ;
66
-
67
- strlcpy (config.hostname ,hostname.c_str (),sizeof (config.hostname ));
68
- strlcpy (config.obsUserID ,obsUserID.c_str (),sizeof (config.obsUserID ));
69
-
79
+
80
+
81
+ Serial.print (" displayConfig:" );
82
+ Serial.println (config.displayConfig );
83
+
84
+ Serial.print (" displaySimple:" );
85
+ Serial.println (displaySimple);
86
+
87
+ Serial.print (" displayGPS:" );
88
+ Serial.println (displayGPS);
89
+
90
+ Serial.print (" displayVELO:" );
91
+ Serial.println (displayVELO);
92
+
93
+ Serial.print (" displayLeft:" );
94
+ Serial.println (displayLeft);
95
+
96
+ Serial.print (" displayRight:" );
97
+ Serial.println (displayRight);
98
+
99
+ Serial.print (" swapSensors:" );
100
+ Serial.println (swapSensors);
101
+
102
+ strlcpy (config.hostname , hostname.c_str (), sizeof (config.hostname ));
103
+ strlcpy (config.obsUserID , obsUserID.c_str (), sizeof (config.obsUserID ));
104
+
70
105
config.sensorOffsets [0 ] = atoi (offsetS1.c_str ());
71
106
config.sensorOffsets [1 ] = atoi (offsetS2.c_str ());
72
107
config.satsForFix = atoi (satsForFix.c_str ());
@@ -98,14 +133,14 @@ void wifiAction() {
98
133
Serial.print (" ssid:" );
99
134
Serial.println (ssid);
100
135
101
- #ifdef dev
102
- Serial.print (F (" pass = " ));
103
- Serial.println (pass);
104
- #endif
136
+ #ifdef dev
137
+ Serial.print (F (" pass = " ));
138
+ Serial.println (pass);
139
+ #endif
105
140
106
141
// Write always both data, thus the WIFI config can be overwritten
107
- strlcpy (config.ssid ,ssid.c_str (),sizeof (config.ssid ));
108
- strlcpy (config.password ,pass.c_str (),sizeof (config.password ));
142
+ strlcpy (config.ssid , ssid.c_str (), sizeof (config.ssid ));
143
+ strlcpy (config.password , pass.c_str (), sizeof (config.password ));
109
144
110
145
// Print and safe config
111
146
Serial.println (F (" Print config file..." ));
@@ -134,7 +169,7 @@ bool CreateWifiSoftAP(String chipID)
134
169
displayTest->showTextOnGrid (1 , 2 , " " );
135
170
displayTest->showTextOnGrid (0 , 3 , APName.c_str ());
136
171
137
-
172
+
138
173
WiFi.softAPConfig (apIP, apIP, netMsk);
139
174
if (SoftAccOK)
140
175
{
@@ -146,10 +181,10 @@ bool CreateWifiSoftAP(String chipID)
146
181
147
182
displayTest->showTextOnGrid (0 , 4 , " Pass:" );
148
183
displayTest->showTextOnGrid (1 , 4 , APPassword);
149
-
184
+
150
185
displayTest->showTextOnGrid (0 , 5 , " IP:" );
151
186
displayTest->showTextOnGrid (1 , 5 , " 172.20.0.1" );
152
- }
187
+ }
153
188
else
154
189
{
155
190
Serial.println (F (" Soft AP Error." ));
@@ -238,14 +273,14 @@ void startServer() {
238
273
});
239
274
240
275
// ### Index ###
241
-
276
+
242
277
server.on (" /" , HTTP_GET, []() {
243
278
String html = navigationIndex;
244
279
// Header
245
280
html.replace (" {action}" , " " );
246
281
html.replace (" {version}" , OBSVersion);
247
282
html.replace (" {subtitle}" , " Navigation" );
248
-
283
+
249
284
server.send (200 , " text/html" , html);
250
285
});
251
286
@@ -261,7 +296,7 @@ void startServer() {
261
296
html.replace (" {subtitle}" , " Wifi Config" );
262
297
// Form data
263
298
html.replace (" {ssid}" , config.ssid );
264
-
299
+
265
300
server.send (200 , " text/html" , html);
266
301
});
267
302
@@ -282,16 +317,21 @@ void startServer() {
282
317
html.replace (" {hostname}" , String (config.hostname ));
283
318
html.replace (" {userId}" , String (config.obsUserID ));
284
319
320
+ bool displaySimple = config.displayConfig & DisplaySimple;
285
321
bool displayGPS = config.displayConfig & DisplaySatelites;
286
- bool displayBoth = config.displayConfig & DisplayBoth;
322
+ bool displayLeft = config.displayConfig & DisplayLeft;
323
+ bool displayRight = config.displayConfig & DisplayRight;
287
324
bool displayVelo = config.displayConfig & DisplayVelocity;
288
325
bool swapSensors = config.swapSensors ;
289
326
327
+
328
+ html.replace (" {displaySimple}" , displaySimple ? " checked" : " " );
290
329
html.replace (" {displayGPS}" , displayGPS ? " checked" : " " );
291
- html.replace (" {displayBoth}" , displayBoth ? " checked" : " " );
292
330
html.replace (" {displayVELO}" , displayVelo ? " checked" : " " );
331
+ html.replace (" {displayLeft}" , displayLeft ? " checked" : " " );
332
+ html.replace (" {displayRight}" , displayRight ? " checked" : " " );
293
333
html.replace (" {swapSensors}" , swapSensors ? " checked" : " " );
294
-
334
+
295
335
server.send (200 , " text/html" , html);
296
336
});
297
337
@@ -303,19 +343,19 @@ void startServer() {
303
343
html.replace (" {action}" , " " ); // Handled by XHR
304
344
html.replace (" {version}" , OBSVersion);
305
345
html.replace (" {subtitle}" , " Update Firmware" );
306
-
346
+
307
347
server.send (200 , " text/html" , html);
308
348
});
309
349
310
350
// Handling uploading firmware file
311
351
server.on (" /update" , HTTP_POST, []() {
312
352
Serial.println (" Send response..." );
313
- if (Update.hasError ()) {
353
+ if (Update.hasError ()) {
314
354
server.send (500 , " text/plain" , " Update fails!" );
315
355
} else {
316
356
server.send (200 , " text/plain" , " Update successful!" );
317
357
delay (250 );
318
- ESP.restart ();
358
+ ESP.restart ();
319
359
}
320
360
}, []() {
321
361
// Serial.println('Update Firmware...');
0 commit comments