Revert to non-STL-using code, since that's not available when compiling for Arduino...

This commit is contained in:
Anna Rose 2021-11-01 15:38:01 -04:00
parent 6a692687f5
commit 5322744f42
2 changed files with 12 additions and 9 deletions

View File

@ -55,7 +55,8 @@ void Joystick::AddButton(uint8_t pin, ButtonType type, bool pullup) {
// todo: fail here // todo: fail here
} }
_buttons.push_back(button); _buttons[_num_buttons] = button;
_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;
@ -69,8 +70,8 @@ void Joystick::AddAxis(uint8_t pin) {
void Joystick::Update() { void Joystick::Update() {
JoyReport oldReport = _joyReport; JoyReport oldReport = _joyReport;
for (list<Button>::iterator cursor = _buttons.begin(); cursor != _buttons.end(); cursor++) { for (uint i = 0; i < _num_buttons; i++) {
_UpdateButton(*cursor); _UpdateButton(i);
} }
for (int i = 0; i < _num_axes; i++) { for (int i = 0; i < _num_axes; i++) {
@ -112,9 +113,9 @@ void Joystick::ReleaseAllButtons() {
} }
void Joystick::_ReleasePulsedButtons() { void Joystick::_ReleasePulsedButtons() {
for (list<Button>::iterator i = _buttons.begin(); i != buttons.end(); i++) { for (uint8_t i = 0; i < _num_buttons; i++ ) {
if (i->type & _BUTTON_PULSED_TYPES) ReleaseButton(i->index0); if (i->type & _BUTTON_PULSED_TYPES) ReleaseButton(_buttons[i].index0);
if (i->type & BUTTON_PULSED_DOUBLE_ACTION_SPLIT) ReleaseButton(i->index1); if (i->type & BUTTON_PULSED_DOUBLE_ACTION_SPLIT) ReleaseButton(_buttons[i].index1);
} }
} }
@ -137,7 +138,8 @@ void Joystick::Write() {
delay(250); delay(250);
} }
void Joystick::_UpdateButton(Button* button) { void Joystick::_UpdateButton(uint8_t button_num) {
Button *button = &_button[button_num];
bool changed = button->bouncer.update(); bool changed = button->bouncer.update();
switch (button->type) { switch (button->type) {

View File

@ -65,8 +65,9 @@ class Joystick {
void _UpdateButton(uint8_t index); void _UpdateButton(uint8_t index);
void _UpdateAxis(uint8_t index); void _UpdateAxis(uint8_t index);
list<Button> _buttons; Button _buttons[JOYSTICK_NUM_BUTTONS];
uint8_t _last_button_index; uint8_t _num_buttons;
uint8_t _last_button_index; // a single physical button can have multiple logical buttons. _last_button_index tracks the number of logical / virtual buttons we have defined.
bool _have_pulsed_button; bool _have_pulsed_button;
uint8_t _axes[JOYSTICK_NUM_AXES]; uint8_t _axes[JOYSTICK_NUM_AXES];