Add BUTTON_LATCHED_MOMENTARY type, to allow a pushbutton to mimic the behavior of a toggle switch.

This commit is contained in:
2021-11-01 15:24:05 -04:00
parent c37e4a6789
commit 6a692687f5
3 changed files with 37 additions and 3 deletions

View File

@ -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: ");