extern void HandlePIOChangedEvent(uint32 pio_changed) { if(pio_changed & PIO_BIT_MASK(BUTTON_PIO)) { /* PIO changed */ uint32 pios = PioGets(); if(!(pios & PIO_BIT_MASK(BUTTON_PIO))) { /* This is for the case when pio changed event has come for button * press. */ /* Delete any button press timer if already running */ TimerDelete(g_app_hw_data.button_press_tid); g_app_hw_data.button_press_tid = TIMER_INVALID; /* Create a button press timer */ g_app_hw_data.button_press_tid = TimerCreate(LONG_BUTTON_PRESS_TIMER, TRUE, handleShortOrLongButtonPressTimerExpiry); /* Initialize the short (or) long button pressed flag with FALSE.*/ g_app_hw_data.long_or_short_button_pressed = FALSE; } else { /* This is for the case when pio changed event comes for * the button release */ if(g_app_hw_data.button_press_tid != TIMER_INVALID) { /* Button press timer is running.This means that either * 1.timer EXTRA_LONG_BUTTON_PRESS_TIMER has not expired yet * OR * 2.Timer EXTRA_LONG_BUTTON_PRESS_TIMER has expired but a 2nd * timer of length (EXTRA_LONG_BUTTON_PRESS_TIMER - * LONG_BUTTON_PRESS_TIMER) which we start on 1st timer * expiry, is still running. */ /* case when timer LONG_BUTTON_PRESS_TIMER is still running */ if(g_app_hw_data.long_or_short_button_pressed == FALSE) { HandleShortButtonPress(); } /* Delete the already running button press timer */ TimerDelete(g_app_hw_data.button_press_tid); g_app_hw_data.button_press_tid = TIMER_INVALID; g_app_hw_data.long_or_short_button_pressed = FALSE; } } } }
extern void HandlePIOChangedEvent(pio_changed_data *pio_data) { if(pio_data->pio_cause & BUTTON_PIO_MASK) { /* PIO changed */ uint32 pios = PioGets(); if(!(pios & BUTTON_PIO_MASK)) { /* This event comes when a button is pressed */ /* Start a timer for EXTRA_LONG_BUTTON_PRESS_TIMER seconds. * If timer expires before we receive a button release event then * it was a long press and if we receive a button release PIO * changed event, it means it was a short press. */ TimerDelete(g_weight_hw_data.button_press_tid); g_weight_hw_data.button_press_tid = TIMER_INVALID; g_weight_hw_data.button_press_tid = TimerCreate( EXTRA_LONG_BUTTON_PRESS_TIMER, TRUE, HandleExtraLongButtonPress); } else { if(g_weight_hw_data.button_press_tid != TIMER_INVALID) { /* Timer was already running. This means it was a short button * press. */ TimerDelete(g_weight_hw_data.button_press_tid); g_weight_hw_data.button_press_tid = TIMER_INVALID; AppHandleShortButtonPress(); } } } }
/*----------------------------------------------------------------------------* * NAME * HandlePIOChangedEvent * * DESCRIPTION * This function handles the PIO Changed event. * * PARAMETERS * pio_data [in] State of the PIOs when the event occurred * * RETURNS * Nothing *----------------------------------------------------------------------------*/ extern void HandlePIOChangedEvent(pio_changed_data *pio_data) { if(pio_data->pio_cause & BUTTON_PIO_MASK) { /* PIO changed */ uint32 pios = PioGets(); if(!(pios & BUTTON_PIO_MASK)) { /* This event is triggered when a button is pressed. */ /* Start a timer for EXTRA_LONG_BUTTON_PRESS_TIMER seconds. If the * timer expires before the button is released an extra long button * press is detected. If the button is released before the timer * expires a short button press is detected. */ TimerDelete(g_app_hw_data.button_press_tid); g_app_hw_data.button_press_tid = TimerCreate(EXTRA_LONG_BUTTON_PRESS_TIMER, TRUE, handleExtraLongButtonPress); } else { /* This event comes when a button is released. */ if(g_app_hw_data.button_press_tid != TIMER_INVALID) { /* Timer was already running. This means it was a short button * press. */ TimerDelete(g_app_hw_data.button_press_tid); g_app_hw_data.button_press_tid = TIMER_INVALID; /* Indicate short button press using short beep */ SoundBuzzer(buzzer_beep_short); HandleShortButtonPress(); } } } }