22
22
23
23
#if defined(_USING_DYNAMIC_HID)
24
24
25
- // #define JOYSTICK_STATE_SIZE 13
26
- // #define JOYSTICK_STATE_SIZE 4
27
-
28
25
#define JOYSTICK_REPORT_ID_INDEX 7
29
26
#define JOYSTICK_AXIS_MINIMUM -32767
30
27
#define JOYSTICK_AXIS_MAXIMUM 32767
31
28
29
+ /*
32
30
static const uint8_t _hidReportDescriptor[] PROGMEM = {
33
31
34
32
// Joystick
@@ -101,6 +99,7 @@ static const uint8_t _hidReportDescriptor[] PROGMEM = {
101
99
102
100
0xc0 // END_COLLECTION
103
101
};
102
+ */
104
103
105
104
Joystick_::Joystick_ (uint8_t hidReportId,
106
105
uint8_t buttonCount,
@@ -124,13 +123,23 @@ Joystick_::Joystick_(uint8_t hidReportId,
124
123
_includeRzAxis = includeRzAxis;
125
124
126
125
// Build Joystick HID Report Description
126
+
127
+ // Button Calculations
127
128
uint8_t buttonsInLastByte = _buttonCount % 8 ;
128
129
uint8_t buttonPaddingBits = 0 ;
129
130
if (buttonsInLastByte > 0 )
130
131
{
131
132
buttonPaddingBits = 8 - buttonsInLastByte;
132
133
}
133
-
134
+
135
+ // Axis Calculations
136
+ uint8_t axisCount = (_includeXAxis == true )
137
+ + (_includeYAxis == true )
138
+ + (_includeZAxis == true )
139
+ + (_includeRxAxis == true )
140
+ + (_includeRyAxis == true )
141
+ + (_includeRzAxis == true );
142
+
134
143
// TODO: Figure out what the max for this could be and set it here...
135
144
uint8_t *customHidReportDescriptor = new uint8_t [100 ];
136
145
int hidReportDescriptorSize = 0 ;
@@ -211,66 +220,82 @@ Joystick_::Joystick_(uint8_t hidReportId,
211
220
212
221
} // Buttons
213
222
214
- // USAGE_PAGE (Generic Desktop)
215
- customHidReportDescriptor[hidReportDescriptorSize++] = 0x05 ;
216
- customHidReportDescriptor[hidReportDescriptorSize++] = 0x01 ;
217
-
218
- // USAGE (Pointer)
219
- customHidReportDescriptor[hidReportDescriptorSize++] = 0x09 ;
220
- customHidReportDescriptor[hidReportDescriptorSize++] = 0x01 ;
221
-
222
- // LOGICAL_MINIMUM (-32767)
223
- customHidReportDescriptor[hidReportDescriptorSize++] = 0x16 ;
224
- customHidReportDescriptor[hidReportDescriptorSize++] = 0x01 ;
225
- customHidReportDescriptor[hidReportDescriptorSize++] = 0x80 ;
226
-
227
- // LOGICAL_MAXIMUM (+32767)
228
- customHidReportDescriptor[hidReportDescriptorSize++] = 0x26 ;
229
- customHidReportDescriptor[hidReportDescriptorSize++] = 0xFF ;
230
- customHidReportDescriptor[hidReportDescriptorSize++] = 0x7F ;
231
-
232
- // REPORT_SIZE (16)
233
- customHidReportDescriptor[hidReportDescriptorSize++] = 0x75 ;
234
- customHidReportDescriptor[hidReportDescriptorSize++] = 0x10 ;
235
-
236
- // REPORT_COUNT (6)
237
- customHidReportDescriptor[hidReportDescriptorSize++] = 0x95 ;
238
- customHidReportDescriptor[hidReportDescriptorSize++] = 0x06 ;
239
-
240
- // COLLECTION (Physical)
241
- customHidReportDescriptor[hidReportDescriptorSize++] = 0xA1 ;
242
- customHidReportDescriptor[hidReportDescriptorSize++] = 0x00 ;
223
+ if (axisCount > 0 ) {
224
+
225
+ // USAGE_PAGE (Generic Desktop)
226
+ customHidReportDescriptor[hidReportDescriptorSize++] = 0x05 ;
227
+ customHidReportDescriptor[hidReportDescriptorSize++] = 0x01 ;
243
228
244
- // USAGE (X )
245
- customHidReportDescriptor[hidReportDescriptorSize++] = 0x09 ;
246
- customHidReportDescriptor[hidReportDescriptorSize++] = 0x30 ;
229
+ // USAGE (Pointer )
230
+ customHidReportDescriptor[hidReportDescriptorSize++] = 0x09 ;
231
+ customHidReportDescriptor[hidReportDescriptorSize++] = 0x01 ;
247
232
248
- // USAGE (Y)
249
- customHidReportDescriptor[hidReportDescriptorSize++] = 0x09 ;
250
- customHidReportDescriptor[hidReportDescriptorSize++] = 0x31 ;
233
+ // LOGICAL_MINIMUM (-32767)
234
+ customHidReportDescriptor[hidReportDescriptorSize++] = 0x16 ;
235
+ customHidReportDescriptor[hidReportDescriptorSize++] = 0x01 ;
236
+ customHidReportDescriptor[hidReportDescriptorSize++] = 0x80 ;
251
237
252
- // USAGE (Z)
253
- customHidReportDescriptor[hidReportDescriptorSize++] = 0x09 ;
254
- customHidReportDescriptor[hidReportDescriptorSize++] = 0x32 ;
238
+ // LOGICAL_MAXIMUM (+32767)
239
+ customHidReportDescriptor[hidReportDescriptorSize++] = 0x26 ;
240
+ customHidReportDescriptor[hidReportDescriptorSize++] = 0xFF ;
241
+ customHidReportDescriptor[hidReportDescriptorSize++] = 0x7F ;
255
242
256
- // USAGE (Rx )
257
- customHidReportDescriptor[hidReportDescriptorSize++] = 0x09 ;
258
- customHidReportDescriptor[hidReportDescriptorSize++] = 0x33 ;
243
+ // REPORT_SIZE (16 )
244
+ customHidReportDescriptor[hidReportDescriptorSize++] = 0x75 ;
245
+ customHidReportDescriptor[hidReportDescriptorSize++] = 0x10 ;
259
246
260
- // USAGE (Ry)
261
- customHidReportDescriptor[hidReportDescriptorSize++] = 0x09 ;
262
- customHidReportDescriptor[hidReportDescriptorSize++] = 0x34 ;
247
+ // REPORT_COUNT (axisCount)
248
+ customHidReportDescriptor[hidReportDescriptorSize++] = 0x95 ;
249
+ customHidReportDescriptor[hidReportDescriptorSize++] = axisCount;
250
+
251
+ // COLLECTION (Physical)
252
+ customHidReportDescriptor[hidReportDescriptorSize++] = 0xA1 ;
253
+ customHidReportDescriptor[hidReportDescriptorSize++] = 0x00 ;
263
254
264
- // USAGE (Rz)
265
- customHidReportDescriptor[hidReportDescriptorSize++] = 0x09 ;
266
- customHidReportDescriptor[hidReportDescriptorSize++] = 0x35 ;
255
+ if (_includeXAxis == true ) {
256
+ // USAGE (X)
257
+ customHidReportDescriptor[hidReportDescriptorSize++] = 0x09 ;
258
+ customHidReportDescriptor[hidReportDescriptorSize++] = 0x30 ;
259
+ }
267
260
268
- // INPUT (Data,Var,Abs)
269
- customHidReportDescriptor[hidReportDescriptorSize++] = 0x81 ;
270
- customHidReportDescriptor[hidReportDescriptorSize++] = 0x02 ;
271
-
272
- // END_COLLECTION (Physical)
273
- customHidReportDescriptor[hidReportDescriptorSize++] = 0xc0 ;
261
+ if (_includeYAxis == true ) {
262
+ // USAGE (Y)
263
+ customHidReportDescriptor[hidReportDescriptorSize++] = 0x09 ;
264
+ customHidReportDescriptor[hidReportDescriptorSize++] = 0x31 ;
265
+ }
266
+
267
+ if (_includeZAxis == true ) {
268
+ // USAGE (Z)
269
+ customHidReportDescriptor[hidReportDescriptorSize++] = 0x09 ;
270
+ customHidReportDescriptor[hidReportDescriptorSize++] = 0x32 ;
271
+ }
272
+
273
+ if (_includeRxAxis == true ) {
274
+ // USAGE (Rx)
275
+ customHidReportDescriptor[hidReportDescriptorSize++] = 0x09 ;
276
+ customHidReportDescriptor[hidReportDescriptorSize++] = 0x33 ;
277
+ }
278
+
279
+ if (_includeRyAxis == true ) {
280
+ // USAGE (Ry)
281
+ customHidReportDescriptor[hidReportDescriptorSize++] = 0x09 ;
282
+ customHidReportDescriptor[hidReportDescriptorSize++] = 0x34 ;
283
+ }
284
+
285
+ if (_includeRzAxis == true ) {
286
+ // USAGE (Rz)
287
+ customHidReportDescriptor[hidReportDescriptorSize++] = 0x09 ;
288
+ customHidReportDescriptor[hidReportDescriptorSize++] = 0x35 ;
289
+ }
290
+
291
+ // INPUT (Data,Var,Abs)
292
+ customHidReportDescriptor[hidReportDescriptorSize++] = 0x81 ;
293
+ customHidReportDescriptor[hidReportDescriptorSize++] = 0x02 ;
294
+
295
+ // END_COLLECTION (Physical)
296
+ customHidReportDescriptor[hidReportDescriptorSize++] = 0xc0 ;
297
+
298
+ } // X, Y, Z, Rx, Ry, and Rz Axis
274
299
275
300
// END_COLLECTION
276
301
customHidReportDescriptor[hidReportDescriptorSize++] = 0xc0 ;
@@ -291,7 +316,10 @@ Joystick_::Joystick_(uint8_t hidReportId,
291
316
292
317
// Calculate HID Report Size
293
318
_hidReportSize = _buttonValuesArraySize;
294
- _hidReportSize += (6 * 2 );
319
+ _hidReportSize += (axisCount * 2 );
320
+
321
+ Serial.print (" _hidReportSize: " );
322
+ Serial.println (_hidReportSize);
295
323
296
324
// Initalize Joystick State
297
325
_xAxis = 0 ;
@@ -541,20 +569,7 @@ void Joystick_::sendState()
541
569
data[index++] = highByte;
542
570
}
543
571
544
- /*
545
- Serial.print("About to send report. _hidReportSize = ");
546
- Serial.print(_hidReportSize);
547
- Serial.print("; index = ");
548
- Serial.print(index);
549
- Serial.print("; xAxis = ");
550
- Serial.print(_xAxis);
551
- Serial.print("; _zAxisRotation = ");
552
- Serial.print(_zAxisRotation);
553
- Serial.print("; _zAxisRotation Mapped Value = ");
554
- Serial.println(axisValue);
555
- */
556
-
557
572
DynamicHID ().SendReport (_hidReportId, data, _hidReportSize);
558
573
}
559
574
560
- #endif
575
+ #endif
0 commit comments