From 1fd9cbedc5855e80edc6ee27dc49cf279ecfd265 Mon Sep 17 00:00:00 2001 From: hathach Date: Fri, 23 Feb 2018 18:53:18 +0700 Subject: [PATCH] add HID_KEYCODE_TO_ASCII decode --- .../src/services/BLEHidGeneric.cpp | 113 +++++++++++++++++- .../src/services/BLEHidGeneric.h | 16 ++- 2 files changed, 125 insertions(+), 4 deletions(-) diff --git a/libraries/Bluefruit52Lib/src/services/BLEHidGeneric.cpp b/libraries/Bluefruit52Lib/src/services/BLEHidGeneric.cpp index bff7cf8d..90e8631c 100644 --- a/libraries/Bluefruit52Lib/src/services/BLEHidGeneric.cpp +++ b/libraries/Bluefruit52Lib/src/services/BLEHidGeneric.cpp @@ -46,7 +46,7 @@ BLEHidGeneric::BLEHidGeneric(uint8_t num_input, uint8_t num_output, uint8_t num_ : BLEService(UUID16_SVC_HUMAN_INTERFACE_DEVICE), _chr_control(UUID16_CHR_HID_CONTROL_POINT) { _has_keyboard = _has_mouse = false; - _protocol_mode = 1; // report mode + _protocol_mode = HID_PROTOCOL_MODE_REPORT; _report_map = NULL; _report_map_len = 0; @@ -284,7 +284,7 @@ bool BLEHidGeneric::bootMouseReport(void const* data, int len) } /*------------------------------------------------------------------*/ -/* +/* Ascii to Keycode *------------------------------------------------------------------*/ const hid_ascii_to_keycode_entry_t HID_ASCII_TO_KEYCODE[128] = { @@ -421,3 +421,112 @@ const hid_ascii_to_keycode_entry_t HID_ASCII_TO_KEYCODE[128] = {0, HID_KEY_DELETE } // 0x7F Delete }; +/*------------------------------------------------------------------*/ +/* Keycode to Ascii + *------------------------------------------------------------------*/ +const hid_keycode_to_ascii_t HID_KEYCODE_TO_ASCII[128] = +{ + {0 , 0 }, // 0x00 + {0 , 0 }, // 0x01 + {0 , 0 }, // 0x02 + {0 , 0 }, // 0x03 + {'a' , 'A' }, // 0x04 + {'b' , 'B' }, // 0x05 + {'c' , 'C' }, // 0x06 + {'d' , 'D' }, // 0x07 + {'e' , 'E' }, // 0x08 + {'f' , 'F' }, // 0x09 + {'g' , 'G' }, // 0x0a + {'h' , 'H' }, // 0x0b + {'i' , 'I' }, // 0x0c + {'j' , 'J' }, // 0x0d + {'k' , 'K' }, // 0x0e + {'l' , 'L' }, // 0x0f + {'m' , 'M' }, // 0x10 + {'n' , 'N' }, // 0x11 + {'o' , 'O' }, // 0x12 + {'p' , 'P' }, // 0x13 + {'q' , 'Q' }, // 0x14 + {'r' , 'R' }, // 0x15 + {'s' , 'S' }, // 0x16 + {'t' , 'T' }, // 0x17 + {'u' , 'U' }, // 0x18 + {'v' , 'V' }, // 0x19 + {'w' , 'W' }, // 0x1a + {'x' , 'X' }, // 0x1b + {'y' , 'Y' }, // 0x1c + {'z' , 'Z' }, // 0x1d + {'1' , '!' }, // 0x1e + {'2' , '@' }, // 0x1f + {'3' , '#' }, // 0x20 + {'4' , '$' }, // 0x21 + {'5' , '%' }, // 0x22 + {'6' , '^' }, // 0x23 + {'7' , '&' }, // 0x24 + {'8' , '*' }, // 0x25 + {'9' , '(' }, // 0x26 + {'0' , ')' }, // 0x27 + {'\r' , '\r' }, // 0x28 + {'\x1b', '\x1b' }, // 0x29 + {'\b' , '\b' }, // 0x2a + {'\t' , '\t' }, // 0x2b + {' ' , ' ' }, // 0x2c + {'-' , '_' }, // 0x2d + {'=' , '+' }, // 0x2e + {'[' , '{' }, // 0x2f + {']' , '}' }, // 0x30 + {'\\' , '|' }, // 0x31 + {'#' , '~' }, // 0x32 + {';' , ':' }, // 0x33 + {'\'' , '\"' }, // 0x34 + {0 , 0 }, // 0x35 + {',' , '<' }, // 0x36 + {'.' , '>' }, // 0x37 + {'/' , '?' }, // 0x38 + + {0 , 0 }, // 0x39 + {0 , 0 }, // 0x3a + {0 , 0 }, // 0x3b + {0 , 0 }, // 0x3c + {0 , 0 }, // 0x3d + {0 , 0 }, // 0x3e + {0 , 0 }, // 0x3f + {0 , 0 }, // 0x40 + {0 , 0 }, // 0x41 + {0 , 0 }, // 0x42 + {0 , 0 }, // 0x43 + {0 , 0 }, // 0x44 + {0 , 0 }, // 0x45 + {0 , 0 }, // 0x46 + {0 , 0 }, // 0x47 + {0 , 0 }, // 0x48 + {0 , 0 }, // 0x49 + {0 , 0 }, // 0x4a + {0 , 0 }, // 0x4b + {0 , 0 }, // 0x4c + {0 , 0 }, // 0x4d + {0 , 0 }, // 0x4e + {0 , 0 }, // 0x4f + {0 , 0 }, // 0x50 + {0 , 0 }, // 0x51 + {0 , 0 }, // 0x52 + {0 , 0 }, // 0x53 + + {'/' , '/' }, // 0x54 + {'*' , '*' }, // 0x55 + {'-' , '-' }, // 0x56 + {'+' , '+' }, // 0x57 + {'\r' , '\r' }, // 0x58 + {'1' , 0 }, // 0x59 /* numpad1 & end */ \ + {'2' , 0 }, // 0x5a + {'3' , 0 }, // 0x5b + {'4' , 0 }, // 0x5c + {'5' , '5' }, // 0x5d + {'6' , 0 }, // 0x5e + {'7' , 0 }, // 0x5f + {'8' , 0 }, // 0x60 + {'9' , 0 }, // 0x61 + {'0' , 0 }, // 0x62 + {'0' , 0 }, // 0x63 + {'=' , '=' }, // 0x67 +}; diff --git a/libraries/Bluefruit52Lib/src/services/BLEHidGeneric.h b/libraries/Bluefruit52Lib/src/services/BLEHidGeneric.h index 0c899c0b..22e15390 100644 --- a/libraries/Bluefruit52Lib/src/services/BLEHidGeneric.h +++ b/libraries/Bluefruit52Lib/src/services/BLEHidGeneric.h @@ -41,12 +41,24 @@ #include "BLECharacteristic.h" #include "BLEService.h" +enum +{ + HID_PROTOCOL_MODE_BOOT = 0, + HID_PROTOCOL_MODE_REPORT = 1 +}; + typedef struct{ uint8_t shift; uint8_t keycode; }hid_ascii_to_keycode_entry_t; extern const hid_ascii_to_keycode_entry_t HID_ASCII_TO_KEYCODE[128]; +typedef struct{ + uint8_t ascii; + uint8_t shifted; +}hid_keycode_to_ascii_t; +extern hid_keycode_to_ascii_t const HID_KEYCODE_TO_ASCII[128]; + /// Standard HID Boot Protocol Mouse Report. typedef ATTR_PACKED_STRUCT(struct) { @@ -103,7 +115,7 @@ class BLEHidGeneric : public BLEService virtual err_t begin(void); - bool isBootMode(void) { return _protocol_mode == 0; } + bool isBootMode(void) { return _protocol_mode == HID_PROTOCOL_MODE_BOOT; } // Report bool inputReport(uint8_t reportID, void const* data, int len); @@ -117,7 +129,7 @@ class BLEHidGeneric : public BLEService bool _has_keyboard; bool _has_mouse; - bool _protocol_mode; // 0 boot, 1 report (default) + bool _protocol_mode; uint8_t _hid_info[4]; const uint8_t* _report_map;