Add new button type, clean up pull-up resistor logic. #1

Merged
annabunches merged 8 commits from new-button-behaviors into main 2021-11-01 22:29:42 +00:00
Showing only changes of commit 398668205d - Show all commits

View File

@ -54,7 +54,7 @@ void Joystick::AddButton(uint8_t pin, ButtonType type, bool pullup) {
_buttons[_num_buttons] = button; _buttons[_num_buttons] = button;
_num_buttons++; _num_buttons++;
last_button_index += increment; _last_button_index += increment;
if (type & _BUTTON_PULSED_TYPES) _have_pulsed_button = true; if (type & _BUTTON_PULSED_TYPES) _have_pulsed_button = true;
} }
@ -67,11 +67,11 @@ void Joystick::AddAxis(uint8_t pin) {
void Joystick::Update() { void Joystick::Update() {
JoyReport oldReport = _joyReport; JoyReport oldReport = _joyReport;
for (uint i = 0; i < _num_buttons; i++) { for (uint8_t i = 0; i < _num_buttons; i++) {
_UpdateButton(i); _UpdateButton(i);
} }
for (int i = 0; i < _num_axes; i++) { for (uint8_t i = 0; i < _num_axes; i++) {
_UpdateAxis(i); _UpdateAxis(i);
} }
@ -111,8 +111,9 @@ void Joystick::ReleaseAllButtons() {
void Joystick::_ReleasePulsedButtons() { void Joystick::_ReleasePulsedButtons() {
for (uint8_t i = 0; i < _num_buttons; i++ ) { for (uint8_t i = 0; i < _num_buttons; i++ ) {
if (i->type & _BUTTON_PULSED_TYPES) ReleaseButton(_buttons[i].index0); Button button = _buttons[i];
if (i->type & BUTTON_PULSED_DOUBLE_ACTION_SPLIT) ReleaseButton(_buttons[i].index1); if (button.type & _BUTTON_PULSED_TYPES) ReleaseButton(button.index0);
if (button.type & BUTTON_PULSED_DOUBLE_ACTION_SPLIT) ReleaseButton(button.index1);
} }
} }
@ -136,7 +137,7 @@ void Joystick::Write() {
} }
void Joystick::_UpdateButton(uint8_t button_num) { void Joystick::_UpdateButton(uint8_t button_num) {
Button *button = &_button[button_num]; Button *button = &_buttons[button_num];
bool changed = button->bouncer.update(); bool changed = button->bouncer.update();
switch (button->type) { switch (button->type) {
@ -156,13 +157,14 @@ void Joystick::_UpdateButton(uint8_t button_num) {
break; break;
case BUTTON_LATCHED_MOMENTARY: case BUTTON_LATCHED_MOMENTARY:
if (button->bouncer.rose()) { if (button->bouncer.rose()) {
if !(button->pressed) { if (!button->pressed) {
PressButton(button->index0); PressButton(button->index0);
button->pressed = true; button->pressed = true;
} else { } else {
ReleaseButton(button->index0); ReleaseButton(button->index0);
button->pressed = false; button->pressed = false;
} }
}
break; break;
default: default:
if (_debug) { if (_debug) {