Skip to content

Commit

Permalink
Add patch from MHeironimus#120
Browse files Browse the repository at this point in the history
  • Loading branch information
tagantroy committed Nov 3, 2022
1 parent 36f2396 commit c98076e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/Joystick.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -437,9 +437,12 @@ Joystick_::Joystick_(
memcpy(customHidReportDescriptor, tempHidReportDescriptor, hidReportDescriptorSize);

// Register HID Report Description
#ifdef USE_TINYUSB
_usb_hid.setReportDescriptor(customHidReportDescriptor, hidReportDescriptorSize);
#else
DynamicHIDSubDescriptor *node = new DynamicHIDSubDescriptor(customHidReportDescriptor, hidReportDescriptorSize, false);
DynamicHID().AppendDescriptor(node);
#endif
// Setup Joystick State
if (buttonCount > 0) {
_buttonValuesArraySize = _buttonCount / 8;
Expand Down Expand Up @@ -479,6 +482,12 @@ Joystick_::Joystick_(

void Joystick_::begin(bool initAutoSendState)
{
#ifdef USE_TINYUSB
_usb_hid.setPollInterval(2);
_usb_hid.begin();

while(!USBDevice.mounted()) delay(1);
#endif
_autoSendState = initAutoSendState;
sendState();
}
Expand Down Expand Up @@ -676,7 +685,16 @@ void Joystick_::sendState()
index += buildAndSetSimulationValue(_includeSimulatorFlags & JOYSTICK_INCLUDE_BRAKE, _brake, _brakeMinimum, _brakeMaximum, &(data[index]));
index += buildAndSetSimulationValue(_includeSimulatorFlags & JOYSTICK_INCLUDE_STEERING, _steering, _steeringMinimum, _steeringMaximum, &(data[index]));

#ifdef USE_TINYUSB
if (_usb_hid.ready()) {
_usb_hid.sendReport(_hidReportId, data, _hidReportSize);
}

if (USBDevice.suspended())
USBDevice.remoteWakeup();
#else
DynamicHID().SendReport(_hidReportId, data, _hidReportSize);
#endif
}

#endif
7 changes: 7 additions & 0 deletions src/Joystick.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@
#ifndef JOYSTICK_h
#define JOYSTICK_h

#ifdef USE_TINYUSB
#include <Adafruit_TinyUSB.h>
#else
#include "DynamicHID/DynamicHID.h"
#endif

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

uint8_t _hidReportId;
uint8_t _hidReportSize;
#ifdef USE_TINYUSB
Adafruit_USBD_HID _usb_hid;
#endif

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

0 comments on commit c98076e

Please sign in to comment.