Add new (stubbed) API that simplifies use of the joystick library.

This commit is contained in:
Anna Rose 2015-11-06 10:48:38 -05:00
parent 0cdaf634a7
commit cd0fe5829e
2 changed files with 34 additions and 7 deletions

View File

@ -19,6 +19,18 @@ void Joystick::Init() {
if (_debug) Serial.println("DEBUG: Joystick library initialized."); if (_debug) Serial.println("DEBUG: Joystick library initialized.");
} }
void Joystick::AddButton(uint8_t pin, ButtonType type) {
// stub
}
void Joystick::AddAxis(uint8_t pin) {
// stub
}
void Joystick::Update() {
// stub
}
void Joystick::SetAxis(uint8_t axis, int16_t value) { void Joystick::SetAxis(uint8_t axis, int16_t value) {
if (axis >= JOYSTICK_NUM_AXES) return; if (axis >= JOYSTICK_NUM_AXES) return;
_joyReport.axis[axis] = value; _joyReport.axis[axis] = value;

View File

@ -4,13 +4,22 @@
#include <Arduino.h> #include <Arduino.h>
// If you're using the arduino-big-joystick firmware, these numbers can't be // If you're using the arduino-big-joystick firmware, these numbers can't be
// changed. If you're writing your own Report Descriptor, tune these to match. // changed. If you're writing your own Report Descriptor, tune these to match by
// TODO: Pass these in to the constructor, with the same caveats. Shouldn't need // defining them *before* you include Joystick.h.
// to edit the header file to make something work in a library. :( #ifndef JOYSTICK_NUM_AXES
#define JOYSTICK_NUM_AXES 8 #define JOYSTICK_NUM_AXES 8
#endif
#ifndef JOYSTICK_NUM_BUTTONS
#define JOYSTICK_NUM_BUTTONS 40 #define JOYSTICK_NUM_BUTTONS 40
#endif
#define JOYSTICK_NUM_BYTES (JOYSTICK_NUM_BUTTONS+7)/8 #define JOYSTICK_NUM_BYTES (JOYSTICK_NUM_BUTTONS+7)/8
enum ButtonType {
BUTTON_MAINTAINED,
BUTTON_PULSED,
BUTTON_PULSED_DOUBLE_ACTION
};
typedef struct JoyReport { typedef struct JoyReport {
int16_t axis[JOYSTICK_NUM_AXES]; int16_t axis[JOYSTICK_NUM_AXES];
uint8_t button[JOYSTICK_NUM_BYTES]; uint8_t button[JOYSTICK_NUM_BYTES];
@ -20,18 +29,24 @@ class Joystick {
public: public:
Joystick(bool debug=false); Joystick(bool debug=false);
void Init(); void Init();
void Update();
void AddButton(uint8_t pin, ButtonType type);
void AddAxis(uint8_t pin);
// These functions are deprecated and may become private in a future
// version. Prefer the above API instead.
void SetAxis(uint8_t axis, int16_t value); void SetAxis(uint8_t axis, int16_t value);
void PressButton(uint8_t button); void PressButton(uint8_t button);
void ReleaseButton(uint8_t button); void ReleaseButton(uint8_t button);
void ReleaseAllButtons(); void ReleaseAllButtons();
// This actually sends the commands. You *must* call this for the
// joystick to do anything!
void Write(); void Write();
private: private:
struct {
} _buttons[JOYSTICK_NUM_BUTTONS];
uint8_t _num_buttons;
JoyReport _joyReport; JoyReport _joyReport;
bool _debug; bool _debug;
}; };