Skip to content

Commit 139a97d

Browse files
authored
Add LED status capability
Add the ability to return the status of the LEDs for CAPS_LOCK, NUM_LOCK and SCROLL_LOCK. Updates to Arduino-keyboard required for this to be useful.
1 parent 3055c1e commit 139a97d

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

libraries/HID/src/HID.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ int HID_::getDescriptor(USBSetup& setup)
5454
return -1;
5555
total += res;
5656
}
57-
57+
5858
// Reset the protocol on reenumeration. Normally the host should not assume the state of the protocol
5959
// due to the USB specs, but Windows and Linux just assumes its in report mode.
6060
protocol = HID_REPORT_PROTOCOL;
61-
61+
6262
return total;
6363
}
6464

@@ -86,6 +86,11 @@ void HID_::AppendDescriptor(HIDSubDescriptor *node)
8686
descriptorSize += node->length;
8787
}
8888

89+
uint8_t HID_::getKeyboardLedsStatus(void)
90+
{
91+
return _keyboardLedsStatus;
92+
}
93+
8994
int HID_::SendReport(uint8_t id, const void* data, int len)
9095
{
9196
auto ret = USB_Send(pluggedEndpoint, &id, 1);
@@ -133,6 +138,15 @@ bool HID_::setup(USBSetup& setup)
133138
}
134139
if (request == HID_SET_REPORT)
135140
{
141+
if (setup.wLength == 2)
142+
{
143+
uint8_t data[2];
144+
if (2 == USB_RecvControl(data, 2))
145+
{
146+
_keyboardLedsStatus = data[1];
147+
return true;
148+
}
149+
}
136150
//uint8_t reportID = setup.wValueL;
137151
//uint16_t length = setup.wLength;
138152
//uint8_t data[length];

libraries/HID/src/HID.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ typedef struct
7272
uint8_t descLenH;
7373
} HIDDescDescriptor;
7474

75-
typedef struct
75+
typedef struct
7676
{
7777
InterfaceDescriptor hid;
7878
HIDDescDescriptor desc;
@@ -95,6 +95,7 @@ class HID_ : public PluggableUSBModule
9595
int begin(void);
9696
int SendReport(uint8_t id, const void* data, int len);
9797
void AppendDescriptor(HIDSubDescriptor* node);
98+
uint8_t getKeyboardLedsStatus(void);
9899

99100
protected:
100101
// Implementation of the PluggableUSBModule
@@ -111,6 +112,7 @@ class HID_ : public PluggableUSBModule
111112

112113
uint8_t protocol;
113114
uint8_t idle;
115+
uint8_t _keyboardLedsStatus;
114116
};
115117

116118
// Replacement for global singleton.

0 commit comments

Comments
 (0)