Fixes #3772: USB Joystick channels were mapped incorrectly on Horus

This commit is contained in:
Damjan Adamic
2016-09-10 12:06:51 +02:00
parent 95fc89ec67
commit 294611c457
2 changed files with 26 additions and 18 deletions
+14 -6
View File
@@ -207,23 +207,31 @@ void usbJoystickUpdate(void)
static uint8_t HID_Buffer[HID_IN_PACKET];
//buttons
HID_Buffer[0] = 0; //buttons
HID_Buffer[0] = 0;
HID_Buffer[1] = 0;
HID_Buffer[2] = 0;
for (int i = 0; i < 8; ++i) {
if (channelOutputs[i+8] > 0) {
if ( channelOutputs[i+8] > 0 ) {
HID_Buffer[0] |= (1 << i);
}
if ( channelOutputs[i+16] > 0 ) {
HID_Buffer[1] |= (1 << i);
}
if ( channelOutputs[i+24] > 0 ) {
HID_Buffer[2] |= (1 << i);
}
}
//analog values
//uint8_t * p = HID_Buffer + 1;
for (int i = 0; i < 8; ++i) {
int16_t value = channelOutputs[i] / 8;
if (value > 127) value = 127;
else if (value < -127) value = -127;
HID_Buffer[i+1] = static_cast<int8_t>(value);
if ( value > 127 ) value = 127;
else if ( value < -127 ) value = -127;
HID_Buffer[i+3] = static_cast<int8_t>(value);
}
USBD_HID_SendReport (&USB_OTG_dev, HID_Buffer, HID_IN_PACKET);
USBD_HID_SendReport (&USB_OTG_dev, HID_Buffer, HID_IN_PACKET );
}
#endif // #defined(USB_JOYSTICK) && !defined(SIMU)
+12 -12
View File
@@ -2,7 +2,7 @@
* Copyright (C) OpenTX
*
* Based on code named
* th9x - http://code.google.com/p/th9x
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
@@ -127,7 +127,7 @@ void boardInit()
ledInit();
ledGreen();
#endif
keysInit();
adcInit();
delaysInit();
@@ -138,8 +138,8 @@ void boardInit()
__enable_irq();
i2cInit();
usbInit();
#if defined(HAPTIC)
#if defined(HAPTIC)
hapticInit();
#endif
@@ -203,7 +203,7 @@ void boardOff()
#if defined(PCBX7D)
ledOff();
#endif
BACKLIGHT_DISABLE();
#if defined(PCBX9E)
@@ -228,13 +228,13 @@ extern USB_OTG_CORE_HANDLE USB_OTG_dev;
Prepare and send new USB data packet
The format of HID_Buffer is defined by
USB endpoint description can be found in
USB endpoint description can be found in
file usb_hid_joystick.c, variable HID_JOYSTICK_ReportDesc
*/
void usbJoystickUpdate(void)
{
static uint8_t HID_Buffer[HID_IN_PACKET];
//buttons
HID_Buffer[0] = 0;
HID_Buffer[1] = 0;
@@ -242,13 +242,13 @@ void usbJoystickUpdate(void)
for (int i = 0; i < 8; ++i) {
if ( channelOutputs[i+8] > 0 ) {
HID_Buffer[0] |= (1 << i);
}
}
if ( channelOutputs[i+16] > 0 ) {
HID_Buffer[1] |= (1 << i);
}
}
if ( channelOutputs[i+24] > 0 ) {
HID_Buffer[2] |= (1 << i);
}
}
}
//analog values
@@ -257,13 +257,13 @@ void usbJoystickUpdate(void)
int16_t value = channelOutputs[i] / 8;
if ( value > 127 ) value = 127;
else if ( value < -127 ) value = -127;
HID_Buffer[i+3] = static_cast<int8_t>(value);
HID_Buffer[i+3] = static_cast<int8_t>(value);
}
USBD_HID_SendReport (&USB_OTG_dev, HID_Buffer, HID_IN_PACKET );
}
#endif // defined(USB_JOYSTICK) && defined(PCBTARANIS) && !defined(SIMU)
#endif // #defined(USB_JOYSTICK) && !defined(SIMU)
uint8_t currentTrainerMode = 0xff;