Index: firmware/App/Controllers/Buttons.c =================================================================== diff -u -rbe83f01a4d54cbd0d92b68cb95a15dcbb06a9a51 -r52863cba9685f31136ab3f4b4764a17ccf34fc05 --- firmware/App/Controllers/Buttons.c (.../Buttons.c) (revision be83f01a4d54cbd0d92b68cb95a15dcbb06a9a51) +++ firmware/App/Controllers/Buttons.c (.../Buttons.c) (revision 52863cba9685f31136ab3f4b4764a17ccf34fc05) @@ -1,6 +1,6 @@ /************************************************************************** * - * Copyright (c) 2019-2019 Diality Inc. - All Rights Reserved. + * Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. * * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN * WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. @@ -39,11 +39,27 @@ NUM_OF_BUTTONS } BUTTON_T; +typedef enum OffButtonCmdsToUI +{ + OFF_BUTTON_CMD_PROMPT_USER_TO_CONFIRM = 0, + OFF_BUTTON_CMD_CANCEL_USER_CONFIRM_PROMPT, + OFF_BUTTON_CMD_REJECT_USER_OFF_REQUEST, + NUM_OF_OFF_BUTTON_CMDS +} OFF_BUTTON_CMD_T; + +typedef enum OffButtonRspsFromUI +{ + OFF_BUTTON_RSP_USER_REQUESTS_POWER_OFF = 0, + OFF_BUTTON_RSP_USER_CONFIRMS_POWER_OFF, + OFF_BUTTON_RSP_USER_REJECTS_POWER_OFF, + NUM_OF_OFF_BUTTON_RSPS +} OFF_BUTTON_RSP_T; + #define OFF_REQUEST_PULSE_COUNT 4 #define OFF_REQUEST_PULSE_INTVL 50 // ms #define STOP_BUTTON_PENDING_TIMEOUT 500 // ms #define STUCK_BUTTON_TIMEOUT 1000 // ms -#define OFF_REQUEST_EXPIRATION_TIME (1000*60) // ms (1 minute) +#define OFF_REQUEST_EXPIRATION_TIME (1000 * 60) // ms (1 minute) #define USER_CONFIRMED 1 #define USER_REJECTED 0 @@ -233,24 +249,51 @@ *************************************************************************/ void userConfirmOffButton( U08 response ) { - // is an off request pending user confirmation? - if ( TRUE == offRequestAwaitingUserConfirmation ) + switch ( response ) { - // did user confirm? - if ( USER_CONFIRMED == response ) - { + case OFF_BUTTON_RSP_USER_REQUESTS_POWER_OFF: + // if we're in a mode that allows power off, set off pending flag and request user confirmation if ( TRUE == isCurrentOpModeOkToTurnOff() ) { - offButtonPressPending = TRUE; - offRequestPulseCount = OFF_REQUEST_PULSE_COUNT; - offRequestPulseTimer = 0; + offRequestAwaitingUserConfirmation = TRUE; + offRequestPendingTimer = 0; + sendOffButtonMsgToUI( OFF_BUTTON_CMD_PROMPT_USER_TO_CONFIRM ); } - } - else // user did not confirm - { - offRequestAwaitingUserConfirmation = FALSE; - } - } + else + { // send rejection response to power off request + sendOffButtonMsgToUI( OFF_BUTTON_CMD_REJECT_USER_OFF_REQUEST ); + } + break; + + case OFF_BUTTON_RSP_USER_CONFIRMS_POWER_OFF: + // is an off request pending user confirmation? + if ( TRUE == offRequestAwaitingUserConfirmation ) + { + // reset off request pending flag + offRequestAwaitingUserConfirmation = FALSE; + // if we're in a mode that allows power off, initiate power off sequence + if ( TRUE == isCurrentOpModeOkToTurnOff() ) + { + offButtonPressPending = TRUE; + offRequestPulseCount = OFF_REQUEST_PULSE_COUNT; + offRequestPulseTimer = 0; + } + } + break; + + case OFF_BUTTON_RSP_USER_REJECTS_POWER_OFF: + // is an off request pending user confirmation? + if ( TRUE == offRequestAwaitingUserConfirmation ) + { + // reset off request pending flag + offRequestAwaitingUserConfirmation = FALSE; + } + break; + + default: + // ok - do nothing + break; + } // end switch } /************************************************************************* @@ -297,7 +340,7 @@ if ( TRUE == isCurrentOpModeOkToTurnOff() ) { // send off button to UI for user confirmation - sendOffButtonMsgToUI( TRUE ); + sendOffButtonMsgToUI( OFF_BUTTON_CMD_PROMPT_USER_TO_CONFIRM ); offRequestAwaitingUserConfirmation = TRUE; offRequestPendingTimer = 0; #ifdef SIMULATE_UI @@ -315,7 +358,7 @@ if ( offRequestPendingTimer >= OFF_REQUEST_EXPIRATION_TIME ) { offRequestAwaitingUserConfirmation = FALSE; - sendOffButtonMsgToUI( FALSE ); + sendOffButtonMsgToUI( OFF_BUTTON_CMD_CANCEL_USER_CONFIRM_PROMPT ); } }