USB Joystick library, modified to work as a 6 DOF joystick.
Fork of USBJoystick by
Diff: USBJoystick.h
- Revision:
- 1:8b5f213b169f
- Parent:
- 0:e086541742c3
- Child:
- 2:1549541d3b4b
--- a/USBJoystick.h Thu Jan 05 14:22:02 2017 +0000 +++ b/USBJoystick.h Fri Jan 13 05:37:07 2017 +0000 @@ -44,7 +44,7 @@ JOY_B0 = 1, JOY_B1 = 2, JOY_B2 = 4, - JOY_B3 = 8, + JOY_B3 = 8, }; #if (HAT4 == 1) @@ -53,7 +53,7 @@ JOY_HAT_RIGHT = 1, JOY_HAT_DOWN = 2, JOY_HAT_LEFT = 3, - JOY_HAT_NEUTRAL = 4, + JOY_HAT_NEUTRAL = 4, }; #endif #if (HAT8 == 1) @@ -63,81 +63,22 @@ JOY_HAT_RIGHT = 2, JOY_HAT_RIGHT_DOWN = 3, JOY_HAT_DOWN = 4, - JOY_HAT_DOWN_LEFT = 5, - JOY_HAT_LEFT = 6, - JOY_HAT_LEFT_UP = 7, - JOY_HAT_NEUTRAL = 8, + JOY_HAT_DOWN_LEFT = 5, + JOY_HAT_LEFT = 6, + JOY_HAT_LEFT_UP = 7, + JOY_HAT_NEUTRAL = 8, }; #endif /* X, Y and T limits */ /* These values do not directly map to screen pixels */ /* Zero may be interpreted as meaning 'no movement' */ -#define JX_MIN_ABS (-127) /*!< The maximum value that we can move to the left on the x-axis */ -#define JY_MIN_ABS (-127) /*!< The maximum value that we can move up on the y-axis */ -#define JT_MIN_ABS (-127) /*!< The minimum value for the throttle */ -#define JX_MAX_ABS (127) /*!< The maximum value that we can move to the right on the x-axis */ -#define JY_MAX_ABS (127) /*!< The maximum value that we can move down on the y-axis */ -#define JT_MAX_ABS (127) /*!< The maximum value for the throttle */ - -/** - * - * USBJoystick example - * @code - * #include "mbed.h" - * #include "USBJoystick.h" - * - * USBJoystick joystick; - * - * int main(void) - * { - * while (1) - * { - * joystick.move(20, 0); - * wait(0.5); - * } - * } - * - * @endcode - * - * - * @code - * #include "mbed.h" - * #include "USBJoystick.h" - * - * USBJoystick joystick; - * - * int main(void) { - * uint16_t i = 0; - * int16_t throttle = 0; - * int16_t rudder = 0; - * int16_t x = 0; - * int16_t y = 0; - * int32_t radius = 120; - * int32_t angle = 0; - * uint32_t buttons = 0; - * uint8_t hat = 0; - * - * while (1) { - * // Basic Joystick - * throttle = (i >> 8) & 0xFF; // value -127 .. 128 - * rudder = (i >> 8) & 0xFF; // value -127 .. 128 - * buttons = (i >> 8) & 0x0F; // value 0 .. 15, one bit per button - * hat = (i >> 8) & 0x07; // value 0 .. 7 or 8 for neutral - * i++; - * - * x = cos((double)angle*3.14/180.0)*radius; // value -127 .. 128 - * y = sin((double)angle*3.14/180.0)*radius; // value -127 .. 128 - * angle += 3; - * - * joystick.update(throttle, rudder, x, y, buttons, hat); - * - * wait(0.001); - * } - * } - * @endcode - */ - +#define JX_MIN_ABS (-32768) /*!< The maximum value that we can move to the left on the x-axis */ +#define JY_MIN_ABS (-32768) /*!< The maximum value that we can move up on the y-axis */ +#define JT_MIN_ABS (-32768) /*!< The minimum value for the throttle */ +#define JX_MAX_ABS (32767) /*!< The maximum value that we can move to the right on the x-axis */ +#define JY_MAX_ABS (32767) /*!< The maximum value that we can move down on the y-axis */ +#define JT_MAX_ABS (32767) /*!< The maximum value for the throttle */ class USBJoystick: public USBHID { public: @@ -226,10 +167,10 @@ virtual uint8_t * reportDesc(); private: - int8_t _t; - int8_t _r; - int8_t _x; - int8_t _y; + int16_t _t; + int16_t _r; + int16_t _x; + int16_t _y; uint32_t _buttons; uint8_t _hat;