@@ -458,33 +458,9 @@ uint8_t USBPutChar(uint8_t c);
458
458
// to the persistent key report and sends the report. Because of the way
459
459
// USB HID works, the host acts like the key remains pressed until we
460
460
// call release(), releaseAll(), or otherwise clear the report and resend.
461
- size_t Keyboard_::pressRaw (uint8_t k)
462
- {
463
- uint8_t i;
464
- // Add k to the key report only if it's not already present
465
- // and if there is an empty slot.
466
- if (_keyReport.keys [0 ] != k && _keyReport.keys [1 ] != k &&
467
- _keyReport.keys [2 ] != k && _keyReport.keys [3 ] != k &&
468
- _keyReport.keys [4 ] != k && _keyReport.keys [5 ] != k) {
469
-
470
- for (i=0 ; i<6 ; i++) {
471
- if (_keyReport.keys [i] == 0x00 ) {
472
- _keyReport.keys [i] = k;
473
- break ;
474
- }
475
- }
476
- if (i == 6 || (k >= 0xE0 )) {
477
- setWriteError ();
478
- return 0 ;
479
- }
480
- }
481
- sendReport (&_keyReport);
482
- return 1 ;
483
- }
484
-
485
- // translates ASCII characters to usage
486
461
size_t Keyboard_::press (uint8_t k)
487
462
{
463
+ uint8_t i;
488
464
if (k >= 136 ) { // it's a non-printing key (not a modifier)
489
465
k = k - 136 ;
490
466
} else if (k >= 128 ) { // it's a modifier key
@@ -501,48 +477,28 @@ size_t Keyboard_::press(uint8_t k)
501
477
k &= 0x7F ;
502
478
}
503
479
}
504
- return pressRaw (k);
505
- }
506
-
507
- // release() takes the specified key out of the persistent key report and
508
- // sends the report. This tells the OS the key is no longer pressed and that
509
- // it shouldn't be repeated any more.
510
- size_t Keyboard_::releaseRaw (uint8_t k)
511
- {
512
- uint8_t i;
513
- // Test the key report to see if k is present. Clear it if it exists.
514
- // Check all positions in case the key is present more than once (which it shouldn't be)
515
- for (i=0 ; i<6 ; i++) {
516
- if (0 != k && _keyReport.keys [i] == k) {
517
- _keyReport.keys [i] = 0x00 ;
480
+
481
+ // Add k to the key report only if it's not already present
482
+ // and if there is an empty slot.
483
+ if (_keyReport.keys [0 ] != k && _keyReport.keys [1 ] != k &&
484
+ _keyReport.keys [2 ] != k && _keyReport.keys [3 ] != k &&
485
+ _keyReport.keys [4 ] != k && _keyReport.keys [5 ] != k) {
486
+
487
+ for (i=0 ; i<6 ; i++) {
488
+ if (_keyReport.keys [i] == 0x00 ) {
489
+ _keyReport.keys [i] = k;
490
+ break ;
491
+ }
518
492
}
493
+ if (i == 6 ) {
494
+ setWriteError ();
495
+ return 0 ;
496
+ }
519
497
}
520
-
521
498
sendReport (&_keyReport);
522
499
return 1 ;
523
500
}
524
501
525
- // translates ASCII characters to usage
526
- size_t Keyboard_::release (uint8_t k)
527
- {
528
- if (k >= 136 ) { // it's a non-printing key (not a modifier)
529
- k = k - 136 ;
530
- } else if (k >= 128 ) { // it's a modifier key
531
- _keyReport.modifiers &= ~(1 <<(k-128 ));
532
- k = 0 ;
533
- } else { // it's a printing key
534
- k = pgm_read_byte (_asciimap + k);
535
- if (!k) {
536
- return 0 ;
537
- }
538
- if (k & 0x80 ) { // it's a capital letter or other character reached with shift
539
- _keyReport.modifiers &= ~(0x02 ); // the left shift modifier
540
- k &= 0x7F ;
541
- }
542
- }
543
- return releaseRaw (k);
544
- }
545
-
546
502
// System Control
547
503
// k is one of the SYSTEM_CONTROL defines which come from the HID usage table "Generic Desktop Page (0x01)"
548
504
// in "HID Usage Tables" (HUT1_12v2.pdf)
@@ -575,6 +531,40 @@ size_t Keyboard_::systemControl(uint8_t k)
575
531
}
576
532
}
577
533
534
+ // release() takes the specified key out of the persistent key report and
535
+ // sends the report. This tells the OS the key is no longer pressed and that
536
+ // it shouldn't be repeated any more.
537
+ size_t Keyboard_::release (uint8_t k)
538
+ {
539
+ uint8_t i;
540
+ if (k >= 136 ) { // it's a non-printing key (not a modifier)
541
+ k = k - 136 ;
542
+ } else if (k >= 128 ) { // it's a modifier key
543
+ _keyReport.modifiers &= ~(1 <<(k-128 ));
544
+ k = 0 ;
545
+ } else { // it's a printing key
546
+ k = pgm_read_byte (_asciimap + k);
547
+ if (!k) {
548
+ return 0 ;
549
+ }
550
+ if (k & 0x80 ) { // it's a capital letter or other character reached with shift
551
+ _keyReport.modifiers &= ~(0x02 ); // the left shift modifier
552
+ k &= 0x7F ;
553
+ }
554
+ }
555
+
556
+ // Test the key report to see if k is present. Clear it if it exists.
557
+ // Check all positions in case the key is present more than once (which it shouldn't be)
558
+ for (i=0 ; i<6 ; i++) {
559
+ if (0 != k && _keyReport.keys [i] == k) {
560
+ _keyReport.keys [i] = 0x00 ;
561
+ }
562
+ }
563
+
564
+ sendReport (&_keyReport);
565
+ return 1 ;
566
+ }
567
+
578
568
void Keyboard_::releaseAll (void )
579
569
{
580
570
_keyReport.keys [0 ] = 0 ;
@@ -587,17 +577,10 @@ void Keyboard_::releaseAll(void)
587
577
sendReport (&_keyReport);
588
578
}
589
579
590
- size_t Keyboard_::writeRaw (uint8_t c)
591
- {
592
- uint8_t p = pressRaw (c); // Keydown
593
- releaseRaw (c); // Keyup
594
- return (p); // just return the result of press() since release() almost always returns 1
595
- }
596
-
597
580
size_t Keyboard_::write (uint8_t c)
598
581
{
599
582
uint8_t p = press (c); // Keydown
600
- release (c); // Keyup
583
+ uint8_t r = release (c); // Keyup
601
584
return (p); // just return the result of press() since release() almost always returns 1
602
585
}
603
586
0 commit comments