From 9af6a589f86b20ff7f3b4bad95246aa2e40886b7 Mon Sep 17 00:00:00 2001 From: Anna Wiggins Date: Sun, 8 Nov 2015 23:15:58 -0500 Subject: [PATCH] Fix code to compile, now that I am in an environment where I can compile. This commit not tested. --- Joystick.cpp | 17 +++++++++++++++-- Joystick.h | 4 ++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/Joystick.cpp b/Joystick.cpp index 8b4c30a..0a11196 100644 --- a/Joystick.cpp +++ b/Joystick.cpp @@ -1,11 +1,20 @@ #include "Joystick.h" #include +bool operator ==(JoyReport a, JoyReport b){ + return a.axis == b.axis && a.button == b.button; +} + +bool operator !=(JoyReport a, JoyReport b){ + return !(a == b); +} + Joystick::Joystick(bool debug) { _debug = debug; _num_buttons = 0; _num_axes = 0; - + _have_pulsed_button = false; + for (uint8_t i=0; i < JOYSTICK_NUM_AXES; i++) { _joyReport.axis[i] = 0; } @@ -29,6 +38,10 @@ void Joystick::AddButton(uint8_t pin, ButtonType type, bool pullup) { _buttons[_num_buttons].type = type; _buttons[_num_buttons].last_state = digitalRead(pin); _num_buttons++; + + if (type == BUTTON_PULSED || type == BUTTON_PULSED_DOUBLE_ACTION) { + _have_pulsed_button = true; + } } void Joystick::AddAxis(uint8_t pin) { @@ -51,7 +64,7 @@ void Joystick::Update() { } if (_joyReport != oldReport) { - Serial.write(_joyReport); + Write(); } } diff --git a/Joystick.h b/Joystick.h index b97e542..5504a7b 100644 --- a/Joystick.h +++ b/Joystick.h @@ -25,6 +25,9 @@ typedef struct JoyReport { uint8_t button[JOYSTICK_NUM_BYTES]; } ; +bool operator ==(JoyReport a, JoyReport b); +bool operator !=(JoyReport a, JoyReport b); + class Joystick { public: Joystick(bool debug=false); @@ -49,6 +52,7 @@ class Joystick { uint8_t last_state; } _buttons[JOYSTICK_NUM_BUTTONS]; uint8_t _num_buttons; + bool _have_pulsed_button; uint8_t _axes[JOYSTICK_NUM_AXES]; uint8_t _num_axes;