fix(radio): properly center analog USB joystick axis (#4883)

This commit is contained in:
ThomasKuehne
2024-05-29 17:55:06 +10:00
committed by GitHub
parent c19f6402d0
commit 3596e02195
3 changed files with 18 additions and 20 deletions
@@ -21,6 +21,8 @@
#if defined(USBJ_EX)
#include "usb_joystick.h"
#else
#include "opentx_helpers.h"
#endif
extern "C" {
@@ -75,7 +77,7 @@ int usbPlugged()
debouncedState = state;
else
lastState = state;
return debouncedState;
}
#endif
@@ -226,11 +228,10 @@ void usbJoystickUpdate()
//uint8_t * p = HID_Buffer + 1;
for (int i = 0; i < 8; ++i) {
int16_t value = channelOutputs[i] + 1024;
if ( value > 2047 ) value = 2047;
else if ( value < 0 ) value = 0;
int16_t value = limit<int16_t>(0, channelOutputs[i] + 1024, 2048);;
HID_Buffer[i*2 +3] = static_cast<uint8_t>(value & 0xFF);
HID_Buffer[i*2 +4] = static_cast<uint8_t>((value >> 8) & 0x07);
HID_Buffer[i*2 +4] = static_cast<uint8_t>(value >> 8);
}
USBD_HID_SendReport(&hUsbDeviceFS, HID_Buffer, HID_IN_PACKET);
@@ -125,7 +125,7 @@ __ALIGN_BEGIN static const uint8_t HID_JOYSTICK_ReportDesc[] __ALIGN_END =
0x09, 0x36, // USAGE (Slider)
0x09, 0x37, // USAGE (Dial)
0x16, 0x00, 0x00, // LOGICAL_MINIMUM (0)
0x26, 0xFF, 0x07, // LOGICAL_MAXIMUM (2047)
0x26, 0x00, 0x08, // LOGICAL_MAXIMUM (2048)
0x75, 0x10, // REPORT_SIZE (16)
0x95, 0x08, // REPORT_COUNT (8)
0x81, 0x02, // INPUT (Data,Var,Abs)