diff --git a/openrtx/include/core/state.h b/openrtx/include/core/state.h index 782dd652..da1e3585 100644 --- a/openrtx/include/core/state.h +++ b/openrtx/include/core/state.h @@ -59,8 +59,8 @@ typedef struct bool bank_enabled; uint16_t bank; uint8_t rtxStatus; - bool rtxShutdown; + bool shutdown; bool emergency; settings_t settings; gps_t gps_data; diff --git a/openrtx/src/core/state.c b/openrtx/src/core/state.c index 493fdc18..6c0602b1 100644 --- a/openrtx/src/core/state.c +++ b/openrtx/src/core/state.c @@ -84,7 +84,7 @@ void state_init() state.channel_index = 1; // Set default channel index (it is 1-based) state.bank_enabled = false; state.rtxStatus = RTX_OFF; - state.rtxShutdown = false; + state.shutdown = false; state.emergency = false; // Force brightness field to be in range 0 - 100 diff --git a/openrtx/src/core/threads.c b/openrtx/src/core/threads.c index eaba85ff..e1796712 100644 --- a/openrtx/src/core/threads.c +++ b/openrtx/src/core/threads.c @@ -144,7 +144,7 @@ void *kbd_task(void *arg) // Initialize keyboard driver kbd_init(); - while(1) + while(state.shutdown == false) { kbd_msg_t msg; @@ -165,6 +165,8 @@ void *kbd_task(void *arg) // Read keyboard state at 40Hz sleepFor(0u, 25u); } + + return NULL; } /** @@ -174,7 +176,7 @@ void *dev_task(void *arg) { (void) arg; - while(1) + while(state.shutdown == false) { // Lock mutex and update internal state pthread_mutex_lock(&state_mutex); @@ -190,6 +192,8 @@ void *dev_task(void *arg) // Execute state update thread every 1s sleepFor(1u, 0u); } + + return NULL; } /** @@ -201,20 +205,13 @@ void *rtx_task(void *arg) rtx_init(&rtx_mutex); - while(1) + while(state.shutdown == false) { rtx_taskFunc(); - - // TODO: implement a cleaner shutdown procedure - if(state.rtxShutdown == true) - { - radio_disableRtx(); - platform_ledOff(RED); - platform_ledOff(GREEN); - break; - } } + rtx_terminate(); + return NULL; } @@ -230,7 +227,7 @@ void *gps_task(void *arg) gps_init(9600); - while(1) + while(state.shutdown == false) { pthread_mutex_lock(&state_mutex); gps_taskFunc(); @@ -238,6 +235,10 @@ void *gps_task(void *arg) sleepFor(0u, 100u); } + + gps_terminate(); + + return NULL; } #endif diff --git a/openrtx/src/rtx/OpMode_FM.cpp b/openrtx/src/rtx/OpMode_FM.cpp index cefe3a43..c1229609 100644 --- a/openrtx/src/rtx/OpMode_FM.cpp +++ b/openrtx/src/rtx/OpMode_FM.cpp @@ -78,6 +78,8 @@ void OpMode_FM::enable() void OpMode_FM::disable() { // Clean shutdown. + platform_ledOff(GREEN); + platform_ledOff(RED); audio_disableAmp(); audio_disableMic(); radio_disableRtx(); diff --git a/openrtx/src/rtx/OpMode_M17.cpp b/openrtx/src/rtx/OpMode_M17.cpp index 353e1332..d386e795 100644 --- a/openrtx/src/rtx/OpMode_M17.cpp +++ b/openrtx/src/rtx/OpMode_M17.cpp @@ -54,6 +54,8 @@ void OpMode_M17::disable() { startRx = false; startTx = false; + platform_ledOff(GREEN); + platform_ledOff(RED); codec_terminate(); audio_disableAmp(); audio_disableMic(); diff --git a/openrtx/src/ui/ui.c b/openrtx/src/ui/ui.c index 35c8e422..645f2c55 100644 --- a/openrtx/src/ui/ui.c +++ b/openrtx/src/ui/ui.c @@ -935,6 +935,7 @@ void ui_updateFSM(event_t event, bool *sync_rtx) // User wants to power off the radio, so shutdown. if(!platform_pwrButtonStatus()) { + state.shutdown = true; state_terminate(); platform_terminate(); return; diff --git a/openrtx/src/ui/ui_menu.c b/openrtx/src/ui/ui_menu.c index ee5ae8d9..8c8a2ef4 100644 --- a/openrtx/src/ui/ui_menu.c +++ b/openrtx/src/ui/ui_menu.c @@ -467,8 +467,8 @@ void _ui_drawMenuBackup(ui_state_t* ui_state) gfx_print(line, FONT_SIZE_8PT, TEXT_ALIGN_CENTER, color_white, "press PTT to start."); - // Shutdown RF stage - state.rtxShutdown = true; + // Shutdown all the other parts + state.shutdown = true; if(platform_getPttStatus() == 1) { @@ -500,8 +500,8 @@ void _ui_drawMenuRestore(ui_state_t* ui_state) gfx_print(line, FONT_SIZE_8PT, TEXT_ALIGN_CENTER, color_white, "press PTT to start."); - // Shutdown RF stage - state.rtxShutdown = true; + // Shutdown all the other parts + state.shutdown = true; if(platform_getPttStatus() == 1) {