For pulsed buttons, implement per-button 'timers' that independently end the pulse instead of having a 250ms delay between every single update...
This commit is contained in:
22
Joystick.cpp
22
Joystick.cpp
@ -25,7 +25,6 @@ Joystick::Joystick(bool debug) {
|
||||
_virtual_buttons = 0;
|
||||
_num_axes = 0;
|
||||
_num_buttons = 0;
|
||||
_have_pulsed_button = false;
|
||||
|
||||
for (uint8_t i=0; i < JOYSTICK_NUM_AXES; i++) {
|
||||
_joyReport.axis[i] = 0;
|
||||
@ -70,7 +69,6 @@ void Joystick::AddButton(uint8_t pin, ButtonType type, bool pullup, Mux* mux, bo
|
||||
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;
|
||||
}
|
||||
|
||||
void Joystick::AddEncoder(uint8_t pin1, uint8_t pin2, ButtonType type) {
|
||||
@ -115,10 +113,6 @@ void Joystick::Update() {
|
||||
|
||||
if (_joyReport != oldReport) {
|
||||
Write();
|
||||
if (_have_pulsed_button) {
|
||||
_ReleasePulsedButtons();
|
||||
Write();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -147,18 +141,8 @@ void Joystick::ReleaseAllButtons() {
|
||||
}
|
||||
}
|
||||
|
||||
void Joystick::_ReleasePulsedButtons() {
|
||||
for (uint8_t i = 0; i < _num_buttons; i++ ) {
|
||||
Button* button = _buttons[i];
|
||||
if (button->type & _BUTTON_PULSED_TYPES) button->ReleaseButtons(this);
|
||||
}
|
||||
}
|
||||
|
||||
void Joystick::Write() {
|
||||
if (!_debug) {
|
||||
Serial.write((uint8_t *)&_joyReport, sizeof(JoyReport));
|
||||
}
|
||||
else {
|
||||
if (_debug) {
|
||||
Serial.print("DEBUG: Writing data: ");
|
||||
for (uint8_t i=0; i < JOYSTICK_NUM_AXES; i++) {
|
||||
Serial.print(_joyReport.axis[i]);
|
||||
@ -169,8 +153,10 @@ void Joystick::Write() {
|
||||
Serial.print(" ");
|
||||
}
|
||||
Serial.println();
|
||||
return;
|
||||
}
|
||||
delay(250);
|
||||
|
||||
Serial.write((uint8_t *)&_joyReport, sizeof(JoyReport));
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user