* button pin state is then read.
If a change has occurred, it is noted by an
* increment to ButtonDebounceCount. When ButtonDebounceCount has reached the
* ButtonDebounceCountList value for that button, the button will have been
* debounced and the button state will be updated in ButtonCurrentState.
*
* @param void
*
* @return void
*
* @see Button_Init
* @see Button_Debounce
* @see Button_StateGet
*
* \b Example Example:
* @code
* // In System_Init
* Gpio_Init();
* Button_Init();
*
* // In Task_10ms
* Button_Debounce();
* @endcode
*
* ----------------------
* - HISTORY OF CHANGES -
* ----------------------
* Date Version Author Description
* 04/01/15 1.0.0 Jacob Beningo Initial Release.
*
*******************************************************************************/
void Button_Debounce(void)
{
uint8_t Index = 0;
/* Loop through all of the buttons, read their state and determine if
* any of their states have changed.
*/
for(Index = 0; Index < BUTTON_MAX_NUMBER; Index++)
{
/* Check to see if the pin reading is different than the current
* debounced button state. If it is different then the debounce
* counter for this pin will be incremented. If it is the same
* the counter will be cleared.
*/
if(Gpio_ChannelRead(ButtonList[Index]) != ButtonCurrentState[Index])
{
ButtonDebounceCount[Index]++;
/* Check to see if the debounce count has met or exceeded the
* required count. If it has, then the state of the button is
* updated. Otherwise it is left as is.
*/
if(ButtonDebounceCount[Index] >= ButtonDebounceCountList[Index])
{
if(ButtonCurrentState[Index] == BUTTON_STATE_NOT_PRESSED)
{
ButtonCurrentState[Index] = BUTTON_STATE_PRESSED;
}
else
{
ButtonCurrentState[Index] = BUTTON_STATE_NOT_PRESSED;
}
}
}
else
{
ButtonDebounceCount[Index] = 0;
}
} // End for loop
}
/******************************************************************************
* Function : Button_StateGet()
*//**
* \b Description:
*
* This function is used to return the current state of a button to the application.
* The application can then use this information to run a state machine or
* perform other related tasks.
*
* @param Button Button_t, a system button defined in the Button_t enum
*
* @return Button_State_t the debounced state of the button
*
* @see Button_Init
* @see Button_Debounce
* @see Button_StateGet
*
* \b Example Example:
* @code
* // In System_Init
* Gpio_Init();
* Button_Init();
*
* // In Task_10ms
* Button_Debounce();
*
* Button_MenuState = Button_StateGet(BUTTON_MENU);
*
* if(Button_MenuState == BUTTON_PRESSED)
* {
* Led_Toggle(LED_RED);
* }
* @endcode
*
* ----------------------
* - HISTORY OF CHANGES -
* ----------------------
* Date Version Author Description
* 04/01/15 1.0.0 Jacob Beningo Initial Release.
*
*******************************************************************************/
Button_State_t Button_StateGet(Button_t Button)
{
Button_State_t State;
/* Verify that the requested button exists and
* return its state. If it doesn't exist, then
* return the MAX as an error code.
*/
if(Button < BUTTON_MAX_NUMBER)
{
State = ButtonCurrentState[Button];
}
else
{
State = BUTTON_STATE_MAX;
}
return State;
}
/*************** END OF FUNCTIONS
***************************************************************************/