From cd0fe5829ee63be8a1dc8f254574ce249cb8466c Mon Sep 17 00:00:00 2001 From: Anna Wiggins Date: Fri, 6 Nov 2015 10:48:38 -0500 Subject: [PATCH] Add new (stubbed) API that simplifies use of the joystick library. --- Joystick.cpp | 12 ++++++++++++ Joystick.h | 29 ++++++++++++++++++++++------- 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/Joystick.cpp b/Joystick.cpp index ed5fa27..e53b715 100644 --- a/Joystick.cpp +++ b/Joystick.cpp @@ -19,6 +19,18 @@ void Joystick::Init() { 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) { if (axis >= JOYSTICK_NUM_AXES) return; _joyReport.axis[axis] = value; diff --git a/Joystick.h b/Joystick.h index e6b0dd1..85d1c9b 100644 --- a/Joystick.h +++ b/Joystick.h @@ -4,13 +4,22 @@ #include // 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. -// TODO: Pass these in to the constructor, with the same caveats. Shouldn't need -// to edit the header file to make something work in a library. :( +// changed. If you're writing your own Report Descriptor, tune these to match by +// defining them *before* you include Joystick.h. +#ifndef JOYSTICK_NUM_AXES #define JOYSTICK_NUM_AXES 8 +#endif +#ifndef JOYSTICK_NUM_BUTTONS #define JOYSTICK_NUM_BUTTONS 40 +#endif #define JOYSTICK_NUM_BYTES (JOYSTICK_NUM_BUTTONS+7)/8 +enum ButtonType { + BUTTON_MAINTAINED, + BUTTON_PULSED, + BUTTON_PULSED_DOUBLE_ACTION +}; + typedef struct JoyReport { int16_t axis[JOYSTICK_NUM_AXES]; uint8_t button[JOYSTICK_NUM_BYTES]; @@ -20,18 +29,24 @@ class Joystick { public: Joystick(bool debug=false); 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 PressButton(uint8_t button); void ReleaseButton(uint8_t button); void ReleaseAllButtons(); - - // This actually sends the commands. You *must* call this for the - // joystick to do anything! void Write(); private: + struct { + + } _buttons[JOYSTICK_NUM_BUTTONS]; + uint8_t _num_buttons; JoyReport _joyReport; bool _debug; };