Skip to content

Commit eb3005e

Browse files
committed
Expand state machine to handle buttons. Move delay into static displays. Increase maxWait during config. Exit fixed mode in rover config.
1 parent fa18eac commit eb3005e

File tree

9 files changed

+281
-203
lines changed

9 files changed

+281
-203
lines changed

Firmware/RTK_Surveyor/Base.ino

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ bool configureUbloxModuleBase()
1111

1212
i2cGNSS.checkUblox(); //Regularly poll to get latest data and any RTCM
1313

14+
if (i2cGNSS.getSurveyInActive() == true)
15+
{
16+
response = i2cGNSS.disableSurveyMode(maxWait); //Disable survey
17+
if (response == false)
18+
Serial.println(F("Disable Survey failed"));
19+
}
20+
1421
//In base mode we force 1Hz
1522
if (i2cGNSS.getNavigationFrequency(maxWait) != 1)
1623
response &= i2cGNSS.setNavigationFrequency(1, maxWait);
@@ -52,7 +59,7 @@ bool configureUbloxModuleBase()
5259

5360
//Start survey
5461
//The ZED-F9P is slightly different than the NEO-M8P. See the Integration manual 3.5.8 for more info.
55-
bool surveyIn()
62+
bool beginSurveyIn()
5663
{
5764
bool needSurveyReset = false;
5865
if (i2cGNSS.getSurveyInActive() == true) needSurveyReset = true;
@@ -103,6 +110,7 @@ bool resetSurvey()
103110
bool startFixedBase()
104111
{
105112
bool response = false;
113+
int maxWait = 2000;
106114

107115
if (settings.fixedBaseCoordinateType == COORD_TYPE_ECEF)
108116
{
@@ -123,7 +131,8 @@ bool startFixedBase()
123131
//-1280208.308,-4716803.847,4086665.811 is SparkFun HQ so...
124132
response = i2cGNSS.setStaticPosition(majorEcefX, minorEcefX,
125133
majorEcefY, minorEcefY,
126-
majorEcefZ, minorEcefZ
134+
majorEcefZ, minorEcefZ,
135+
maxWait
127136
); //With high precision 0.1mm parts
128137
}
129138
else if (settings.fixedBaseCoordinateType == COORD_TYPE_GEOGRAPHIC)
@@ -153,12 +162,8 @@ bool startFixedBase()
153162
majorLat, minorLat,
154163
majorLong, minorLong,
155164
majorAlt, minorAlt,
156-
true);
157-
}
158-
159-
if (response == true)
160-
{
161-
Serial.println(F("Static Base Started Successfully"));
165+
true, //Use lat/long as input
166+
maxWait);
162167
}
163168

164169
return (response);

Firmware/RTK_Surveyor/Buttons.ino

Lines changed: 6 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,22 @@
1-
//Regularly update subsystems. Called from main loop (aka not tasks).
2-
31
//Change between Rover or Base depending on switch state
42
void checkSetupButton()
53
{
64
//Check rover switch and configure module accordingly
75
//When switch is set to '1' = BASE, pin will be shorted to ground
86
if (digitalRead(baseSwitch) == LOW) //Switch is set to base mode
97
{
10-
if (systemState == STATE_ROVER_NO_FIX ||
11-
systemState == STATE_ROVER_FIX ||
12-
systemState == STATE_ROVER_RTK_FLOAT ||
13-
systemState == STATE_ROVER_RTK_FIX)
8+
if (buttonPreviousState == BUTTON_ROVER)
149
{
15-
displayBaseStart();
16-
17-
//Configure for base mode
18-
Serial.println(F("Base Mode"));
19-
20-
//Restart Bluetooth with 'Base' name
21-
//We start BT regardless of Ntrip Server in case user wants to transmit survey-in stats over BT
22-
beginBluetooth();
23-
24-
if (settings.fixedBase == false)
25-
{
26-
//Don't configure base if we are going to do a survey in. We need to wait for surveyInStartingAccuracy to be achieved in state machine
27-
changeState(STATE_BASE_TEMP_SURVEY_NOT_STARTED);
28-
}
29-
else if (settings.fixedBase == true)
30-
{
31-
if (configureUbloxModuleBase() == false)
32-
{
33-
Serial.println(F("Base config failed!"));
34-
displayBaseFail();
35-
delay(1000);
36-
return;
37-
}
38-
39-
bool response = startFixedBase();
40-
if (response == true)
41-
{
42-
changeState(STATE_BASE_FIXED_TRANSMITTING);
43-
}
44-
else
45-
{
46-
Serial.println(F("Fixed base start failed"));
47-
displayBaseFail();
48-
delay(1000);
49-
return;
50-
}
51-
}
52-
53-
digitalWrite(baseStatusLED, HIGH);
54-
displayBaseSuccess();
55-
delay(500);
10+
buttonPreviousState = BUTTON_BASE;
11+
changeState(STATE_BASE_NOT_STARTED);
5612
}
5713
}
5814
else if (digitalRead(baseSwitch) == HIGH) //Switch is set to Rover
5915
{
60-
if (systemState == STATE_BASE_TEMP_SURVEY_NOT_STARTED ||
61-
systemState == STATE_BASE_TEMP_SURVEY_STARTED ||
62-
systemState == STATE_BASE_TEMP_TRANSMITTING ||
63-
systemState == STATE_BASE_TEMP_WIFI_STARTED ||
64-
systemState == STATE_BASE_TEMP_WIFI_CONNECTED ||
65-
systemState == STATE_BASE_TEMP_CASTER_STARTED ||
66-
systemState == STATE_BASE_TEMP_CASTER_CONNECTED ||
67-
systemState == STATE_BASE_FIXED_TRANSMITTING ||
68-
systemState == STATE_BASE_FIXED_WIFI_STARTED ||
69-
systemState == STATE_BASE_FIXED_WIFI_CONNECTED ||
70-
systemState == STATE_BASE_FIXED_CASTER_STARTED ||
71-
systemState == STATE_BASE_FIXED_CASTER_CONNECTED)
16+
if (buttonPreviousState == BUTTON_BASE)
7217
{
73-
displayRoverStart();
74-
75-
//Configure for rover mode
76-
Serial.println(F("Rover Mode"));
77-
78-
//If we are survey'd in, but switch is rover then disable survey
79-
if (configureUbloxModuleRover() == false)
80-
{
81-
Serial.println(F("Rover config failed!"));
82-
displayRoverFail();
83-
return;
84-
}
85-
86-
beginBluetooth(); //Restart Bluetooth with 'Rover' name
87-
88-
changeState(STATE_ROVER_NO_FIX);
89-
90-
digitalWrite(baseStatusLED, LOW);
91-
displayRoverSuccess();
92-
delay(500);
18+
buttonPreviousState = BUTTON_ROVER;
19+
changeState(STATE_ROVER_NOT_STARTED);
9320
}
9421
}
9522
}

