acid-drop- Hacking the planet from a LilyGo T-Deck using custom firmware |
git clone git://git.acid.vegas/acid-drop.git |
Log | Files | Refs | Archive | README | LICENSE |
keyboard.h (1851B)
1 /******************************************************************************* 2 * Keyboard libraries: 3 * M5Stack CardKB: no extra libraries required 4 https://github.com/solderparty/arduino_bbq10kbd 5 ******************************************************************************/ 6 7 /* uncomment for M5Stack CardKB */ 8 // #define KEYBOARD_CARDKB 9 // #define KEYBOARD_CARDKB_SDA 19 10 // #define KEYBOARD_CARDKB_SCL 20 11 // #define KEYBOARD_CARDKB_I2C_ADDR 0x5f 12 13 /* uncomment for BBQKeyboard */ 14 // #define KEYBOARD_BBQKB 15 // #define KEYBOARD_BBQKB_SDA 21 16 // #define KEYBOARD_BBQKB_SCL 22 17 18 #if defined(KEYBOARD_CARDKB) 19 #include <Wire.h> 20 #elif defined(KEYBOARD_BBQKB) 21 #include <Wire.h> 22 #include <BBQ10Keyboard.h> 23 BBQ10Keyboard keyboard; 24 #endif 25 26 void keyboard_init() { 27 #if defined(KEYBOARD_CARDKB) 28 Wire1.begin(KEYBOARD_CARDKB_SDA, KEYBOARD_CARDKB_SCL); 29 #elif defined(KEYBOARD_BBQKB) 30 Wire1.begin(KEYBOARD_BBQKB_SDA, KEYBOARD_BBQKB_SCL); 31 keyboard.begin(); 32 keyboard.setBacklight(0.5f); 33 #endif 34 } 35 36 char keyboard_get_key() { 37 #if defined(KEYBOARD_CARDKB) 38 uint8_t bytesReceived = Wire1.requestFrom(KEYBOARD_CARDKB_I2C_ADDR, 1); 39 if ((bool)bytesReceived) { //If received more than zero bytes 40 return Wire1.read(); 41 } else { 42 return 0; 43 } 44 #elif defined(KEYBOARD_BBQKB) 45 const int keyCount = keyboard.keyCount(); 46 if (keyCount > 0) { 47 const BBQ10Keyboard::KeyEvent key = keyboard.keyEvent(); 48 String state = "pressed"; 49 if (key.state == BBQ10Keyboard::StateLongPress) 50 state = "held down"; 51 else if (key.state == BBQ10Keyboard::StateRelease) 52 state = "released"; 53 54 Serial.printf("key: '%c' (dec %d, hex %02x) %s\r\n", key.key, key.key, key.key, state.c_str()); 55 56 if ((key.key != 0) && (key.state != BBQ10Keyboard::StateRelease)) { 57 return key.key; 58 } else { 59 return 0; 60 } 61 } else { 62 return 0; 63 } 64 #endif 65 }