Add some additionally debugging, fix the 'ole broken switch statement.

This commit is contained in:
2021-11-09 06:11:36 +00:00
parent a69c2d3364
commit e09c21edf1
4 changed files with 46 additions and 17 deletions

View File

@ -2,6 +2,7 @@
#include "Button.h"
#include <Mux.h>
#include <Arduino.h>
#include <stdio.h>
using namespace admux;
@ -45,21 +46,30 @@ void Joystick::AddButton(uint8_t pin, ButtonType type, bool pullup, Mux* mux) {
case BUTTON_PASSTHRU:
button = new PassthruButton(pin, _virtual_buttons, pullup, mux);
_virtual_buttons++;
break;
case BUTTON_PULSED:
button = new PulsedButton(pin, _virtual_buttons, false, false, pullup, mux);
_virtual_buttons++;
break;
case BUTTON_PULSED_DOUBLE_ACTION:
button = new PulsedButton(pin, _virtual_buttons, true, false, pullup, mux);
_virtual_buttons++;
break;
case BUTTON_PULSED_DOUBLE_ACTION_SPLIT:
button = new PulsedButton(pin, _virtual_buttons, true, true, pullup, mux);
_virtual_buttons += 2;
break;
default:
return;
}
_buttons[_num_buttons] = button;
_num_buttons++;
if (_debug) {
char buffer[100];
sprintf(buffer, "Added button %d of type %d", _num_buttons - 1, button->type);
Serial.println(buffer);
}
if (type & _BUTTON_PULSED_TYPES) _have_pulsed_button = true;
}
@ -90,7 +100,12 @@ void Joystick::Update() {
JoyReport oldReport = _joyReport;
for (uint8_t i = 0; i < _num_buttons; i++) {
_buttons[i]->Update(this);
bool changed = _buttons[i]->Update(this);
if (changed && _debug) {
char buffer[25];
sprintf(buffer, "Button %d changed state.", i);
Serial.println(buffer);
}
}
// TODO: implement this and also refactor it into a class or classes