Add BUTTON_LATCHED_MOMENTARY type, to allow a pushbutton to mimic the behavior of a toggle switch.
This commit is contained in:
12
Joystick.cpp
12
Joystick.cpp
@ -50,7 +50,7 @@ void Joystick::AddButton(uint8_t pin, ButtonType type, bool pullup) {
|
||||
increment = 2;
|
||||
button.index1 = index + 1;
|
||||
}
|
||||
|
||||
|
||||
if (_last_button_index + increment > JOYSTICK_NUM_BUTTONS) {
|
||||
// todo: fail here
|
||||
}
|
||||
@ -155,6 +155,16 @@ void Joystick::_UpdateButton(Button* button) {
|
||||
if (button->bouncer.rose()) PressButton(button->index0);
|
||||
else if (button->bouncer.fell()) PressButton(button->index1);
|
||||
break;
|
||||
case BUTTON_LATCHED_MOMENTARY:
|
||||
if (button->bouncer.rose()) {
|
||||
if !(button->pressed) {
|
||||
PressButton(button->index0);
|
||||
button->pressed = true;
|
||||
} else {
|
||||
ReleaseButton(button->index0);
|
||||
button->pressed = false;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (_debug) {
|
||||
Serial.print("DEBUG: Unhandled button type: ");
|
||||
|
Reference in New Issue
Block a user