Input Handling
Button and encoder input
Input Callback
Use the on_input callback in your app descriptor:
void my_input(os_app_t* app, uint8_t btn, KeyStateEnum state) {
if (btn == 3 && state == KEY_STATE_HOLD) {
os_app_exit();
}
}Button IDs
| ID | Name | Common Use |
|---|---|---|
| 0 | BTN1 | Select |
| 1 | BTN2 | - |
| 2 | BTN3 | - |
| 3 | BTN4 | Back/Exit |
| 4 | BTN5 | - |
| 5 | ENCODER_I | Rotation notification — see below, NOT a button |
There is no encoder push button. ID 5 fires when the encoder is turned, and the firmware sends it with a zero-initialised state, so state is always KEY_STATE_RELEASED. Never branch on the state for ID 5 — either ignore the event and poll os_controls_encoder_get_delta() from tick(), or use ID 5 purely as a "something moved" hint and read the delta in response.
int32_t os_controls_encoder_get_delta(void)
Get encoder rotation delta since last call
Returns — Signed delta (positive = clockwise, negative = counter-clockwise)
int32_t diff = os_controls_encoder_get_delta();
if (diff != 0) {
model->value += diff;
}