feat: add support for long press callbacks in encoder library
This commit is contained in:
@ -21,6 +21,7 @@ class Encoder {
|
|||||||
typedef void (*CallbackFunction)(void);
|
typedef void (*CallbackFunction)(void);
|
||||||
typedef void (*RotateCallbackFunction)(int val);
|
typedef void (*RotateCallbackFunction)(int val);
|
||||||
CallbackFunction on_press;
|
CallbackFunction on_press;
|
||||||
|
CallbackFunction on_long_press;
|
||||||
RotateCallbackFunction on_press_rotate;
|
RotateCallbackFunction on_press_rotate;
|
||||||
RotateCallbackFunction on_rotate;
|
RotateCallbackFunction on_rotate;
|
||||||
int change;
|
int change;
|
||||||
@ -40,6 +41,10 @@ class Encoder {
|
|||||||
on_press = f;
|
on_press = f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AttachLongPressHandler(CallbackFunction f) {
|
||||||
|
on_long_press = f;
|
||||||
|
}
|
||||||
|
|
||||||
void AttachRotateHandler(RotateCallbackFunction f) {
|
void AttachRotateHandler(RotateCallbackFunction f) {
|
||||||
on_rotate = f;
|
on_rotate = f;
|
||||||
}
|
}
|
||||||
@ -62,6 +67,8 @@ class Encoder {
|
|||||||
if (on_rotate != NULL) on_rotate(change);
|
if (on_rotate != NULL) on_rotate(change);
|
||||||
} else if (button_.Change() == Button::CHANGE_RELEASED && !rotated_while_held_) {
|
} else if (button_.Change() == Button::CHANGE_RELEASED && !rotated_while_held_) {
|
||||||
if (on_press != NULL) on_press();
|
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.
|
// Reset rotate while held state.
|
||||||
|
|||||||
Reference in New Issue
Block a user