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

@ -48,10 +48,11 @@ PassthruButton::PassthruButton(uint8_t pin, uint8_t vbutton, bool pullup, Mux* m
this->type = BUTTON_PASSTHRU;
}
void PassthruButton::Update(Joystick* js) {
if (!BouncerUpdate()) return;
bool PassthruButton::Update(Joystick* js) {
if (!BouncerUpdate()) return false;
if (On()) js->PressButton(vbutton);
else js->ReleaseButton(vbutton);
return true;
}
@ -60,8 +61,8 @@ LatchedButton::LatchedButton(uint8_t pin, uint8_t vbutton, bool pullup, Mux* mux
this->pressed = false;
}
void LatchedButton::Update(Joystick* js) {
if (!BouncerUpdate()) return;
bool LatchedButton::Update(Joystick* js) {
if (!BouncerUpdate()) return false;
if (On()) {
if (!pressed) {
@ -72,6 +73,8 @@ void LatchedButton::Update(Joystick* js) {
pressed = false;
}
}
return true;
}
@ -88,8 +91,8 @@ PulsedButton::PulsedButton(uint8_t pin, uint8_t vbutton, bool double_action, boo
}
}
void PulsedButton::Update(Joystick* js) {
if (!BouncerUpdate()) return;
bool PulsedButton::Update(Joystick* js) {
if (!BouncerUpdate()) return false;
switch(type) {
case BUTTON_PULSED:
@ -103,6 +106,8 @@ void PulsedButton::Update(Joystick* js) {
else js->PressButton(vbutton2);
break;
}
return true;
}
void PulsedButton::ReleaseButtons(Joystick* js) {
@ -119,11 +124,19 @@ EncoderButton::EncoderButton(uint8_t pin1, uint8_t pin2, uint8_t vbutton) : Butt
this->last_value = encoder->read();
}
void EncoderButton::Update(Joystick* js) {
bool EncoderButton::Update(Joystick* js) {
bool changed = false;
long new_value = encoder->read();
if (new_value > last_value) js->PressButton(vbutton);
else if (new_value < last_value) js->PressButton(vbutton2);
if (new_value > last_value) {
js->PressButton(vbutton);
changed = true;
}
else if (new_value < last_value) {
js->PressButton(vbutton2);
changed = true;
}
last_value = new_value;
return changed;
}
void EncoderButton::ReleaseButtons(Joystick* js) {