Made SetReportData more flexible
can now take more data and keep the data array if changed to zero.
This commit is contained in:
parent
a0edeebc61
commit
803ecfddf5
10 changed files with 24 additions and 13 deletions
|
|
@ -37,7 +37,7 @@ Use the [online Wiki](https://github.com/NicoHood/HID/wiki) to get the newest do
|
|||
* Download an offline version in [releases](https://github.com/NicoHood/HID/releases).
|
||||
It's a snapshot of the current stable release but might have missed some updates that the current master branch has included.
|
||||
This also includes an offline version of the wiki. Offline versions will be available after some time when the official release is out.
|
||||
* Select [branch 'dev'](https://github.com/NicoHood/HID/tree/dev) to test the bleeding edge of this software. It might now work at all or has a lot of debugging stuff in it.
|
||||
* Select [branch 'dev'](https://github.com/NicoHood/HID/tree/dev) to test the bleeding edge of this software. It might not work at all or has a lot of debugging stuff in it.
|
||||
If the dev version gets near to a new release a note will be placed here, that you can test the new dev beta.
|
||||
Currently there is no beta available.
|
||||
|
||||
|
|
|
|||
|
|
@ -116,7 +116,7 @@ void Keyboard_::send_now(void){
|
|||
}
|
||||
|
||||
#if defined(HID_KEYBOARD_LEDS_ENABLED)
|
||||
void Keyboard_::setReportData(const void* data, uint8_t len){
|
||||
void Keyboard_::setReportData(void* &data, uint16_t len){
|
||||
// Save led state
|
||||
if(len == 2)
|
||||
leds = *(uint8_t*)(data+1);
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ private:
|
|||
HID_KeyboardReport_Data_t _keyReport;
|
||||
void sendReport(HID_KeyboardReport_Data_t* keys);
|
||||
#if defined(HID_KEYBOARD_LEDS_ENABLED)
|
||||
virtual void setReportData(const void* data, uint8_t len);
|
||||
virtual void setReportData(void* &data, uint16_t len);
|
||||
uint8_t leds;
|
||||
#endif
|
||||
public:
|
||||
|
|
|
|||
|
|
@ -121,7 +121,7 @@ void NKROKeyboard_::send_now(void){
|
|||
}
|
||||
|
||||
#if defined(HID_KEYBOARD_LEDS_ENABLED)
|
||||
void NKROKeyboard_::setReportData(const void* data, uint8_t len){
|
||||
void NKROKeyboard_::setReportData(void* &data, uint16_t len){
|
||||
// Save led state
|
||||
if(len == 2)
|
||||
leds = *(uint8_t*)(data+1);
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ protected:
|
|||
HID_NKROKeyboardReport_Data_t _keyReport;
|
||||
void sendReport(HID_NKROKeyboardReport_Data_t* keys);
|
||||
#if defined(HID_KEYBOARD_LEDS_ENABLED)
|
||||
virtual void setReportData(const void* data, uint8_t len);
|
||||
virtual void setReportData(void* &data, uint16_t len);
|
||||
uint8_t leds;
|
||||
#endif
|
||||
public:
|
||||
|
|
|
|||
|
|
@ -169,11 +169,22 @@ bool HID_::HID_Setup(USBSetup& setup, u8 i)
|
|||
// Get the data length information and the corresponding bytes
|
||||
// Assuming the host will never send more than 255 bytes
|
||||
uint8_t length = setup.wLength;
|
||||
uint8_t data[length];
|
||||
USB_RecvControl(data, length);
|
||||
void* data = malloc(length);
|
||||
if(data){
|
||||
uint8_t recvLength = length;
|
||||
//TODO loop can be improved maybe? Or does the compiler do this already?
|
||||
while(recvLength > USB_EP_SIZE){
|
||||
USB_RecvControl(data + (length - recvLength), USB_EP_SIZE);
|
||||
recvLength -= USB_EP_SIZE;
|
||||
}
|
||||
USB_RecvControl(data + (length - recvLength), recvLength);
|
||||
|
||||
// Data may contain the report ID again (Keyboard), maybe not (RawHID)
|
||||
current->setReportData(data, length);
|
||||
// Data may contain the report ID again (Keyboard), maybe not (RawHID)
|
||||
current->setReportData(data, length);
|
||||
}
|
||||
|
||||
// Release data if the pointer still exists
|
||||
free(data);
|
||||
|
||||
// Dont search any further
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ void HIDDevice::SendRawReport(const void* data, int len){
|
|||
HID.SendReport(HID_REPORTID_NONE, data, len);
|
||||
}
|
||||
|
||||
void HIDDevice::setReportData(const void* data, uint8_t len){
|
||||
void HIDDevice::setReportData(void* &data, uint16_t len){
|
||||
// Discard this information if its not implemented by the HIDDevice
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ public:
|
|||
const uint16_t descriptorLength;
|
||||
const uint8_t reportID;
|
||||
|
||||
virtual void setReportData(const void* data, uint8_t len);
|
||||
virtual void setReportData(void* &data, uint16_t len);
|
||||
|
||||
protected:
|
||||
// Could be used and inherited public for custom, professional usage, like raw Keyboard
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ HIDDevice((uint8_t*)teensykeyboard_hid_report_desc, sizeof(teensykeyboard_hid_re
|
|||
}
|
||||
|
||||
#if defined(HID_KEYBOARD_LEDS_ENABLED)
|
||||
void usb_keyboard_class::setReportData(const void* data, uint8_t len){
|
||||
void usb_keyboard_class::setReportData(void* &data, uint16_t len){
|
||||
// Save led state
|
||||
if(len == 2)
|
||||
leds = *(uint8_t*)(data+1);
|
||||
|
|
|
|||
|
|
@ -128,7 +128,7 @@ class usb_keyboard_class : public Print, private HIDDevice
|
|||
uint8_t keyboard_report_data[8];
|
||||
|
||||
#if defined(HID_KEYBOARD_LEDS_ENABLED)
|
||||
virtual void setReportData(const void* data, uint8_t len);
|
||||
virtual void setReportData(void* &data, uint16_t len);
|
||||
uint8_t leds;
|
||||
#endif
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue