USB Joystick library, modified to work as a 6 DOF joystick.
Fork of USBJoystick by
Revision 1:8b5f213b169f, committed 2017-01-13
- Comitter:
- smartsystemdesign
- Date:
- Fri Jan 13 05:37:07 2017 +0000
- Parent:
- 0:e086541742c3
- Child:
- 2:1549541d3b4b
- Commit message:
- Switching from 8 bit to 16 bit analog controls. Work in progress.
Changed in this revision
| USBJoystick.cpp | Show annotated file Show diff for this revision Revisions of this file |
| USBJoystick.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/USBJoystick.cpp Thu Jan 05 14:22:02 2017 +0000
+++ b/USBJoystick.cpp Fri Jan 13 05:37:07 2017 +0000
@@ -43,10 +43,10 @@
HID_REPORT report;
// Fill the report according to the Joystick Descriptor
- report.data[0] = _t & 0xff;
- report.data[1] = _r & 0xff;
- report.data[2] = _x & 0xff;
- report.data[3] = _y & 0xff;
+ report.data[0] = _t & 0xffff;
+ report.data[1] = _r & 0xffff;
+ report.data[2] = _x & 0xffff;
+ report.data[3] = _y & 0xffff;
#if (BUTTONS4 == 1)
@@ -122,8 +122,8 @@
void USBJoystick::_init() {
- _t = -127;
- _r = -127;
+ _t = -32768;
+ _r = -32768;
_x = 0;
_y = 0;
_buttons = 0x00000000;
@@ -151,18 +151,19 @@
COLLECTION(1), 0x00, // Physical
USAGE(1), 0x30, // X
USAGE(1), 0x31, // Y
-// 8 bit values
- LOGICAL_MINIMUM(1), 0x81, // -127
- LOGICAL_MAXIMUM(1), 0x7f, // 127
- REPORT_SIZE(1), 0x08,
+//// 8 bit values
+// LOGICAL_MINIMUM(1), 0x81, // -127
+// LOGICAL_MAXIMUM(1), 0x7f, // 127
+// REPORT_SIZE(1), 0x08,
+// REPORT_COUNT(1), 0x02,
+// INPUT(1), 0x02, // Data, Variable, Absolute
+
+// 16 bit values
+ LOGICAL_MINIMUM(1), 0x00, // 0
+ LOGICAL_MAXIMUM(2), 0xff, 0x7f, // 32767
+ REPORT_SIZE(1), 0x10,
REPORT_COUNT(1), 0x02,
- INPUT(1), 0x02, // Data, Variable, Absolute
-// 16 bit values
-// LOGICAL_MINIMUM(1), 0x00, // 0
-// LOGICAL_MAXIMUM(2), 0xff, 0x7f, // 32767
-// REPORT_SIZE(1), 0x10,
-// REPORT_COUNT(1), 0x02,
-// INPUT(1), 0x02, // Data, Variable, Absolute
+ INPUT(1), 0x02, // Data, Variable, Absolute
END_COLLECTION(0),
--- 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;
