Index: firmware/App/Controllers/Buttons.c =================================================================== diff -u -rd9cc76524777a12ba77b58ce95416dddfb032997 -r1bbf9da32e622975efed00b1a7589387a9829440 --- firmware/App/Controllers/Buttons.c (.../Buttons.c) (revision d9cc76524777a12ba77b58ce95416dddfb032997) +++ firmware/App/Controllers/Buttons.c (.../Buttons.c) (revision 1bbf9da32e622975efed00b1a7589387a9829440) @@ -39,6 +39,22 @@ 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 @@ -233,22 +249,51 @@ *************************************************************************/ void userConfirmOffButton( U08 response ) { - // is an off request pending user confirmation? - if ( TRUE == offRequestAwaitingUserConfirmation ) + switch ( response ) { - // reset off request pending flag regardless of user response - offRequestAwaitingUserConfirmation = FALSE; - // 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 + { // 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 } /************************************************************************* @@ -295,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 @@ -313,7 +358,7 @@ if ( offRequestPendingTimer >= OFF_REQUEST_EXPIRATION_TIME ) { offRequestAwaitingUserConfirmation = FALSE; - sendOffButtonMsgToUI( FALSE ); + sendOffButtonMsgToUI( OFF_BUTTON_CMD_CANCEL_USER_CONFIRM_PROMPT ); } }