Fix code to compile, now that I am in an environment where I can compile. This commit not tested.

This commit is contained in:
Anna Rose 2015-11-08 23:15:58 -05:00
parent f2d7f48d43
commit 9af6a589f8
2 changed files with 19 additions and 2 deletions

View File

@ -1,11 +1,20 @@
#include "Joystick.h" #include "Joystick.h"
#include <Arduino.h> #include <Arduino.h>
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) { Joystick::Joystick(bool debug) {
_debug = debug; _debug = debug;
_num_buttons = 0; _num_buttons = 0;
_num_axes = 0; _num_axes = 0;
_have_pulsed_button = false;
for (uint8_t i=0; i < JOYSTICK_NUM_AXES; i++) { for (uint8_t i=0; i < JOYSTICK_NUM_AXES; i++) {
_joyReport.axis[i] = 0; _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].type = type;
_buttons[_num_buttons].last_state = digitalRead(pin); _buttons[_num_buttons].last_state = digitalRead(pin);
_num_buttons++; _num_buttons++;
if (type == BUTTON_PULSED || type == BUTTON_PULSED_DOUBLE_ACTION) {
_have_pulsed_button = true;
}
} }
void Joystick::AddAxis(uint8_t pin) { void Joystick::AddAxis(uint8_t pin) {
@ -51,7 +64,7 @@ void Joystick::Update() {
} }
if (_joyReport != oldReport) { if (_joyReport != oldReport) {
Serial.write(_joyReport); Write();
} }
} }

View File

@ -25,6 +25,9 @@ typedef struct JoyReport {
uint8_t button[JOYSTICK_NUM_BYTES]; uint8_t button[JOYSTICK_NUM_BYTES];
} ; } ;
bool operator ==(JoyReport a, JoyReport b);
bool operator !=(JoyReport a, JoyReport b);
class Joystick { class Joystick {
public: public:
Joystick(bool debug=false); Joystick(bool debug=false);
@ -49,6 +52,7 @@ class Joystick {
uint8_t last_state; uint8_t last_state;
} _buttons[JOYSTICK_NUM_BUTTONS]; } _buttons[JOYSTICK_NUM_BUTTONS];
uint8_t _num_buttons; uint8_t _num_buttons;
bool _have_pulsed_button;
uint8_t _axes[JOYSTICK_NUM_AXES]; uint8_t _axes[JOYSTICK_NUM_AXES];
uint8_t _num_axes; uint8_t _num_axes;