Skip to content

Commit 5666b15

Browse files
committed
rename keyboardPress() keyboardRelease()
1 parent 17f3704 commit 5666b15

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

examples/hid_composite/hid_composite.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ void loop()
111111
}else
112112
{
113113
// send empty key report if previously has key pressed
114-
if (has_key) usb_hid.keyboardKeyRelease(RID_KEYBOARD);
114+
if (has_key) usb_hid.keyboardRelease(RID_KEYBOARD);
115115
has_key = false;
116116
}
117117
}

src/Adafruit_USBD_HID.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,15 @@
2424

2525
#include "Adafruit_USBD_HID.h"
2626

27+
28+
//--------------------------------------------------------------------+
29+
//
30+
//--------------------------------------------------------------------+
2731
#define EPOUT 0x00
2832
#define EPIN 0x80
2933

34+
uint8_t const _ascii2keycode[128][2] = { HID_ASCII_TO_KEYCODE };
35+
3036
//------------- IMPLEMENTATION -------------//
3137
Adafruit_USBD_HID::Adafruit_USBD_HID(void)
3238
{
@@ -97,7 +103,17 @@ bool Adafruit_USBD_HID::keyboadReport(uint8_t report_id, uint8_t modifier, uint8
97103
return tud_hid_keyboard_report(report_id, modifier, keycode);
98104
}
99105

100-
bool Adafruit_USBD_HID::keyboardKeyRelease(uint8_t report_id)
106+
bool Adafruit_USBD_HID::keyboardPress(uint8_t report_id, char ch)
107+
{
108+
uint8_t keycode[6] = { 0 };
109+
uint8_t modifier = 0;
110+
111+
if ( _ascii2keycode[ch][0] ) modifier = KEYBOARD_MODIFIER_LEFTSHIFT;
112+
keycode[0] = _ascii2keycode[ch][1];
113+
tud_hid_keyboard_report(report_id, modifier, keycode);
114+
}
115+
116+
bool Adafruit_USBD_HID::keyboardRelease(uint8_t report_id)
101117
{
102118
return tud_hid_keyboard_key_release(report_id);
103119
}

src/Adafruit_USBD_HID.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ class Adafruit_USBD_HID : Adafruit_USBD_Interface
4747

4848
//------------- Keyboard API -------------//
4949
bool keyboadReport(uint8_t report_id, uint8_t modifier, uint8_t keycode[6]);
50-
bool keyboardKeyPress(uint8_t report_id, char ch);
51-
bool keyboardKeyRelease(uint8_t report_id);
50+
bool keyboardPress(uint8_t report_id, char ch);
51+
bool keyboardRelease(uint8_t report_id);
5252

5353
//------------- Mouse API -------------//
5454
bool mouseReport(uint8_t report_id, uint8_t buttons, int8_t x, int8_t y, int8_t scroll, int8_t pan);

0 commit comments

Comments
 (0)