Handle buttons & encoders in View, not Model
This commit is contained in:
36
Core/Src/STWButtonController.cpp
Normal file
36
Core/Src/STWButtonController.cpp
Normal file
@ -0,0 +1,36 @@
|
||||
#include "STWButtonController.hpp"
|
||||
|
||||
#include "main.h"
|
||||
#include "tx_api.h"
|
||||
#include "ui.h"
|
||||
|
||||
void STWButtonController::init() {}
|
||||
|
||||
bool STWButtonController::sample(uint8_t &key) {
|
||||
ButtonMessage msg;
|
||||
if (tx_queue_receive(&gui_button_queue, &msg, TX_NO_WAIT) == TX_SUCCESS) {
|
||||
switch (msg.kind) {
|
||||
case UMK_BTN_RELEASED:
|
||||
key = KEY_BTN1 + msg.number;
|
||||
break;
|
||||
case UMK_ENC_CW: {
|
||||
if (msg.number == 0) {
|
||||
key = KEY_ENC1_CW;
|
||||
} else {
|
||||
key = KEY_ENC2_CW;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case UMK_ENC_CCW:
|
||||
if (msg.number == 0) {
|
||||
key = KEY_ENC1_CCW;
|
||||
} else {
|
||||
key = KEY_ENC2_CCW;
|
||||
}
|
||||
}
|
||||
HAL_GPIO_TogglePin(STATUS2_GPIO_Port, STATUS2_Pin);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
Reference in New Issue
Block a user