Bedtime. /Input Handling

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

IDNameCommon Use
0BTN1Select
1BTN2-
2BTN3-
3BTN4Back/Exit
4BTN5-
5ENCODER_IRotation 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;
}