feat: add support for long press callbacks in encoder library

This commit is contained in:
2026-04-04 08:49:50 -07:00
parent be760e6dd5
commit 5c0c34f564

View File

@ -21,6 +21,7 @@ class Encoder {
typedef void (*CallbackFunction)(void);
typedef void (*RotateCallbackFunction)(int val);
CallbackFunction on_press;
CallbackFunction on_long_press;
RotateCallbackFunction on_press_rotate;
RotateCallbackFunction on_rotate;
int change;
@ -40,6 +41,10 @@ class Encoder {
on_press = f;
}
void AttachLongPressHandler(CallbackFunction f) {
on_long_press = f;
}
void AttachRotateHandler(RotateCallbackFunction f) {
on_rotate = f;
}
@ -62,6 +67,8 @@ class Encoder {
if (on_rotate != NULL) on_rotate(change);
} else if (button_.Change() == Button::CHANGE_RELEASED && !rotated_while_held_) {
if (on_press != NULL) on_press();
} else if (button_.Change() == Button::CHANGE_RELEASED_LONG && !rotated_while_held_) {
if (on_long_press != NULL) on_long_press();
}
// Reset rotate while held state.