Skip to content

Commit 801bf13

Browse files
committed
rename hid to blehid to make it clearer (from usbhid)
1 parent 80297bb commit 801bf13

File tree

4 files changed

+29
-18
lines changed

4 files changed

+29
-18
lines changed

libraries/Bluefruit52Lib/examples/Peripheral/hid_keyscan/hid_keyscan.ino renamed to libraries/Bluefruit52Lib/examples/Peripheral/blehid_keyscan/blehid_keyscan.ino

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,43 @@
2222
BLEDis bledis;
2323
BLEHidAdafruit blehid;
2424

25+
// use on-board button if available
26+
#ifdef PIN_BUTTON1
27+
#define BTN1 PIN_BUTTON1
28+
#else
29+
#define BTN1 A0
30+
#endif
31+
32+
#ifdef PIN_BUTTON2
33+
#define BTN2 PIN_BUTTON2
34+
#else
35+
#define BTN2 A1
36+
#endif
37+
38+
// Circuit Play Bluefruit has button active state = high
39+
#ifdef ARDUINO_NRF52840_CIRCUITPLAY
40+
#define BTN_ACTIVE HIGH
41+
#else
42+
#define BTN_ACTIVE LOW
43+
#endif
44+
2545
// Array of pins and its keycode
26-
// For keycode definition see BLEHidGeneric.h
27-
uint8_t pins[] = { A0, A1, A2, A3, A4, A5 };
28-
uint8_t hidcode[] = { HID_KEY_A, HID_KEY_B, HID_KEY_C ,HID_KEY_D, HID_KEY_E, HID_KEY_F };
46+
// For keycode definition: https://github.com/hathach/tinyusb/blob/master/src/class/hid/hid.h
47+
uint8_t pins[] = { BTN1, BTN2 };
48+
uint8_t hidcode[] = { HID_KEY_KEYPAD_0, HID_KEY_KEYPAD_1 };
2949

3050
uint8_t pincount = sizeof(pins)/sizeof(pins[0]);
3151

32-
// Modifier keys, only take cares of Shift
33-
// ATL, CTRL, CMD keys are left for user excersie.
34-
uint8_t shiftPin = 11;
35-
3652
bool keyPressedPreviously = false;
3753

3854
void setup()
3955
{
4056
Serial.begin(115200);
41-
while ( !Serial ) delay(10); // for nrf52840 with native usb
57+
58+
#if CFG_DEBUG
59+
// Blocking wait for connection when debug mode is enabled via IDE
60+
while ( !Serial ) delay(10);
61+
#endif
4262

4363
Serial.println("Bluefruit52 HID Keyscan Example");
4464
Serial.println("-------------------------------\n");
@@ -66,9 +86,6 @@ void setup()
6686
pinMode(pins[i], INPUT_PULLUP);
6787
}
6888

69-
// set up modifier key
70-
pinMode(shiftPin, INPUT_PULLUP);
71-
7289
/* Start BLE HID
7390
* Note: Apple requires BLE device must have min connection interval >= 20m
7491
* ( The smaller the connection interval the faster we could send data).
@@ -128,16 +145,10 @@ void loop()
128145
uint8_t count=0;
129146
uint8_t keycode[6] = { 0 };
130147

131-
// scan modifier key (only SHIFT), user implement ATL, CTRL, CMD if needed
132-
if ( 0 == digitalRead(shiftPin) )
133-
{
134-
modifier |= KEYBOARD_MODIFIER_LEFTSHIFT;
135-
}
136-
137148
// scan normal key and send report
138149
for(uint8_t i=0; i < pincount; i++)
139150
{
140-
if ( 0 == digitalRead(pins[i]) )
151+
if ( BTN_ACTIVE == digitalRead(pins[i]) )
141152
{
142153
// if pin is active (low), add its hid code to key report
143154
keycode[count++] = hidcode[i];

0 commit comments

Comments
 (0)