@@ -35,32 +35,42 @@ static const uint8_t _hidReportDescriptor[] PROGMEM = {
35
35
0xa1 , 0x01 , // COLLECTION (Application)
36
36
0x85 , 0x02 , // REPORT_ID (2)
37
37
0x05 , 0x07 , // USAGE_PAGE (Keyboard)
38
-
38
+
39
39
0x19 , 0xe0 , // USAGE_MINIMUM (Keyboard LeftControl)
40
40
0x29 , 0xe7 , // USAGE_MAXIMUM (Keyboard Right GUI)
41
41
0x15 , 0x00 , // LOGICAL_MINIMUM (0)
42
42
0x25 , 0x01 , // LOGICAL_MAXIMUM (1)
43
43
0x75 , 0x01 , // REPORT_SIZE (1)
44
-
44
+
45
45
0x95 , 0x08 , // REPORT_COUNT (8)
46
46
0x81 , 0x02 , // INPUT (Data,Var,Abs)
47
47
0x95 , 0x01 , // REPORT_COUNT (1)
48
48
0x75 , 0x08 , // REPORT_SIZE (8)
49
49
0x81 , 0x03 , // INPUT (Cnst,Var,Abs)
50
-
50
+
51
+ 0x95 , 0x05 , // REPORT_COUNT (5)
52
+ 0x75 , 0x01 , // REPORT_SIZE (1)
53
+ 0x05 , 0x08 , // USAGE_PAGE (LEDs)
54
+ 0x19 , 0x01 , // USAGE_MINIMUM (1)
55
+ 0x29 , 0x05 , // USAGE_MAXIMUM (5)
56
+ 0x91 , 0x02 , // OUTPUT (Data,Var,Abs) // LED report
57
+ 0x95 , 0x01 , // REPORT_COUNT (1)
58
+ 0x75 , 0x03 , // REPORT_SIZE (3)
59
+ 0x91 , 0x01 , // OUTPUT (Constant) // padding
60
+
51
61
0x95 , 0x06 , // REPORT_COUNT (6)
52
62
0x75 , 0x08 , // REPORT_SIZE (8)
53
63
0x15 , 0x00 , // LOGICAL_MINIMUM (0)
54
64
0x25 , 0x73 , // LOGICAL_MAXIMUM (115)
55
65
0x05 , 0x07 , // USAGE_PAGE (Keyboard)
56
-
66
+
57
67
0x19 , 0x00 , // USAGE_MINIMUM (Reserved (no event indicated))
58
68
0x29 , 0x73 , // USAGE_MAXIMUM (Keyboard Application)
59
69
0x81 , 0x00 , // INPUT (Data,Ary,Abs)
60
70
0xc0 , // END_COLLECTION
61
71
};
62
72
63
- Keyboard_::Keyboard_ (void )
73
+ Keyboard_::Keyboard_ (void )
64
74
{
65
75
static HIDSubDescriptor node (_hidReportDescriptor, sizeof (_hidReportDescriptor));
66
76
HID ().AppendDescriptor (&node);
@@ -91,16 +101,16 @@ const uint8_t _asciimap[128] =
91
101
0x00 , // ETX
92
102
0x00 , // EOT
93
103
0x00 , // ENQ
94
- 0x00 , // ACK
104
+ 0x00 , // ACK
95
105
0x00 , // BEL
96
106
0x2a , // BS Backspace
97
107
0x2b , // TAB Tab
98
108
0x28 , // LF Enter
99
- 0x00 , // VT
100
- 0x00 , // FF
101
- 0x00 , // CR
102
- 0x00 , // SO
103
- 0x00 , // SI
109
+ 0x00 , // VT
110
+ 0x00 , // FF
111
+ 0x00 , // CR
112
+ 0x00 , // SO
113
+ 0x00 , // SI
104
114
0x00 , // DEL
105
115
0x00 , // DC1
106
116
0x00 , // DC2
@@ -110,13 +120,13 @@ const uint8_t _asciimap[128] =
110
120
0x00 , // SYN
111
121
0x00 , // ETB
112
122
0x00 , // CAN
113
- 0x00 , // EM
123
+ 0x00 , // EM
114
124
0x00 , // SUB
115
125
0x00 , // ESC
116
- 0x00 , // FS
117
- 0x00 , // GS
118
- 0x00 , // RS
119
- 0x00 , // US
126
+ 0x00 , // FS
127
+ 0x00 , // GS
128
+ 0x00 , // RS
129
+ 0x00 , // US
120
130
121
131
0x2c , // ' '
122
132
0x1e |SHIFT, // !
@@ -220,10 +230,10 @@ const uint8_t _asciimap[128] =
220
230
uint8_t USBPutChar (uint8_t c);
221
231
222
232
// press() adds the specified key (printing, non-printing, or modifier)
223
- // to the persistent key report and sends the report. Because of the way
224
- // USB HID works, the host acts like the key remains pressed until we
233
+ // to the persistent key report and sends the report. Because of the way
234
+ // USB HID works, the host acts like the key remains pressed until we
225
235
// call release(), releaseAll(), or otherwise clear the report and resend.
226
- size_t Keyboard_::press (uint8_t k)
236
+ size_t Keyboard_::press (uint8_t k)
227
237
{
228
238
uint8_t i;
229
239
if (k >= 136 ) { // it's a non-printing key (not a modifier)
@@ -242,13 +252,13 @@ size_t Keyboard_::press(uint8_t k)
242
252
k &= 0x7F ;
243
253
}
244
254
}
245
-
255
+
246
256
// Add k to the key report only if it's not already present
247
257
// and if there is an empty slot.
248
- if (_keyReport.keys [0 ] != k && _keyReport.keys [1 ] != k &&
258
+ if (_keyReport.keys [0 ] != k && _keyReport.keys [1 ] != k &&
249
259
_keyReport.keys [2 ] != k && _keyReport.keys [3 ] != k &&
250
260
_keyReport.keys [4 ] != k && _keyReport.keys [5 ] != k) {
251
-
261
+
252
262
for (i=0 ; i<6 ; i++) {
253
263
if (_keyReport.keys [i] == 0x00 ) {
254
264
_keyReport.keys [i] = k;
@@ -258,7 +268,7 @@ size_t Keyboard_::press(uint8_t k)
258
268
if (i == 6 ) {
259
269
setWriteError ();
260
270
return 0 ;
261
- }
271
+ }
262
272
}
263
273
sendReport (&_keyReport);
264
274
return 1 ;
@@ -267,7 +277,7 @@ size_t Keyboard_::press(uint8_t k)
267
277
// release() takes the specified key out of the persistent key report and
268
278
// sends the report. This tells the OS the key is no longer pressed and that
269
279
// it shouldn't be repeated any more.
270
- size_t Keyboard_::release (uint8_t k)
280
+ size_t Keyboard_::release (uint8_t k)
271
281
{
272
282
uint8_t i;
273
283
if (k >= 136 ) { // it's a non-printing key (not a modifier)
@@ -285,7 +295,7 @@ size_t Keyboard_::release(uint8_t k)
285
295
k &= 0x7F ;
286
296
}
287
297
}
288
-
298
+
289
299
// Test the key report to see if k is present. Clear it if it exists.
290
300
// Check all positions in case the key is present more than once (which it shouldn't be)
291
301
for (i=0 ; i<6 ; i++) {
@@ -301,11 +311,11 @@ size_t Keyboard_::release(uint8_t k)
301
311
void Keyboard_::releaseAll (void )
302
312
{
303
313
_keyReport.keys [0 ] = 0 ;
304
- _keyReport.keys [1 ] = 0 ;
314
+ _keyReport.keys [1 ] = 0 ;
305
315
_keyReport.keys [2 ] = 0 ;
306
- _keyReport.keys [3 ] = 0 ;
316
+ _keyReport.keys [3 ] = 0 ;
307
317
_keyReport.keys [4 ] = 0 ;
308
- _keyReport.keys [5 ] = 0 ;
318
+ _keyReport.keys [5 ] = 0 ;
309
319
_keyReport.modifiers = 0 ;
310
320
sendReport (&_keyReport);
311
321
}
@@ -332,7 +342,25 @@ size_t Keyboard_::write(const uint8_t *buffer, size_t size) {
332
342
return n;
333
343
}
334
344
345
+ bool Keyboard_::getLedStatus (uint8_t led)
346
+ {
347
+ uint8_t _keyboardLedsStatus = HID ().getKeyboardLedsStatus ();
348
+ if (led == LED_CAPS_LOCK) {
349
+ if (_keyboardLedsStatus == 2 || _keyboardLedsStatus == 3 || _keyboardLedsStatus == 6 || _keyboardLedsStatus == 7 ) {
350
+ return true ;
351
+ }
352
+ } else if (led == LED_NUM_LOCK) {
353
+ if (_keyboardLedsStatus == 1 || _keyboardLedsStatus == 3 || _keyboardLedsStatus == 5 || _keyboardLedsStatus == 7 ) {
354
+ return true ;
355
+ }
356
+ } else if (led == LED_SCROLL_LOCK) {
357
+ if (_keyboardLedsStatus == 4 || _keyboardLedsStatus == 5 || _keyboardLedsStatus == 6 || _keyboardLedsStatus == 7 ) {
358
+ return true ;
359
+ }
360
+ }
361
+ return false ;
362
+ }
363
+
335
364
Keyboard_ Keyboard;
336
365
337
366
#endif
338
-
0 commit comments