diff --git a/libraries/HID/src/HID.cpp b/libraries/HID/src/HID.cpp index 21ede269e..492112c30 100644 --- a/libraries/HID/src/HID.cpp +++ b/libraries/HID/src/HID.cpp @@ -54,11 +54,11 @@ int HID_::getDescriptor(USBSetup& setup) return -1; total += res; } - + // Reset the protocol on reenumeration. Normally the host should not assume the state of the protocol // due to the USB specs, but Windows and Linux just assumes its in report mode. protocol = HID_REPORT_PROTOCOL; - + return total; } @@ -86,6 +86,11 @@ void HID_::AppendDescriptor(HIDSubDescriptor *node) descriptorSize += node->length; } +uint8_t HID_::getKeyboardLedsStatus(void) +{ + return _keyboardLedsStatus; +} + int HID_::SendReport(uint8_t id, const void* data, int len) { auto ret = USB_Send(pluggedEndpoint, &id, 1); @@ -133,6 +138,15 @@ bool HID_::setup(USBSetup& setup) } if (request == HID_SET_REPORT) { + if (setup.wLength == 2) + { + uint8_t data[2]; + if (2 == USB_RecvControl(data, 2)) + { + _keyboardLedsStatus = data[1]; + return true; + } + } //uint8_t reportID = setup.wValueL; //uint16_t length = setup.wLength; //uint8_t data[length]; diff --git a/libraries/HID/src/HID.h b/libraries/HID/src/HID.h index 93c4bd5b4..13c7fbb64 100644 --- a/libraries/HID/src/HID.h +++ b/libraries/HID/src/HID.h @@ -72,7 +72,7 @@ typedef struct uint8_t descLenH; } HIDDescDescriptor; -typedef struct +typedef struct { InterfaceDescriptor hid; HIDDescDescriptor desc; @@ -95,6 +95,7 @@ class HID_ : public PluggableUSBModule int begin(void); int SendReport(uint8_t id, const void* data, int len); void AppendDescriptor(HIDSubDescriptor* node); + uint8_t getKeyboardLedsStatus(void); protected: // Implementation of the PluggableUSBModule @@ -111,6 +112,7 @@ class HID_ : public PluggableUSBModule uint8_t protocol; uint8_t idle; + uint8_t _keyboardLedsStatus; }; // Replacement for global singleton.