Fixed various errors.

This commit is contained in:
Anna Rose 2021-11-01 15:44:32 -04:00
parent 2a35a86230
commit 398668205d

View File

@ -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) {