Skip to content

Commit c98076e

Browse files
committed
Add patch from MHeironimus#120
1 parent 36f2396 commit c98076e

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/Joystick.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,9 +437,12 @@ Joystick_::Joystick_(
437437
memcpy(customHidReportDescriptor, tempHidReportDescriptor, hidReportDescriptorSize);
438438

439439
// Register HID Report Description
440+
#ifdef USE_TINYUSB
441+
_usb_hid.setReportDescriptor(customHidReportDescriptor, hidReportDescriptorSize);
442+
#else
440443
DynamicHIDSubDescriptor *node = new DynamicHIDSubDescriptor(customHidReportDescriptor, hidReportDescriptorSize, false);
441444
DynamicHID().AppendDescriptor(node);
442-
445+
#endif
443446
// Setup Joystick State
444447
if (buttonCount > 0) {
445448
_buttonValuesArraySize = _buttonCount / 8;
@@ -479,6 +482,12 @@ Joystick_::Joystick_(
479482

480483
void Joystick_::begin(bool initAutoSendState)
481484
{
485+
#ifdef USE_TINYUSB
486+
_usb_hid.setPollInterval(2);
487+
_usb_hid.begin();
488+
489+
while(!USBDevice.mounted()) delay(1);
490+
#endif
482491
_autoSendState = initAutoSendState;
483492
sendState();
484493
}
@@ -676,7 +685,16 @@ void Joystick_::sendState()
676685
index += buildAndSetSimulationValue(_includeSimulatorFlags & JOYSTICK_INCLUDE_BRAKE, _brake, _brakeMinimum, _brakeMaximum, &(data[index]));
677686
index += buildAndSetSimulationValue(_includeSimulatorFlags & JOYSTICK_INCLUDE_STEERING, _steering, _steeringMinimum, _steeringMaximum, &(data[index]));
678687

688+
#ifdef USE_TINYUSB
689+
if (_usb_hid.ready()) {
690+
_usb_hid.sendReport(_hidReportId, data, _hidReportSize);
691+
}
692+
693+
if (USBDevice.suspended())
694+
USBDevice.remoteWakeup();
695+
#else
679696
DynamicHID().SendReport(_hidReportId, data, _hidReportSize);
697+
#endif
680698
}
681699

682700
#endif

src/Joystick.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@
2121
#ifndef JOYSTICK_h
2222
#define JOYSTICK_h
2323

24+
#ifdef USE_TINYUSB
25+
#include <Adafruit_TinyUSB.h>
26+
#else
2427
#include "DynamicHID/DynamicHID.h"
28+
#endif
2529

2630
#if ARDUINO < 10606
2731
#error The Joystick library requires Arduino IDE 1.6.6 or greater. Please update your IDE.
@@ -106,6 +110,9 @@ class Joystick_
106110

107111
uint8_t _hidReportId;
108112
uint8_t _hidReportSize;
113+
#ifdef USE_TINYUSB
114+
Adafruit_USBD_HID _usb_hid;
115+
#endif
109116

110117
protected:
111118
int buildAndSet16BitValue(bool includeValue, int32_t value, int32_t valueMinimum, int32_t valueMaximum, int32_t actualMinimum, int32_t actualMaximum, uint8_t dataLocation[]);

0 commit comments

Comments
 (0)