HID Joystick - For use with X-Plane or other programs that can read HID JoySticks

Dependencies:   USBDevice mbed-rtos mbed

Fork of JoyStick by Ries Twisk

This is a simple Joystick HID that I use for xplane and a home build yoke + paddels, see this forum with the look and feel of it : http://forums.x-plane.org/index.php?showtopic=70041

The analog input are filtered with a LowPass IIR filter and the digital input's will be derived from the analog input and de-bounced.

The analog values are read at a 1Khz interval and to ensure we don't push the USB stack to much at a maximum rate of 20 updates/sec HID data is send over USB only if any values where changed. The JoyStick will send 16Bit analog values as opposite of 8 bit values that are normally used to increase accuracy of the whole system. This is well noticeable within x-plane!

The JoyStick uses the JoyStick copied from Wim Huiskamp and modified to suite my needs and the MBED RTOS libraries for reading analog inputs, sending debug data over USB and sending HID data, 3 threads in total.

Revision:
4:2cc58c173de8
Parent:
2:ae7a31a3c618
--- a/USBJoystick.cpp	Tue Feb 10 13:48:20 2015 +0000
+++ b/USBJoystick.cpp	Thu Mar 10 14:05:02 2016 +0000
@@ -20,27 +20,14 @@
 #include "stdint.h"
 #include "USBJoystick.h"
 
-bool USBJoystick::update(int16_t t, int16_t r, int16_t x, int16_t y, uint8_t button) {
-             HID_REPORT report;
+bool USBJoystick::update(int16_t t, int16_t r, int16_t x, int16_t y, uint32_t button) {
    _t = t;
    _r = r;   
    _x = x;
    _y = y;
    _button = button;     
 
-   // Fill the report according to the Joystick Descriptor
-   report.data[0] = _t & 0xff;
-   report.data[1] = (_t >> 8) & 0xff;
-   report.data[2] = _r & 0xff;
-   report.data[3] = (_r >> 8) & 0xff;
-   report.data[4] = _x & 0xff;
-   report.data[5] = (_x >> 8) & 0xff;
-   report.data[6] = _y & 0xff;
-   report.data[7] = (_y >> 8) & 0xff;
-   report.data[8] = (_button & 0xff);                                      
-   report.length = 9;
-   
-   return send(&report);
+   return USBJoystick::update();
 }
  
 bool USBJoystick::update() {
@@ -55,8 +42,11 @@
    report.data[5] = (_x >> 8) & 0xff;
    report.data[6] = _y & 0xff;
    report.data[7] = (_y >> 8) & 0xff;
-   report.data[8] = (_button & 0xff);                                      
-   report.length = 9;
+   report.data[8] =  (_button >> 24) & 0xff;
+   report.data[9] =  (_button >> 16) & 0xff;
+   report.data[10] = (_button >>  8) & 0xff;
+   report.data[11] = _button & 0xff;
+   report.length = 12;
 
    return send(&report);
 }
@@ -77,7 +67,7 @@
      return update();
 }
 
-bool USBJoystick::button(uint8_t button) {
+bool USBJoystick::button(uint32_t button) {
      _button = button;
      return update();
 }
@@ -89,7 +79,7 @@
    _r = 0;    
    _x = 0;                       
    _y = 0;     
-   _button = 0x00;
+   _button = 0x00000000;
 }
 
 
@@ -154,11 +144,11 @@
 // Buttons
                USAGE_PAGE(1), 0x09,            // Buttons
                USAGE_MINIMUM(1), 0x01,         // 1
-               USAGE_MAXIMUM(1), 0x08,         // 4
+               USAGE_MAXIMUM(1), 0x20,         // 32
                LOGICAL_MINIMUM(1), 0x00,       // 0
                LOGICAL_MAXIMUM(1), 0x01,       // 1
                REPORT_SIZE(1), 0x01,
-               REPORT_COUNT(1), 0x08,
+               REPORT_COUNT(1), 0x20,          // 32
                UNIT_EXPONENT(1), 0x00,         // Unit_Exponent (0)
                UNIT(1), 0x00,                  // Unit (None)                                           
                INPUT(1), 0x02,                 // Data, Variable, Absolute