USBJoystick updated for 32 buttons and added wait-for-connect.

Dependents:   joy2

Files at this revision

API Documentation at this revision

Comitter:
gagarinlg
Date:
Sun Aug 01 17:20:34 2021 +0000
Parent:
2:de0ca539fa79
Commit message:
working

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 Aug 01 11:49:38 2021 +0000
+++ b/USBJoystick.cpp	Sun Aug 01 17:20:34 2021 +0000
@@ -28,28 +28,35 @@
 #include "USBJoystick.h"
 #include "../buffer_builder.hpp"
 
-bool USBJoystick::update(int16_t t, int16_t r, int16_t x, int16_t y, uint32_t buttons, uint8_t hat) {
+bool USBJoystick::update(int16_t t, int16_t r, int16_t x, int16_t y, uint16_t z, uint16_t rx, uint16_t ry, uint16_t rz, uint32_t buttons, uint8_t hat) {
 
    _t = t;
    _r = r;   
    _x = x;
    _y = y;
+   _z = z;
+   _rx = rx;
+   _ry = ry;
+   _rz = rz;
    _buttons = buttons;     
    _hat = hat;
 
    return update();
 }
- 
+ HID_REPORT report;
 bool USBJoystick::update() {
-   HID_REPORT report;
+   
 
    uint8_t* data = &report.data[0];
    buffer_builder::put_u16le(data, _t);
    buffer_builder::put_u16le(data, _r);
    buffer_builder::put_u16le(data, _x);
    buffer_builder::put_u16le(data, _y);
-   buffer_builder::put_u16le(data, _t);
- //  buffer_builder::put_u16le(data, 0x5678);
+   buffer_builder::put_u32le(data, 0x00);
+   buffer_builder::put_u16le(data, _z);
+   buffer_builder::put_u16le(data, _rx);
+   buffer_builder::put_u16le(data, _ry);
+   buffer_builder::put_u16le(data, _rz);
 #if (BUTTONS4 == 1 && 0)               
 //Hat and 4 Buttons
 //   report.data[4] = ((_buttons & 0x0f) << 4) | (_hat & 0x0f) ;                                      
@@ -133,7 +140,6 @@
              USAGE_PAGE(1), 0x01,           // Generic Desktop           
              USAGE(1), 0x04,                // Usage (Joystick)
              COLLECTION(1), 0x01,           // Application
-#if 0
                USAGE_PAGE(1), 0x02,            // Simulation Controls
                USAGE(1), 0xBB,                 // Throttle             
                USAGE(1), 0xBA,                 // Rudder
@@ -148,14 +154,10 @@
                REPORT_SIZE(1), 0x10,
                REPORT_COUNT(1), 0x02,
                INPUT(1), 0x02,                 // Data, Variable, Absolute
-#endif
 #if 1               
                USAGE_PAGE(1), 0x01,            // Generic Desktop
                  USAGE(1), 0x30,                 // X
                  USAGE(1), 0x31,                 // Y
-                 USAGE(1), 0x32,                 // Z
-                 USAGE(1), 0x33,                 // RX
-                 USAGE(1), 0x34,                 // RY
 //  8 bit values
  //                LOGICAL_MINIMUM(1), 0x81,       // -127
  //                LOGICAL_MAXIMUM(1), 0x7f,       // 127
@@ -166,9 +168,23 @@
                  LOGICAL_MINIMUM(2), 0x01, 0x80,       // -32767
                  LOGICAL_MAXIMUM(2), 0xff, 0x7f, // 32767
                  REPORT_SIZE(1), 0x10,
-                 REPORT_COUNT(1), 0x05,
+                 REPORT_COUNT(1), 0x02,
                  INPUT(1), 0x02,                 // Data, Variable, Absolute                
+               REPORT_SIZE(1), 0x20,
+               REPORT_COUNT(1), 0x01,
+               INPUT(1), 0x01,                 // Constant
 
+              USAGE_PAGE(1), 0x01,            // Generic Desktop
+                 USAGE(1), 0x32,                 // Z
+                 USAGE(1), 0x33,                 // RX
+                 USAGE(1), 0x34,                 // RY
+                 USAGE(1), 0x35,                 // Rz
+                 LOGICAL_MINIMUM(2), 0x01, 0x80,       // -32767
+                 LOGICAL_MAXIMUM(2), 0xff, 0x7f, // 32767
+                 REPORT_SIZE(1), 0x10,
+                 REPORT_COUNT(1), 0x04,
+                 INPUT(1), 0x02,                 // Data, Variable, Absolute                
+ 
 #endif            
 #if (HAT4 == 1 && 0)
 // 4 Position Hat Switch
--- a/USBJoystick.h	Sun Aug 01 11:49:38 2021 +0000
+++ b/USBJoystick.h	Sun Aug 01 17:20:34 2021 +0000
@@ -168,7 +168,7 @@
        * @param hat hat state 0 (up), 1 (right, 2 (down), 3 (left) or 4 (neutral)
        * @returns true if there is no error, false otherwise
        */
-     bool update(int16_t t, int16_t r, int16_t x, int16_t y, uint32_t buttons, uint8_t hat);
+        bool update(int16_t t, int16_t r, int16_t x, int16_t y, uint16_t z, uint16_t rx, uint16_t ry, uint16_t rz, uint32_t buttons, uint8_t hat);
 
      /**
        * Write state of the joystick
@@ -230,6 +230,11 @@
      int16_t _r;              
      int16_t _x;                       
      int16_t _y;     
+     int16_t _z;     
+     int16_t _rx;     
+     int16_t _ry;
+     int16_t _rz;     
+     
      uint32_t _buttons;
      uint8_t _hat;