mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-20 23:05:19 +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:
parent
8e361c574b
commit
d62273f43d
2 changed files with 31 additions and 7 deletions
|
@ -37,7 +37,11 @@ typedef enum rc_alias {
|
||||||
AUX5,
|
AUX5,
|
||||||
AUX6,
|
AUX6,
|
||||||
AUX7,
|
AUX7,
|
||||||
AUX8
|
AUX8,
|
||||||
|
AUX9,
|
||||||
|
AUX10,
|
||||||
|
AUX11,
|
||||||
|
AUX12
|
||||||
} rc_alias_e;
|
} rc_alias_e;
|
||||||
|
|
||||||
#define PRIMARY_CHANNEL_COUNT (THROTTLE + 1)
|
#define PRIMARY_CHANNEL_COUNT (THROTTLE + 1)
|
||||||
|
|
|
@ -39,6 +39,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define USB_CDC_HID_NUM_AXES 8
|
#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_MIN -127
|
||||||
#define USB_CDC_HID_RANGE_MAX 127
|
#define USB_CDC_HID_RANGE_MAX 127
|
||||||
|
@ -48,25 +49,44 @@
|
||||||
const uint8_t hidChannelMapping[] = {
|
const uint8_t hidChannelMapping[] = {
|
||||||
ROLL, // X
|
ROLL, // X
|
||||||
PITCH, // Y
|
PITCH, // Y
|
||||||
AUX3,
|
AUX3, // Z
|
||||||
YAW, // X Rotation
|
YAW, // X Rotation
|
||||||
AUX1, // Z Rotation
|
AUX1, // Z Rotation
|
||||||
THROTTLE, // Y Rotation
|
THROTTLE, // Y Rotation
|
||||||
AUX4,
|
AUX4, // Slider
|
||||||
AUX2, // Wheel
|
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)
|
void sendRcDataToHid(void)
|
||||||
{
|
{
|
||||||
int8_t report[8];
|
int8_t report[9];
|
||||||
|
// Axes
|
||||||
for (unsigned i = 0; i < USB_CDC_HID_NUM_AXES; i++) {
|
for (unsigned i = 0; i < USB_CDC_HID_NUM_AXES; i++) {
|
||||||
const uint8_t channel = hidChannelMapping[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);
|
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) {
|
if (channel == PITCH) {
|
||||||
// For some reason ROLL is inverted in Windows
|
// PITCH is inverted in Windows
|
||||||
report[i] = -report[i];
|
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)
|
#if defined(STM32F4)
|
||||||
USBD_HID_SendReport(&USB_OTG_dev, (uint8_t*)report, sizeof(report));
|
USBD_HID_SendReport(&USB_OTG_dev, (uint8_t*)report, sizeof(report));
|
||||||
#elif defined(STM32F7) || defined(STM32H7)
|
#elif defined(STM32F7) || defined(STM32H7)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue