void HoverButtonControl::Enable() { ChangeButtonState(ButtonStates::Normal); }
static void ButtonStateMachine(unsigned char ButtonOn, unsigned char btnIndex) { if ( ButtonOn ) { if( ButtonData[btnIndex].BtnState == BUTTON_STATE_OFF || ButtonData[btnIndex].BtnState == BUTTON_STATE_DEBOUNCE ) { // Make it more "On" ButtonData[btnIndex].BtnFilter++; if(ButtonData[btnIndex].BtnFilter == BTN_ON_COUNT) { ChangeButtonState(btnIndex, BUTTON_STATE_PRESSED); } } else // it's on one of the on (pressed) states. { if ( ButtonData[btnIndex].BtnHoldCounter < 65535 ) { ButtonData[btnIndex].BtnHoldCounter++; } if(ButtonData[btnIndex].BtnHoldCounter == BTN_HOLD_COUNT) { ChangeButtonState(btnIndex, BUTTON_STATE_HOLD); } if(ButtonData[btnIndex].BtnHoldCounter == BTN_LONG_HOLD_COUNT) { ChangeButtonState(btnIndex, BUTTON_STATE_LONG_HOLD); } } } else // The button is not pressed, but it may still be in the on state { // see if we still have a filter count (still in the on state) if( ButtonData[btnIndex].BtnFilter > 0 ) { ButtonData[btnIndex].BtnFilter--; // make it closer to off // When we reach a filter count of zero, by definition we are in // the off state if( ButtonData[btnIndex].BtnFilter == 0 ) { // Don't go from the off state to the off state. If we ramp // up but don't change to the BtnPressed state then that is // due to switch bounce if(ButtonData[btnIndex].BtnState != BUTTON_STATE_OFF) { ChangeButtonState(btnIndex, BUTTON_STATE_OFF); // Clear the hold counter so we start at the original off state ButtonData[btnIndex].BtnHoldCounter = 0; // If this one is off, maybe they all are off. When all // buttons are off, we stop the button timer ISR CheckForAllButtonsOff( ); } } } } // button on or off }
void HoverButtonControl::Disable() { ChangeButtonState(ButtonStates::Disabled); }