diff --git a/drivers/expander.cpp b/drivers/expander.cpp index 990caca..06b001b 100644 --- a/drivers/expander.cpp +++ b/drivers/expander.cpp @@ -31,6 +31,24 @@ const static uint8_t REG_HALL_SENSITIVITY = 0x31; const static uint8_t REG_CLOSE_SENSITIVITY = 0x32; const static uint8_t REG_SWITCH_TOUCH_EVENT = 0x33; +/// The global data for the expander peripheral. +class ExpanderPeripheral { + // TODO: change these to private + // or even make this class hidden + public: + SemaphoreHandle_t state_mutex; + ExpanderState state; + + // channels + QueueHandle_t button_press_events; + QueueHandle_t button_release_events; + QueueHandle_t switch_flip_events; + QueueHandle_t switch_touch_events; + QueueHandle_t touch_events; + QueueHandle_t keypad_press_events; + QueueHandle_t keypad_release_events; +}; + ExpanderPeripheral expander_peripheral_singleton; // forward declarations @@ -308,3 +326,174 @@ static void handle_close_hal_event(uint8_t event) { (void)event; } +// InputsController implementations + +/// Clears all events waiting in the queues. +void InputsController::clear_all_events() { + xQueueReset(expander_peripheral_singleton.button_press_events); + xQueueReset(expander_peripheral_singleton.button_release_events); + xQueueReset(expander_peripheral_singleton.switch_flip_events); + xQueueReset(expander_peripheral_singleton.switch_touch_events); + xQueueReset(expander_peripheral_singleton.touch_events); + xQueueReset(expander_peripheral_singleton.keypad_press_events); + xQueueReset(expander_peripheral_singleton.keypad_release_events); +} + +/// Returns `true` iff there is a button press event waiting. +bool InputsController::has_button_press() const { + return uxQueueMessagesWaiting(expander_peripheral_singleton.button_press_events) > 0; +} + +/// Gets the next button press event (if any). +std::optional