Add new button type, clean up pull-up resistor logic. #1
16
Joystick.cpp
16
Joystick.cpp
|
@ -55,7 +55,8 @@ void Joystick::AddButton(uint8_t pin, ButtonType type, bool pullup) {
|
|||
// todo: fail here
|
||||
}
|
||||
|
||||
_buttons.push_back(button);
|
||||
_buttons[_num_buttons] = button;
|
||||
_num_buttons++;
|
||||
last_button_index += increment;
|
||||
|
||||
if (type & _BUTTON_PULSED_TYPES) _have_pulsed_button = true;
|
||||
|
@ -69,8 +70,8 @@ void Joystick::AddAxis(uint8_t pin) {
|
|||
void Joystick::Update() {
|
||||
JoyReport oldReport = _joyReport;
|
||||
|
||||
for (list<Button>::iterator cursor = _buttons.begin(); cursor != _buttons.end(); cursor++) {
|
||||
_UpdateButton(*cursor);
|
||||
for (uint i = 0; i < _num_buttons; i++) {
|
||||
_UpdateButton(i);
|
||||
}
|
||||
|
||||
for (int i = 0; i < _num_axes; i++) {
|
||||
|
@ -112,9 +113,9 @@ void Joystick::ReleaseAllButtons() {
|
|||
}
|
||||
|
||||
void Joystick::_ReleasePulsedButtons() {
|
||||
for (list<Button>::iterator i = _buttons.begin(); i != buttons.end(); i++) {
|
||||
if (i->type & _BUTTON_PULSED_TYPES) ReleaseButton(i->index0);
|
||||
if (i->type & BUTTON_PULSED_DOUBLE_ACTION_SPLIT) ReleaseButton(i->index1);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -137,7 +138,8 @@ void Joystick::Write() {
|
|||
delay(250);
|
||||
}
|
||||
|
||||
void Joystick::_UpdateButton(Button* button) {
|
||||
void Joystick::_UpdateButton(uint8_t button_num) {
|
||||
Button *button = &_button[button_num];
|
||||
bool changed = button->bouncer.update();
|
||||
|
||||
switch (button->type) {
|
||||
|
|
|
@ -65,8 +65,9 @@ class Joystick {
|
|||
void _UpdateButton(uint8_t index);
|
||||
void _UpdateAxis(uint8_t index);
|
||||
|
||||
list<Button> _buttons;
|
||||
uint8_t _last_button_index;
|
||||
Button _buttons[JOYSTICK_NUM_BUTTONS];
|
||||
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;
|
||||
|
||||
uint8_t _axes[JOYSTICK_NUM_AXES];
|
||||
|
|
Loading…
Reference in New Issue
Block a user