diff --git a/src/main/fc/rc_controls.h b/src/main/fc/rc_controls.h index d31b433b86..61bb8847af 100644 --- a/src/main/fc/rc_controls.h +++ b/src/main/fc/rc_controls.h @@ -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) diff --git a/src/main/io/usb_cdc_hid.c b/src/main/io/usb_cdc_hid.c index 96b86fb7b0..86e4a03423 100644 --- a/src/main/io/usb_cdc_hid.c +++ b/src/main/io/usb_cdc_hid.c @@ -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)