Joystick now supports 24 buttons (ch9-32) (fix #3268)
This commit is contained in:
@@ -235,11 +235,19 @@ 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 ) {
|
||||
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
|
||||
@@ -248,7 +256,7 @@ void usbJoystickUpdate(void)
|
||||
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);
|
||||
HID_Buffer[i+3] = static_cast<int8_t>(value);
|
||||
}
|
||||
|
||||
USBD_HID_SendReport (&USB_OTG_dev, HID_Buffer, HID_IN_PACKET );
|
||||
|
||||
@@ -42,7 +42,7 @@
|
||||
#define HID_IN_EP 0x81
|
||||
#define HID_OUT_EP 0x01
|
||||
|
||||
#define HID_IN_PACKET 9
|
||||
#define HID_IN_PACKET 11
|
||||
#define HID_OUT_PACKET 9
|
||||
|
||||
#define CDC_IN_EP 0x81 /* EP1 for data IN */
|
||||
|
||||
@@ -90,13 +90,15 @@ static uint8_t USBD_HID_DataIn (void *pdev, uint8_t epnum);
|
||||
#endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
|
||||
/*
|
||||
This USB HID endpoint report description defines a device with:
|
||||
* 8 digital buttons
|
||||
* 24 digital buttons
|
||||
* 8 analog axes with 8bit resolution
|
||||
|
||||
Repot packet described as C struct is:
|
||||
|
||||
struct {
|
||||
uint8_t buttons; //bit 0 - button 1, bit 1 - button 2, ..., mapped to channels 9-16, on if channel > 0
|
||||
uint8_t buttons1; //bit 0 - button 1, bit 1 - button 2, ..., mapped to channels 9-16, on if channel > 0
|
||||
uint8_t buttons2; // mapped to channels 17-24, on if channel > 0
|
||||
uint8_t buttons3; // mapped to channels 25-32, on if channel > 0
|
||||
uint8_t X; //analog value, mapped to channel 1
|
||||
uint8_t Y; //analog value, mapped to channel 2
|
||||
uint8_t Z; //analog value, mapped to channel 3
|
||||
@@ -115,10 +117,10 @@ __ALIGN_BEGIN static const uint8_t HID_JOYSTICK_ReportDesc[] __ALIGN_END =
|
||||
0xa1, 0x00, // COLLECTION (Physical)
|
||||
0x05, 0x09, // USAGE_PAGE (Button)
|
||||
0x19, 0x01, // USAGE_MINIMUM (Button 1)
|
||||
0x29, 0x08, // USAGE_MAXIMUM (Button 8)
|
||||
0x29, 0x18, // USAGE_MAXIMUM (Button 24)
|
||||
0x15, 0x00, // LOGICAL_MINIMUM (0)
|
||||
0x25, 0x01, // LOGICAL_MAXIMUM (1)
|
||||
0x95, 0x08, // REPORT_COUNT (8)
|
||||
0x95, 0x18, // REPORT_COUNT (24)
|
||||
0x75, 0x01, // REPORT_SIZE (1)
|
||||
0x81, 0x02, // INPUT (Data,Var,Abs)
|
||||
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
|
||||
|
||||
Reference in New Issue
Block a user