Skip to content

Commit 9ffc3ad

Browse files
committed
Fixed #50 #55 - Simple Display option and configure right and left separately
1 parent 0c51ee8 commit 9ffc3ad

File tree

4 files changed

+164
-105
lines changed

4 files changed

+164
-105
lines changed

config.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@
1919
*/
2020

2121
enum DisplayOptions {
22-
DisplaySatelites=0x01,
23-
DisplayBoth=0x02,
24-
DisplayVelocity=0x04
22+
DisplaySatelites=0x01, // 1
23+
DisplayVelocity=0x02, // 2
24+
DisplayLeft=0x04, // 4
25+
DisplayRight=0x08, // 8
26+
DisplaySimple=0x10 // 16
2527
};
2628

2729
struct Config {

configServer.h

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,15 @@ WebServer server(80);
4141
String style =
4242
"<style>"
4343
"#file-input,input {width:100%;height:44px;border-radius:4px;margin:10px auto;font-size:15px;}"
44-
"input {background:#f1f1f1;border:0;padding:0 15px}"
44+
"input {background:#f1f1f1;border:0;padding:0 15px;text-align:center;}"
4545
"body {background:#3498db;font-family:sans-serif;font-size:14px;color:#777}"
4646
"#file-input {padding:0 5;border:1px solid #ddd;line-height:44px;text-align:left;display:block;cursor:pointer}"
4747
"#bar,#prgbar {background-color:#f1f1f1;border-radius:10px}"
4848
"#bar {background-color:#3498db;width:0%;height:10px}"
4949
"form {background:#fff;max-width:258px;margin:75px auto;padding:30px;border-radius:5px;text-align:center}"
5050
".btn {background:#3498db;color:#fff;cursor:pointer}"
5151
"h1,h2 {padding:0;margin:0;}"
52+
"h3 {padding:10px 0;margin:0;}"
5253
"h1 a {color:#777}"
5354
"</style>";
5455

@@ -99,15 +100,17 @@ String wifiSettingsIndex =
99100
String configIndex =
100101
header +
101102
"<h3>Sensor</h3>"
102-
"Offset Sensor 1<input name='offsetS1' placeholder='Offset Sensor 1' value='{offset1}'>"
103-
"Offset Sensor 2<input name='offsetS2' placeholder='Offset Sensor 2' value='{offset2}'>"
104-
"Swap Sensors<input type='checkbox' name='swapSensors' {swapSensors}>"
103+
"Offset Sensor Left<input name='offsetS1' placeholder='Offset Sensor Left' value='{offset1}'>"
104+
"Offset Sensor Right<input name='offsetS2' placeholder='Offset Sensor Right' value='{offset2}'>"
105+
"Swap Sensors (Left <--> Right)<input type='checkbox' name='swapSensors' {swapSensors}>"
105106
"<h3>GPS</h3>"
106107
"Number of Satellites for fix<input name='satsForFix' placeholder='Number of Satellites for fix' value='{satsForFix}'>"
107108
"<h3>Display</h3>"
108-
"Display Both<input type='checkbox' name='displayBoth' {displayBoth}>"
109-
"Display Satellites<input type='checkbox' name='displayGPS' {displayGPS}>"
110-
"Display Velocity<input type='checkbox' name='displayVELO' {displayVELO}>"
109+
"Simple Mode<br>(all other display options are ignored)<input type='checkbox' name='displaySimple' {displaySimple}>"
110+
"Show Left Measurement<input type='checkbox' name='displayLeft' {displayLeft}>"
111+
"Show Right Measurement<input type='checkbox' name='displayRight' {displayRight}>"
112+
"Show Satellites<input type='checkbox' name='displayGPS' {displayGPS}>"
113+
"Show Velocity<input type='checkbox' name='displayVELO' {displayVELO}>"
111114
//"Upload Host"
112115
"<input name='hostname' placeholder='hostname' value='{hostname}' style='display:none'>"
113116
//"Upload UserID"

configServer.ino

Lines changed: 77 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -23,50 +23,85 @@
2323
// remix, transform, build upon the material and distributed for any purposes
2424
// only if provided appropriate credit to the author and link to the original article.
2525

26-
void handle_NotFound(){
26+
void handle_NotFound() {
2727
server.send(404, "text/plain", "Not found");
2828
}
2929

3030
void configAction() {
31-
31+
3232
String offsetS1 = server.arg("offsetS1");
3333
String offsetS2 = server.arg("offsetS2");
3434
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";
3941
String obsUserID = server.arg("obsUserID");
4042
String hostname = server.arg("hostname");
41-
43+
4244
//String confirmation = server.arg("confirmation");
43-
44-
/* displayTest->clear();
45+
46+
/* displayTest->clear();
4547
displayTest->drawString(64, 36, "displayConfig");
4648
displayTest->drawString(64, 48, displayGPS);*/
47-
if(displayGPS == "on")
49+
if (displayGPS == "on")
4850
config.displayConfig |= DisplaySatelites;
4951
else
5052
config.displayConfig &= ~DisplaySatelites;
5153

52-
if(displayBoth == "on")
53-
config.displayConfig |= DisplayBoth;
54+
if (displaySimple == "on")
55+
config.displayConfig |= DisplaySimple;
5456
else
55-
config.displayConfig &= ~DisplayBoth;
57+
config.displayConfig &= ~DisplaySimple;
58+
5659

57-
if(displayVELO == "on")
60+
if (displayVELO == "on")
5861
config.displayConfig |= DisplayVelocity;
5962
else
6063
config.displayConfig &= ~DisplayVelocity;
6164

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")
6376
config.swapSensors = 1;
6477
else
6578
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+
70105
config.sensorOffsets[0] = atoi(offsetS1.c_str());
71106
config.sensorOffsets[1] = atoi(offsetS2.c_str());
72107
config.satsForFix = atoi(satsForFix.c_str());
@@ -98,14 +133,14 @@ void wifiAction() {
98133
Serial.print("ssid:");
99134
Serial.println(ssid);
100135

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
105140

106141
// 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));
109144

110145
// Print and safe config
111146
Serial.println(F("Print config file..."));
@@ -134,7 +169,7 @@ bool CreateWifiSoftAP(String chipID)
134169
displayTest->showTextOnGrid(1, 2, "");
135170
displayTest->showTextOnGrid(0, 3, APName.c_str());
136171

137-
172+
138173
WiFi.softAPConfig(apIP, apIP, netMsk);
139174
if (SoftAccOK)
140175
{
@@ -146,10 +181,10 @@ bool CreateWifiSoftAP(String chipID)
146181

147182
displayTest->showTextOnGrid(0, 4, "Pass:");
148183
displayTest->showTextOnGrid(1, 4, APPassword);
149-
184+
150185
displayTest->showTextOnGrid(0, 5, "IP:");
151186
displayTest->showTextOnGrid(1, 5, "172.20.0.1");
152-
}
187+
}
153188
else
154189
{
155190
Serial.println(F("Soft AP Error."));
@@ -238,14 +273,14 @@ void startServer() {
238273
});
239274

240275
// ### Index ###
241-
276+
242277
server.on("/", HTTP_GET, []() {
243278
String html = navigationIndex;
244279
// Header
245280
html.replace("{action}", "");
246281
html.replace("{version}", OBSVersion);
247282
html.replace("{subtitle}", "Navigation");
248-
283+
249284
server.send(200, "text/html", html);
250285
});
251286

@@ -261,7 +296,7 @@ void startServer() {
261296
html.replace("{subtitle}", "Wifi Config");
262297
// Form data
263298
html.replace("{ssid}", config.ssid);
264-
299+
265300
server.send(200, "text/html", html);
266301
});
267302

@@ -282,16 +317,21 @@ void startServer() {
282317
html.replace("{hostname}", String(config.hostname));
283318
html.replace("{userId}", String(config.obsUserID));
284319

320+
bool displaySimple = config.displayConfig & DisplaySimple;
285321
bool displayGPS = config.displayConfig & DisplaySatelites;
286-
bool displayBoth = config.displayConfig & DisplayBoth;
322+
bool displayLeft = config.displayConfig & DisplayLeft;
323+
bool displayRight = config.displayConfig & DisplayRight;
287324
bool displayVelo = config.displayConfig & DisplayVelocity;
288325
bool swapSensors = config.swapSensors;
289326

327+
328+
html.replace("{displaySimple}", displaySimple ? "checked" : "");
290329
html.replace("{displayGPS}", displayGPS ? "checked" : "");
291-
html.replace("{displayBoth}", displayBoth ? "checked" : "");
292330
html.replace("{displayVELO}", displayVelo ? "checked" : "");
331+
html.replace("{displayLeft}", displayLeft ? "checked" : "");
332+
html.replace("{displayRight}", displayRight ? "checked" : "");
293333
html.replace("{swapSensors}", swapSensors ? "checked" : "");
294-
334+
295335
server.send(200, "text/html", html);
296336
});
297337

@@ -303,19 +343,19 @@ void startServer() {
303343
html.replace("{action}", ""); // Handled by XHR
304344
html.replace("{version}", OBSVersion);
305345
html.replace("{subtitle}", "Update Firmware");
306-
346+
307347
server.send(200, "text/html", html);
308348
});
309349

310350
// Handling uploading firmware file
311351
server.on("/update", HTTP_POST, []() {
312352
Serial.println("Send response...");
313-
if(Update.hasError()) {
353+
if (Update.hasError()) {
314354
server.send(500, "text/plain", "Update fails!");
315355
} else {
316356
server.send(200, "text/plain", "Update successful!");
317357
delay(250);
318-
ESP.restart();
358+
ESP.restart();
319359
}
320360
}, []() {
321361
//Serial.println('Update Firmware...');

0 commit comments

Comments
 (0)