Skip to content

Commit 120082e

Browse files
committed
Add Ref Stn button check task
1 parent 98188cf commit 120082e

File tree

1 file changed

+122
-0
lines changed

1 file changed

+122
-0
lines changed

Firmware/RTK_Surveyor/Tasks.ino

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -851,6 +851,128 @@ void ButtonCheckTask(void *e)
851851
}
852852
}
853853
} //End Platform = RTK Facet
854+
else if (productVariant == REFERENCE_STATION) //Check one momentary button
855+
{
856+
if (setupBtn != nullptr) setupBtn->read();
857+
858+
if (systemState == STATE_SHUTDOWN)
859+
{
860+
//Ignore button presses while shutting down
861+
}
862+
else if (setupBtn != nullptr && setupBtn->pressedFor(shutDownButtonTime))
863+
{
864+
forceSystemStateUpdate = true;
865+
requestChangeState(STATE_SHUTDOWN);
866+
867+
if (inMainMenu) powerDown(true); //State machine is not updated while in menu system so go straight to power down as needed
868+
}
869+
else if (setupBtn != nullptr && systemState == STATE_ROVER_NOT_STARTED && firstRoverStart == true && setupBtn->pressedFor(500))
870+
{
871+
forceSystemStateUpdate = true;
872+
requestChangeState(STATE_TEST);
873+
lastTestMenuChange = millis(); //Avoid exiting test menu for 1s
874+
}
875+
else if (setupBtn != nullptr && setupBtn->wasReleased() && firstRoverStart == false)
876+
{
877+
switch (systemState)
878+
{
879+
//If we are in any running state, change to STATE_DISPLAY_SETUP
880+
case STATE_ROVER_NOT_STARTED:
881+
case STATE_ROVER_NO_FIX:
882+
case STATE_ROVER_FIX:
883+
case STATE_ROVER_RTK_FLOAT:
884+
case STATE_ROVER_RTK_FIX:
885+
case STATE_BASE_NOT_STARTED:
886+
case STATE_BASE_TEMP_SETTLE:
887+
case STATE_BASE_TEMP_SURVEY_STARTED:
888+
case STATE_BASE_TEMP_TRANSMITTING:
889+
case STATE_BASE_FIXED_NOT_STARTED:
890+
case STATE_BASE_FIXED_TRANSMITTING:
891+
case STATE_BUBBLE_LEVEL:
892+
case STATE_WIFI_CONFIG_NOT_STARTED:
893+
case STATE_WIFI_CONFIG:
894+
case STATE_ESPNOW_PAIRING_NOT_STARTED:
895+
case STATE_ESPNOW_PAIRING:
896+
lastSystemState = systemState; //Remember this state to return after we mark an event or ESP-Now pair
897+
requestChangeState(STATE_DISPLAY_SETUP);
898+
setupState = STATE_MARK_EVENT;
899+
lastSetupMenuChange = millis();
900+
break;
901+
902+
case STATE_MARK_EVENT:
903+
//If the user presses the setup button during a mark event, do nothing
904+
//Allow system to return to lastSystemState
905+
break;
906+
907+
case STATE_PROFILE:
908+
//If the user presses the setup button during a profile change, do nothing
909+
//Allow system to return to lastSystemState
910+
break;
911+
912+
case STATE_TEST:
913+
//Do nothing. User is releasing the setup button.
914+
break;
915+
916+
case STATE_TESTING:
917+
//If we are in testing, return to Rover Not Started
918+
requestChangeState(STATE_ROVER_NOT_STARTED);
919+
break;
920+
921+
case STATE_DISPLAY_SETUP:
922+
//If we are displaying the setup menu, cycle through possible system states
923+
//Exit display setup and enter new system state after ~1500ms in updateSystemState()
924+
lastSetupMenuChange = millis();
925+
926+
forceDisplayUpdate = true; //User is interacting so repaint display quickly
927+
928+
switch (setupState)
929+
{
930+
case STATE_MARK_EVENT:
931+
setupState = STATE_ROVER_NOT_STARTED;
932+
break;
933+
case STATE_ROVER_NOT_STARTED:
934+
//If F9R, skip base state
935+
if (zedModuleType == PLATFORM_F9R)
936+
setupState = STATE_BUBBLE_LEVEL;
937+
else
938+
setupState = STATE_BASE_NOT_STARTED;
939+
break;
940+
case STATE_BASE_NOT_STARTED:
941+
setupState = STATE_BUBBLE_LEVEL;
942+
break;
943+
case STATE_BUBBLE_LEVEL:
944+
setupState = STATE_WIFI_CONFIG_NOT_STARTED;
945+
break;
946+
case STATE_WIFI_CONFIG_NOT_STARTED:
947+
setupState = STATE_ESPNOW_PAIRING_NOT_STARTED;
948+
break;
949+
case STATE_ESPNOW_PAIRING_NOT_STARTED:
950+
//If only one active profile do not show any profiles
951+
index = getProfileNumberFromUnit(0);
952+
displayProfile = getProfileNumberFromUnit(1);
953+
setupState = (index >= displayProfile) ? STATE_MARK_EVENT : STATE_PROFILE;
954+
displayProfile = 0;
955+
break;
956+
case STATE_PROFILE:
957+
//Done when no more active profiles
958+
displayProfile++;
959+
if (!getProfileNumberFromUnit(displayProfile))
960+
setupState = STATE_MARK_EVENT;
961+
break;
962+
default:
963+
systemPrintf("ButtonCheckTask unknown setup state: %d\r\n", setupState);
964+
setupState = STATE_MARK_EVENT;
965+
break;
966+
}
967+
break;
968+
969+
default:
970+
systemPrintf("ButtonCheckTask unknown system state: %d\r\n", systemState);
971+
requestChangeState(STATE_ROVER_NOT_STARTED);
972+
break;
973+
}
974+
}
975+
} //End Platform = REFERENCE_STATION
854976

855977
delay(1); //Poor man's way of feeding WDT. Required to prevent Priority 1 tasks from causing WDT reset
856978
taskYIELD();

0 commit comments

Comments
 (0)