Initial for Condor Simulator
Dependents: USBJoystick_2 USBJoystick_NEW
Fork of USBJoystick by
Revision 2:265e03bf82af, committed 2018-09-15
- Comitter:
- Cirrus01
- Date:
- Sat Sep 15 07:46:30 2018 +0000
- Parent:
- 1:92574cf6e9af
- Child:
- 3:550cca870c98
- Commit message:
- Hat Switch Bug fixed; - HID Descriptor fixed; - Hat Switch values transleted
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 Sun Jul 22 10:34:23 2018 +0000
+++ b/USBJoystick.cpp Sat Sep 15 07:46:30 2018 +0000
@@ -44,45 +44,64 @@
bool USBJoystick::update()
{
+ uint8_t pos = 0;
HID_REPORT report;
// Fill the report according to the Joystick Descriptor
- report.data[0] = _t & 0xff;
- report.data[1] = _r & 0xff;
- report.data[2] = _d & 0xff;
- report.data[3] = _w & 0xff;
- report.data[4] = _x & 0xff;
- report.data[5] = _y & 0xff;
+ report.data[pos] = (_t >> 0) & 0xff;
+#if (SWORD == 1)
+ report.data[pos++] = (_t >> 8) & 0xff;
+#endif
+ report.data[pos++] = _r & 0xff;
+#if (SWORD == 1)
+ report.data[pos++] = (_r >> 8) & 0xff;
+#endif
+ report.data[pos++] = _d & 0xff;
+#if (SWORD == 1)
+ report.data[pos++] = (_d >> 8) & 0xff;
+#endif
+ report.data[pos++] = _w & 0xff;
+#if (SWORD == 1)
+ report.data[pos++] = (_w >> 8) & 0xff;
+#endif
+ report.data[pos++] = _x & 0xff;
+#if (SWORD == 1)
+ report.data[pos++] = (_x >> 8) & 0xff;
+#endif
+ report.data[pos++] = _y & 0xff;
+#if (SWORD == 1)
+ report.data[pos++] = (_y >> 8) & 0xff;
+#endif
#if (HAT4 == 1)
//Use 4 bit padding for hat4 or hat8
- report.data[6] = (_hat & 0x0f) ;
+ report.data[pos++] = (_hat & 0x0f) ;
#endif
#if (HAT8 == 1)
//Use 4 bit padding for hat4 or hat8
- report.data[6] = (_hat & 0xff) ;
+ report.data[pos++] = (_hat & 0xff) ;
#endif
#if (BUTTONS4 == 1)
//Use 4 bit padding for buttons
- report.data[7] = (_buttons & 0x0f) ;
- report.length = 8;
+ report.data[pos++] = (_buttons & 0x0f) ;
+ report.length = pos++;
#endif
#if (BUTTONS8 == 1)
//Use 8 bits for buttons
- report.data[7] = (_buttons & 0xff) ;
- report.length = 8;
+ report.data[pos++] = (_buttons & 0xff) ;
+ report.length = pos++;
#endif
#if (BUTTONS32 == 1)
//No bit padding for 32 buttons
- report.data[7] = (_buttons >> 0) & 0xff;
- report.data[8] = (_buttons >> 8) & 0xff;
- report.data[9] = (_buttons >> 16) & 0xff;
- report.data[10] = (_buttons >> 24) & 0xff;
- report.length = 11;
+ report.data[pos++] = (_buttons >> 0) & 0xff;
+ report.data[pos++] = (_buttons >> 8) & 0xff;
+ report.data[pos++] = (_buttons >> 16) & 0xff;
+ report.data[pos++] = (_buttons >> 24) & 0xff;
+ report.length = pos++;
#endif
return send(&report);
@@ -162,63 +181,78 @@
REPORT_COUNT(1), 0x02,
INPUT(1), 0x02, // Data, Variable, Absolute
USAGE(1), 0xB6, // Dive Breaks
- USAGE(1), 0xC3, // Wing Flaps
+ USAGE(1), 0xC3, // Wing Flaps
+// 8 bit values
+#if (SBYTE == 1)
LOGICAL_MINIMUM(1), 0x81, // -127
LOGICAL_MAXIMUM(1), 0x7f, // 127
REPORT_SIZE(1), 0x08,
REPORT_COUNT(1), 0x02,
+ INPUT(1), 0x02, // Data, Variable, Absolute
+#endif
+// 16 bit values
+#if (SWORD ==1)
+ LOGICAL_MINIMUM(2), 0x80, 0x01 // -32767
+ LOGICAL_MAXIMUM(2), 0x7f, 0xff, // 32767
+ REPORT_SIZE(1), 0x10,
+ REPORT_COUNT(1), 0x04,
INPUT(1), 0x02, // Data, Variable, Absolute
+#endif
USAGE_PAGE(1), 0x01, // Generic Desktop
USAGE(1), 0x01, // Usage (Pointer)
COLLECTION(1), 0x00, // Physical
USAGE(1), 0x30, // X
USAGE(1), 0x31, // Y
// 8 bit values
+#if (SBYTE == 1)
LOGICAL_MINIMUM(1), 0x81, // -127
LOGICAL_MAXIMUM(1), 0x7f, // 127
REPORT_SIZE(1), 0x08,
REPORT_COUNT(1), 0x02,
INPUT(1), 0x02, // Data, Variable, Absolute
+#endif
// 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
+#if (SWORD ==1)
+ LOGICAL_MINIMUM(2), 0x80, 0x01 // -32767
+ LOGICAL_MAXIMUM(2), 0x7f, 0xff, // 32767
+ REPORT_SIZE(1), 0x10,
+ REPORT_COUNT(1), 0x04,
+ INPUT(1), 0x02, // Data, Variable, Absolute
+#endif
END_COLLECTION(0),
-#if (HAT4 == 1)
+#if (HAT4 == 1 && HAT4_8 == 0)
// 4 Position Hat Switch
USAGE(1), 0x39, // Usage (Hat switch)
LOGICAL_MINIMUM(1), 0x00, // 0
LOGICAL_MAXIMUM(1), 0x03, // 3
PHYSICAL_MINIMUM(1), 0x00, // Physical_Minimum (0)
PHYSICAL_MAXIMUM(2), 0x0E, 0x01, // Physical_Maximum (270)
- UNIT(1), 0x14, // Unit (Eng Rot:Angular Pos)
+ UNIT_EXPONENT(1), 0x00, // Unit Exponent (0)
+ UNIT(1), 0x14, // Unit (Degrees)
REPORT_SIZE(1), 0x04,
REPORT_COUNT(1), 0x01,
- INPUT(1), 0x02, // Data, Variable, Absolute
+ INPUT(1), 0x42, // Data, Variable, Absolute, Null State
+// Padding 4 bits
+ REPORT_SIZE(1), 0x01,
+ REPORT_COUNT(1), 0x04,
+ INPUT(1), 0x01, // Constant
#endif
-#if (HAT8 == 1)
+#if (HAT8 == 1) || (HAT4 == 1 && HAT4_8 == 1)
// 8 Position Hat Switch
USAGE(1), 0x39, // Usage (Hat switch)
LOGICAL_MINIMUM(1), 0x00, // 0
LOGICAL_MAXIMUM(1), 0x07, // 7
PHYSICAL_MINIMUM(1), 0x00, // Physical_Minimum (0)
PHYSICAL_MAXIMUM(2), 0x3B, 0x01, // Physical_Maximum (315)
- UNIT(1), 0x14, // Unit (Eng Rot:Angular Pos)
- REPORT_SIZE(1), 0x04,
+ UNIT_EXPONENT(1), 0x00, // Unit Exponent (0)
+ UNIT(1), 0x14, // Unit (Degrees)
+ REPORT_SIZE(1), 0x08,
REPORT_COUNT(1), 0x01,
- INPUT(1), 0x02, // Data, Variable, Absolute
+ INPUT(1), 0x42, // Data, Variable, Absolute, Null State
#endif
-// Padding 4 bits
- REPORT_SIZE(1), 0x01,
- REPORT_COUNT(1), 0x04,
- INPUT(1), 0x01, // Constant
-
-
#if (BUTTONS4 == 1)
// 4 Buttons
USAGE_PAGE(1), 0x09, // Buttons
@@ -251,7 +285,6 @@
UNIT(1), 0x00, // Unit (None)
INPUT(1), 0x02, // Data, Variable, Absolute
#endif
-
#if (BUTTONS32 == 1)
// 32 Buttons
USAGE_PAGE(1), 0x09, // Buttons
--- a/USBJoystick.h Sun Jul 22 10:34:23 2018 +0000
+++ b/USBJoystick.h Sat Sep 15 07:46:30 2018 +0000
@@ -30,10 +30,15 @@
#define REPORT_ID_JOYSTICK 4
-//Configure Joystick
-#define HAT4 1
+//Configure Joystick Slider Resolution
+#define SBYTE 1 // 1 Byte, 8 Bit Resolution
+#define SWORD 0 // 2 Byte, 16 Bit Resolution
+//Configure Joystick Hat Buttons
+#define HAT4 1 // 4 Hat Buttons; 4 Positions if HAT4_8 = 0
+#define HAT4_8 0 // 4 Hat Buttons giving 8 Positions if 1; DO NOT USE WITH HAT8!
#define HAT8 0
+//Configure Joystick Buttons
#define BUTTONS4 0
#define BUTTONS8 0
#define BUTTONS32 1
@@ -47,7 +52,7 @@
JOY_B3 = 8,
};
-#if (HAT4 == 1)
+#if (HAT4 == 1 && HAT4_8 == 0)
enum JOY_HAT {
JOY_HAT_UP = 0,
JOY_HAT_RIGHT = 1,
@@ -56,16 +61,16 @@
JOY_HAT_NEUTRAL = 4,
};
#endif
-#if (HAT8 == 1)
+#if (HAT8 == 1 || (HAT4 == 1 && HAT4_8 == 1))
enum JOY_HAT {
JOY_HAT_UP = 0,
JOY_HAT_UP_RIGHT = 1,
JOY_HAT_RIGHT = 2,
- JOY_HAT_RIGHT_DOWN = 3,
+ JOY_HAT_DOWN_RIGHT = 3,
JOY_HAT_DOWN = 4,
JOY_HAT_DOWN_LEFT = 5,
JOY_HAT_LEFT = 6,
- JOY_HAT_LEFT_UP = 7,
+ JOY_HAT_UP_LEFT = 7,
JOY_HAT_NEUTRAL = 8,
};
#endif
@@ -147,7 +152,7 @@
* Constructor
*
* @param vendor_id Your vendor_id (default: 0x1234)
- * @param product_id Your product_id (default: 0x0002)
+ * @param product_id Your product_id (default: 0x0604)
* @param product_release Your product_release (default: 0x0001)
*/
// USBJoystick(uint16_t vendor_id = 0x1234, uint16_t product_id = 0x0100, uint16_t product_release = 0x0001, int waitForConnect = true): // 4 buttons, no padding on buttons
@@ -244,12 +249,12 @@
virtual uint8_t * reportDesc();
private:
- int8_t _t;
- int8_t _r;
- int8_t _d;
- int8_t _w;
- int8_t _x;
- int8_t _y;
+ int16_t _t;
+ int16_t _r;
+ int16_t _d;
+ int16_t _w;
+ int16_t _x;
+ int16_t _y;
uint32_t _buttons;
uint8_t _hat;
