Add inputs controller

This commit is contained in:
2026-04-01 13:29:40 -05:00
parent 837c3eacda
commit 1b4795b4de
2 changed files with 220 additions and 15 deletions
+31 -15
View File
@@ -3,7 +3,9 @@
#include "blk_box_drivers/i2c.h"
#include <freertos/FreeRTOS.h>
#include <freertos/queue.h>
#include <freertos/semphr.h>
#include <optional>
#define EXPANDER_I2C_ADDR (0x7E)
#define EXPANDER_I2C_SPEED (400000)
@@ -195,23 +197,37 @@ struct ExpanderState {
ExpanderState() : touch_state(0), button_state(0), switch_state(0), keypad_state(0), hal_sense(0), close_hal_sense(0), hal(0), close_hal(0), rfid_state(0) {}
};
/// The global data for the expander peripheral.
class ExpanderPeripheral {
// TODO: change these to private
public:
SemaphoreHandle_t state_mutex;
ExpanderState state;
class InputsController {
public:
void clear_all_events();
// 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;
bool has_button_press() const;
std::optional<Button> get_button_press();
Button wait_button_press();
uint8_t button_state();
bool has_button_release() const;
std::optional<Button> get_button_release();
Button wait_button_release();
bool has_switch_flip() const;
std::optional<SwitchFlip> get_switch_flip();
SwitchFlip wait_switch_flip();
uint8_t switch_state();
bool has_switch_touch() const;
std::optional<SwitchTouch> get_switch_touch();
SwitchTouch wait_switch_touch();
uint8_t switch_touch_state();
bool has_keypad_press() const;
std::optional<KeypadKey> get_keypad_press();
KeypadKey wait_keypad_press();
bool has_keypad_release() const;
std::optional<KeypadKey> get_keypad_release();
KeypadKey wait_keypad_release();
uint16_t keypad_state();
};
#endif // EXPANDER_H