From 398668205da4e5ef22f610b3677324fcf495352b Mon Sep 17 00:00:00 2001 From: annabunches Date: Mon, 1 Nov 2021 15:44:32 -0400 Subject: [PATCH] Fixed various errors. --- Joystick.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/Joystick.cpp b/Joystick.cpp index 23613dd..0814b09 100644 --- a/Joystick.cpp +++ b/Joystick.cpp @@ -54,7 +54,7 @@ void Joystick::AddButton(uint8_t pin, ButtonType type, bool pullup) { _buttons[_num_buttons] = button; _num_buttons++; - last_button_index += increment; + _last_button_index += increment; if (type & _BUTTON_PULSED_TYPES) _have_pulsed_button = true; } @@ -67,11 +67,11 @@ void Joystick::AddAxis(uint8_t pin) { void Joystick::Update() { JoyReport oldReport = _joyReport; - for (uint i = 0; i < _num_buttons; i++) { + for (uint8_t i = 0; i < _num_buttons; i++) { _UpdateButton(i); } - for (int i = 0; i < _num_axes; i++) { + for (uint8_t i = 0; i < _num_axes; i++) { _UpdateAxis(i); } @@ -111,8 +111,9 @@ void Joystick::ReleaseAllButtons() { void Joystick::_ReleasePulsedButtons() { for (uint8_t i = 0; i < _num_buttons; i++ ) { - if (i->type & _BUTTON_PULSED_TYPES) ReleaseButton(_buttons[i].index0); - if (i->type & BUTTON_PULSED_DOUBLE_ACTION_SPLIT) ReleaseButton(_buttons[i].index1); + Button button = _buttons[i]; + 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) { - Button *button = &_button[button_num]; + Button *button = &_buttons[button_num]; bool changed = button->bouncer.update(); switch (button->type) { @@ -156,13 +157,14 @@ void Joystick::_UpdateButton(uint8_t button_num) { break; case BUTTON_LATCHED_MOMENTARY: if (button->bouncer.rose()) { - if !(button->pressed) { + if (!button->pressed) { PressButton(button->index0); button->pressed = true; } else { ReleaseButton(button->index0); button->pressed = false; } + } break; default: if (_debug) {