Firmware/RTK_Surveyor/Display.ino

Lines changed: 54 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ void updateDisplay()
1212

1313
switch (systemState)
1414
{
15+
case (STATE_ROVER_NOT_STARTED):
16+
//Do nothing. Static display shown during state change.
17+
break;
1518
case (STATE_ROVER_NO_FIX):
1619
paintRoverNoFix();
1720
break;
@@ -24,8 +27,11 @@ void updateDisplay()
2427
case (STATE_ROVER_RTK_FIX):
2528
paintRoverRTKFix();
2629
break;
27-
case (STATE_BASE_TEMP_SURVEY_NOT_STARTED):
28-
paintBaseTempSurveyNotStarted();
30+
case (STATE_BASE_NOT_STARTED):
31+
//Do nothing. Static display shown during state change.
32+
break;
33+
case (STATE_BASE_TEMP_SETTLE):
34+
paintBaseTempSettle();
2935
break;
3036
case (STATE_BASE_TEMP_SURVEY_STARTED):
3137
paintBaseTempSurveyStarted();
@@ -45,6 +51,9 @@ void updateDisplay()
4551
case (STATE_BASE_TEMP_CASTER_CONNECTED):
4652
paintBaseTempCasterConnected();
4753
break;
54+
case (STATE_BASE_FIXED_NOT_STARTED):
55+
//Do nothing. Static display shown during state change.
56+
break;
4857
case (STATE_BASE_FIXED_TRANSMITTING):
4958
paintBaseFixedTransmitting();
5059
break;
@@ -212,7 +221,7 @@ void paintHorizontalAccuracy()
212221
if (online.display == true)
213222
{
214223
//Blink crosshair icon until we achieve <5m horz accuracy (user definable)
215-
if (systemState == STATE_BASE_TEMP_SURVEY_NOT_STARTED)
224+
if (systemState == STATE_BASE_TEMP_SETTLE)
216225
{
217226
if (millis() - lastCrosshairIconUpdate > 500)
218227
{
@@ -292,8 +301,8 @@ void paintBaseState()
292301
{
293302
oled.drawIcon(27, 3, Rover_Width, Rover_Height, Rover, sizeof(Rover), true);
294303
}
295-
else if (systemState == STATE_BASE_TEMP_SURVEY_STARTED ||
296-
systemState == STATE_BASE_TEMP_SURVEY_NOT_STARTED //Turn on base icon solid (blink crosshair in paintHorzAcc)
304+
else if (systemState == STATE_BASE_TEMP_SETTLE ||
305+
systemState == STATE_BASE_TEMP_SURVEY_STARTED //Turn on base icon solid (blink crosshair in paintHorzAcc)
297306
)
298307
{
299308
//Blink base icon until survey is complete
@@ -469,7 +478,7 @@ void paintRoverRTKFix()
469478
//Start of base / survey in / NTRIP mode
470479
//Screen is displayed while we are waiting for horz accuracy to drop to appropriate level
471480
//Blink crosshair icon until we have we have horz accuracy < user defined level
472-
void paintBaseTempSurveyNotStarted()
481+
void paintBaseTempSettle()
473482
{
474483
if (online.display == true)
475484
{
@@ -861,7 +870,7 @@ void paintBaseFixedCasterConnected()
861870
// oled.print("Base Fail Please Reset");
862871
//}
863872

864-
void displayBaseStart()
873+
void displayBaseStart(uint16_t displayTime)
865874
{
866875
if (online.display == true)
867876
{
@@ -877,10 +886,12 @@ void displayBaseStart()
877886
printTextwithKerning((char*)"Base", textX, textY, textKerning);
878887

879888
oled.display();
889+
890+
delay(displayTime);
880891
}
881892
}
882893

883-
void displayBaseSuccess()
894+
void displayBaseSuccess(uint16_t displayTime)
884895
{
885896
if (online.display == true)
886897
{
@@ -902,10 +913,12 @@ void displayBaseSuccess()
902913

903914
printTextwithKerning((char*)"Started", textX, textY, textKerning);
904915
oled.display();
916+
917+
delay(displayTime);
905918
}
906919
}
907920

908-
void displayBaseFail()
921+
void displayBaseFail(uint16_t displayTime)
909922
{
910923
if (online.display == true)
911924
{
@@ -927,10 +940,12 @@ void displayBaseFail()
927940

928941
printTextwithKerning((char*)"Failed", textX, textY, textKerning);
929942
oled.display();
943+
944+
delay(displayTime);
930945
}
931946
}
932947

933-
void displayRoverStart()
948+
void displayRoverStart(uint16_t displayTime)
934949
{
935950
if (online.display == true)
936951
{
@@ -946,10 +961,12 @@ void displayRoverStart()
946961
printTextwithKerning((char*)"Rover", textX, textY, textKerning);
947962

948963
oled.display();
964+
965+
delay(displayTime);
949966
}
950967
}
951968

952-
void displayRoverSuccess()
969+
void displayRoverSuccess(uint16_t displayTime)
953970
{
954971
if (online.display == true)
955972
{
@@ -971,10 +988,12 @@ void displayRoverSuccess()
971988

972989
printTextwithKerning((char*)"Started", textX, textY, textKerning);
973990
oled.display();
991+
992+
delay(displayTime);
974993
}
975994
}
976995

977-
void displayRoverFail()
996+
void displayRoverFail(uint16_t displayTime)
978997
{
979998
if (online.display == true)
980999
{
@@ -996,6 +1015,8 @@ void displayRoverFail()
9961015

9971016
printTextwithKerning((char*)"Failed", textX, textY, textKerning);
9981017
oled.display();
1018+
1019+
delay(displayTime);
9991020
}
10001021
}
10011022

@@ -1025,7 +1046,7 @@ void displaySerialConfig()
10251046
}
10261047
}
10271048

1028-
void displaySurveyStart()
1049+
void displaySurveyStart(uint16_t displayTime)
10291050
{
10301051
if (online.display == true)
10311052
{
@@ -1041,10 +1062,12 @@ void displaySurveyStart()
10411062
printTextwithKerning((char*)"Survey", textX, textY, textKerning);
10421063

10431064
oled.display();
1065+
1066+
delay(displayTime);
10441067
}
10451068
}
10461069

1047-
void displaySurveyStarted()
1070+
void displaySurveyStarted(uint16_t displayTime)
10481071
{
10491072
if (online.display == true)
10501073
{
@@ -1066,23 +1089,13 @@ void displaySurveyStarted()
10661089

10671090
printTextwithKerning((char*)"Started", textX, textY, textKerning);
10681091
oled.display();
1069-
}
1070-
}
10711092

1072-
//Draw a frame at outside edge
1073-
void drawFrame()
1074-
{
1075-
//Init and draw box at edge to see screen alignment
1076-
int xMax = 63;
1077-
int yMax = 47;
1078-
oled.line(0, 0, xMax, 0); //Top
1079-
oled.line(0, 0, 0, yMax); //Left
1080-
oled.line(0, yMax, xMax, yMax); //Bottom
1081-
oled.line(xMax, 0, xMax, yMax); //Right
1093+
delay(displayTime);
1094+
}
10821095
}
10831096

10841097
//If the SD card is detected but is not formatted correctly, display warning
1085-
void displaySDFail()
1098+
void displaySDFail(uint16_t displayTime)
10861099
{
10871100
if (online.display == true)
10881101
{
@@ -1104,5 +1117,19 @@ void displaySDFail()
11041117

11051118
printTextwithKerning((char*)"SD Card", textX, textY, textKerning);
11061119
oled.display();
1120+
1121+
delay(displayTime);
11071122
}
11081123
}
1124+
1125+
//Draw a frame at outside edge
1126+
void drawFrame()
1127+
{
1128+
//Init and draw box at edge to see screen alignment
1129+
int xMax = 63;
1130+
int yMax = 47;
1131+
oled.line(0, 0, xMax, 0); //Top
1132+
oled.line(0, 0, 0, yMax); //Left
1133+
oled.line(0, yMax, xMax, yMax); //Bottom
1134+
oled.line(xMax, 0, xMax, yMax); //Right
1135+
}

0 commit comments

Comments
 (0)