1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-20 14:55:21 +03:00

Fixed misaligned report 'usages', added few chnls

Fixed bracket

Removed extra semicolon

Fixed misaligned report 'usages', added few chnls

Reverted lib changes
This commit is contained in:
Davor Kustec 2020-08-28 21:27:37 +02:00
parent 8e361c574b
commit d62273f43d
2 changed files with 31 additions and 7 deletions

View file

@ -37,7 +37,11 @@ typedef enum rc_alias {
AUX5,
AUX6,
AUX7,
AUX8
AUX8,
AUX9,
AUX10,
AUX11,
AUX12
} rc_alias_e;
#define PRIMARY_CHANNEL_COUNT (THROTTLE + 1)

View file

@ -39,6 +39,7 @@
#endif
#define USB_CDC_HID_NUM_AXES 8
#define USB_CDC_HID_NUM_BUTTONS 8
#define USB_CDC_HID_RANGE_MIN -127
#define USB_CDC_HID_RANGE_MAX 127
@ -48,25 +49,44 @@
const uint8_t hidChannelMapping[] = {
ROLL, // X
PITCH, // Y
AUX3,
AUX3, // Z
YAW, // X Rotation
AUX1, // Z Rotation
THROTTLE, // Y Rotation
AUX4,
AUX2, // Wheel
AUX4, // Slider
AUX2, // Dial
AUX5, // Button 1
AUX6, // Button 2
AUX7, // Button 3
AUX8, // Button 4
AUX9, // Button 5
AUX10, // Button 6
AUX11, // Button 7
AUX12 // Button 8
};
void sendRcDataToHid(void)
{
int8_t report[8];
int8_t report[9];
// Axes
for (unsigned i = 0; i < USB_CDC_HID_NUM_AXES; i++) {
const uint8_t channel = hidChannelMapping[i];
report[i] = scaleRange(constrain(rcData[channel], PWM_RANGE_MIN, PWM_RANGE_MAX), PWM_RANGE_MIN, PWM_RANGE_MAX, USB_CDC_HID_RANGE_MIN, USB_CDC_HID_RANGE_MAX);
if (i == 1) {
// For some reason ROLL is inverted in Windows
if (channel == PITCH) {
// PITCH is inverted in Windows
report[i] = -report[i];
}
}
// Buttons
// Each bit in one byte represents one button so we have 8 buttons in one-byte-data
report[8] = 0;
for (unsigned i = 0; i < USB_CDC_HID_NUM_BUTTONS; i++) {
const uint8_t channel = hidChannelMapping[i + USB_CDC_HID_NUM_AXES];
if (scaleRange(constrain(rcData[channel], PWM_RANGE_MIN, PWM_RANGE_MAX), PWM_RANGE_MIN, PWM_RANGE_MAX, USB_CDC_HID_RANGE_MIN, USB_CDC_HID_RANGE_MAX) > 0) {
report[8] |= (1 << i);
}
}
#if defined(STM32F4)
USBD_HID_SendReport(&USB_OTG_dev, (uint8_t*)report, sizeof(report));
#elif defined(STM32F7) || defined(STM32H7)