cleanup expander

This commit is contained in:
2026-04-01 15:55:23 -05:00
parent 1b4795b4de
commit c82c9adf32
2 changed files with 92 additions and 58 deletions
+20 -29
View File
@@ -157,8 +157,6 @@ static void expander_task(void *arg) {
// Wait for interrupt notification (signal is sent when INT falls)
ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
// loop continues and will process events once INT goes low
printf("WAKE\n");
}
}
@@ -222,9 +220,7 @@ static void handle_button_switch_event(uint8_t event) {
Switch sw = static_cast<Switch>(number);
SwitchFlip sw_flip = SwitchFlip(sw, pressed);
if (xQueueSendToBack(expander_peripheral_singleton.switch_flip_events, &sw_flip, 0) != pdTRUE) {
ESP_LOGE(TAG, "Failed to send switch flip event!");
}
xQueueSendToBack(expander_peripheral_singleton.switch_flip_events, &sw_flip, 0);
xSemaphoreTake(expander_peripheral_singleton.state_mutex, portMAX_DELAY);
if (pressed) {
// set
@@ -238,16 +234,12 @@ static void handle_button_switch_event(uint8_t event) {
// button
Button button = static_cast<Button>(number);
if (pressed) {
if (xQueueSendToBack(expander_peripheral_singleton.button_press_events, &button, 0) != pdTRUE) {
ESP_LOGE(TAG, "Failed to send button press event!");
}
xQueueSendToBack(expander_peripheral_singleton.button_press_events, &button, 0);
xSemaphoreTake(expander_peripheral_singleton.state_mutex, portMAX_DELAY);
expander_peripheral_singleton.state.button_state |= 1 << number;
xSemaphoreGive(expander_peripheral_singleton.state_mutex);
} else {
if (xQueueSendToBack(expander_peripheral_singleton.button_release_events, &button, 0) != pdTRUE) {
ESP_LOGE(TAG, "Failed to send button release event!");
}
xQueueSendToBack(expander_peripheral_singleton.button_release_events, &button, 0);
xSemaphoreTake(expander_peripheral_singleton.state_mutex, portMAX_DELAY);
expander_peripheral_singleton.state.button_state &= ~(1 << number);
xSemaphoreGive(expander_peripheral_singleton.state_mutex);
@@ -270,16 +262,12 @@ static void handle_keypad_event(uint8_t event) {
// }
if (pressed) {
if (xQueueSendToBack(expander_peripheral_singleton.keypad_press_events, &key, 0) != pdTRUE) {
ESP_LOGE(TAG, "Failed to send keypad press event!");
}
xQueueSendToBack(expander_peripheral_singleton.keypad_press_events, &key, 0);
xSemaphoreTake(expander_peripheral_singleton.state_mutex, portMAX_DELAY);
expander_peripheral_singleton.state.keypad_state |= 1 << number;
xSemaphoreGive(expander_peripheral_singleton.state_mutex);
} else {
if (xQueueSendToBack(expander_peripheral_singleton.keypad_release_events, &key, 0) != pdTRUE) {
ESP_LOGE(TAG, "Failed to send keypad release event!");
}
xQueueSendToBack(expander_peripheral_singleton.keypad_release_events, &key, 0);
xSemaphoreTake(expander_peripheral_singleton.state_mutex, portMAX_DELAY);
expander_peripheral_singleton.state.keypad_state &= ~(1 << number);
xSemaphoreGive(expander_peripheral_singleton.state_mutex);
@@ -296,15 +284,11 @@ static void handle_touch_event(uint8_t event) {
if ((sensor & FINGERPRINT_BIT) != 0) {
TouchedReleased touch_state = static_cast<TouchedReleased>(touched);
if (xQueueSendToBack(expander_peripheral_singleton.touch_events, &touch_state, 0) != pdTRUE) {
ESP_LOGE(TAG, "Failed to send touch event!");
}
xQueueSendToBack(expander_peripheral_singleton.touch_events, &touch_state, 0);
} else {
Switch sw = static_cast<Switch>(sensor);
SwitchTouch sw_touch = SwitchTouch(sw, touched);
if (xQueueSendToBack(expander_peripheral_singleton.switch_touch_events, &sw_touch, 0) != pdTRUE) {
ESP_LOGE(TAG, "Failed to send switch touch event!");
}
xQueueSendToBack(expander_peripheral_singleton.switch_touch_events, &sw_touch, 0);
}
xSemaphoreTake(expander_peripheral_singleton.state_mutex, portMAX_DELAY);
@@ -339,8 +323,15 @@ void InputsController::clear_all_events() {
xQueueReset(expander_peripheral_singleton.keypad_release_events);
}
ExpanderState InputsController::get_input_state() {
xSemaphoreTake(expander_peripheral_singleton.state_mutex, portMAX_DELAY);
ExpanderState state_copy = expander_peripheral_singleton.state;
xSemaphoreGive(expander_peripheral_singleton.state_mutex);
return state_copy;
}
/// Returns `true` iff there is a button press event waiting.
bool InputsController::has_button_press() const {
bool InputsController::has_button_press() {
return uxQueueMessagesWaiting(expander_peripheral_singleton.button_press_events) > 0;
}
@@ -369,7 +360,7 @@ uint8_t InputsController::button_state() {
}
/// Returns `true` iff there is a button release event waiting.
bool InputsController::has_button_release() const {
bool InputsController::has_button_release() {
return uxQueueMessagesWaiting(expander_peripheral_singleton.button_release_events) > 0;
}
@@ -390,7 +381,7 @@ Button InputsController::wait_button_release() {
}
/// Returns `true` iff there is a switch flip event waiting.
bool InputsController::has_switch_flip() const {
bool InputsController::has_switch_flip() {
return uxQueueMessagesWaiting(expander_peripheral_singleton.switch_flip_events) > 0;
}
@@ -419,7 +410,7 @@ uint8_t InputsController::switch_state() {
}
/// Returns `true` iff there is a switch touch event waiting.
bool InputsController::has_switch_touch() const {
bool InputsController::has_switch_touch() {
return uxQueueMessagesWaiting(expander_peripheral_singleton.switch_touch_events) > 0;
}
@@ -448,7 +439,7 @@ uint8_t InputsController::switch_touch_state() {
}
/// Returns `true` iff there is a keypad press event waiting.
bool InputsController::has_keypad_press() const {
bool InputsController::has_keypad_press() {
return uxQueueMessagesWaiting(expander_peripheral_singleton.keypad_press_events) > 0;
}
@@ -469,7 +460,7 @@ KeypadKey InputsController::wait_keypad_press() {
}
/// Returns `true` iff there is a keypad release event waiting.
bool InputsController::has_keypad_release() const {
bool InputsController::has_keypad_release() {
return uxQueueMessagesWaiting(expander_peripheral_singleton.keypad_release_events) > 0;
}