include/keymap.h

Code:
  1. /*    
  2.     By Marcus   Xing   
  3.     include/keymap.h  
  4.     扫描码映射表定义  
  5. */      
  6.       
  7. #ifndef _KEYMAP_H_       
  8. #define _KEYMAP_H_     
  9.   
  10. /*  
  11.     forward include:  
  12.     type.h  
  13.     keyboard.h  
  14. */     
  15.       
  16. /* Keymap for US MF-2 keyboard. */      
  17.       
  18. u32 Key_Map[SCAN_CODES * MAP_COLS] = {       
  19.       
  20. /* scan-code            !Shift      Shift       E0 XX   */      
  21. /* ==================================================================== */      
  22. /* 0x00 - none      */  0,              0,          0,       
  23. /* 0x01 - ESC       */  ESC,        ESC,        0,       
  24. /* 0x02 - '1'       */  '1',        '!',        0,       
  25. /* 0x03 - '2'       */  '2',        '@',        0,       
  26. /* 0x04 - '3'       */  '3',        '#',        0,       
  27. /* 0x05 - '4'       */  '4',        '$',        0,       
  28. /* 0x06 - '5'       */  '5',        '%',        0,       
  29. /* 0x07 - '6'       */  '6',        '^',        0,       
  30. /* 0x08 - '7'       */  '7',        '&',        0,       
  31. /* 0x09 - '8'       */  '8',        '*',        0,       
  32. /* 0x0A - '9'       */  '9',        '(',        0,       
  33. /* 0x0B - '0'       */  '0',        ')',        0,       
  34. /* 0x0C - '-'       */  '-',        '_',        0,       
  35. /* 0x0D - '='       */  '=',        '+',        0,       
  36. /* 0x0E - BS        */  BACKSPACE,  BACKSPACE,  0,       
  37. /* 0x0F - TAB       */  TAB,        TAB,        0,       
  38. /* 0x10 - 'q'       */  'q',        'Q',        0,       
  39. /* 0x11 - 'w'       */  'w',        'W',        0,       
  40. /* 0x12 - 'e'       */  'e',        'E',        0,       
  41. /* 0x13 - 'r'       */  'r',        'R',        0,       
  42. /* 0x14 - 't'       */  't',        'T',        0,       
  43. /* 0x15 - 'y'       */  'y',        'Y',        0,       
  44. /* 0x16 - 'u'       */  'u',        'U',        0,       
  45. /* 0x17 - 'i'       */  'i',        'I',        0,       
  46. /* 0x18 - 'o'       */  'o',        'O',        0,       
  47. /* 0x19 - 'p'       */  'p',        'P',        0,       
  48. /* 0x1A - '['       */  '[',        '{',        0,       
  49. /* 0x1B - ']'       */  ']',        '}',        0,       
  50. /* 0x1C - CR/LF     */  ENTER,      ENTER,      PAD_ENTER,       
  51. /* 0x1D - l. Ctrl   */  CTRL_L,     CTRL_L,     CTRL_R,       
  52. /* 0x1E - 'a'       */  'a',        'A',        0,       
  53. /* 0x1F - 's'       */  's',        'S',        0,       
  54. /* 0x20 - 'd'       */  'd',        'D',        0,       
  55. /* 0x21 - 'f'       */  'f',        'F',        0,       
  56. /* 0x22 - 'g'       */  'g',        'G',        0,       
  57. /* 0x23 - 'h'       */  'h',        'H',        0,       
  58. /* 0x24 - 'j'       */  'j',        'J',        0,       
  59. /* 0x25 - 'k'       */  'k',        'K',        0,       
  60. /* 0x26 - 'l'       */  'l',        'L',        0,       
  61. /* 0x27 - ';'       */  ';',        ':',        0,       
  62. /* 0x28 - '/''      */  '/'',       '"',        0,       
  63. /* 0x29 - '`'       */  '`',        '~',        0,       
  64. /* 0x2A - l. SHIFT  */  SHIFT_L,    SHIFT_L,    0,       
  65. /* 0x2B - '/'       */  '//',       '|',        0,       
  66. /* 0x2C - 'z'       */  'z',        'Z',        0,       
  67. /* 0x2D - 'x'       */  'x',        'X',        0,       
  68. /* 0x2E - 'c'       */  'c',        'C',        0,       
  69. /* 0x2F - 'v'       */  'v',        'V',        0,       
  70. /* 0x30 - 'b'       */  'b',        'B',        0,       
  71. /* 0x31 - 'n'       */  'n',        'N',        0,       
  72. /* 0x32 - 'm'       */  'm',        'M',        0,       
  73. /* 0x33 - ','       */  ',',        '<',        0,       
  74. /* 0x34 - '.'       */  '.',        '>',        0,       
  75. /* 0x35 - '/'       */  '/',        '?',        PAD_SLASH,       
  76. /* 0x36 - r. SHIFT  */  SHIFT_R,    SHIFT_R,    0,       
  77. /* 0x37 - '*'       */  '*',        '*',        0,       
  78. /* 0x38 - ALT       */  ALT_L,      ALT_L,      ALT_R,       
  79. /* 0x39 - ' '       */  ' ',        ' ',        0,       
  80. /* 0x3A - CapsLock  */  CAPS_LOCK,  CAPS_LOCK,  0,       
  81. /* 0x3B - F1        */  F1,         F1,         0,       
  82. /* 0x3C - F2        */  F2,         F2,         0,       
  83. /* 0x3D - F3        */  F3,         F3,         0,       
  84. /* 0x3E - F4        */  F4,         F4,         0,       
  85. /* 0x3F - F5        */  F5,         F5,         0,       
  86. /* 0x40 - F6        */  F6,         F6,         0,       
  87. /* 0x41 - F7        */  F7,         F7,         0,       
  88. /* 0x42 - F8        */  F8,         F8,         0,       
  89. /* 0x43 - F9        */  F9,         F9,         0,       
  90. /* 0x44 - F10       */  F10,        F10,        0,       
  91. /* 0x45 - NumLock   */  NUM_LOCK,   NUM_LOCK,   0,       
  92. /* 0x46 - ScrLock   */  SCROLL_LOCK,SCROLL_LOCK,0,       
  93. /* 0x47 - Home      */  PAD_HOME,   '7',        HOME,       
  94. /* 0x48 - CurUp     */  PAD_UP,     '8',        UP,       
  95. /* 0x49 - PgUp      */  PAD_PAGEUP, '9',        PAGEUP,       
  96. /* 0x4A - '-'       */  PAD_MINUS,  '-',        0,       
  97. /* 0x4B - Left      */  PAD_LEFT,   '4',        LEFT,       
  98. /* 0x4C - MID       */  PAD_MID,    '5',        0,       
  99. /* 0x4D - Right     */  PAD_RIGHT,  '6',        RIGHT,       
  100. /* 0x4E - '+'       */  PAD_PLUS,   '+',        0,       
  101. /* 0x4F - End       */  PAD_END,    '1',        END,       
  102. /* 0x50 - Down      */  PAD_DOWN,   '2',        DOWN,       
  103. /* 0x51 - PgDown    */  PAD_PAGEDOWN,'3',       PAGEDOWN,       
  104. /* 0x52 - Insert    */  PAD_INS,    '0',        INSERT,       
  105. /* 0x53 - Delete    */  PAD_DOT,    '.',        DELETE,       
  106. /* 0x54 - Enter     */  0,           0,         0,       
  107. /* 0x55 - ???       */  0,           0,         0,       
  108. /* 0x56 - ???       */  0,           0,         0,       
  109. /* 0x57 - F11       */  F11,        F11,        0,         
  110. /* 0x58 - F12       */  F12,        F12,        0,         
  111. /* 0x59 - ???       */  0,           0,         0,         
  112. /* 0x5A - ???       */  0,           0,         0,         
  113. /* 0x5B - ???       */  0,           0,         GUI_L,         
  114. /* 0x5C - ???       */  0,           0,         GUI_R,         
  115. /* 0x5D - ???       */  0,           0,         APPS,          
  116. /* 0x5E - 'POWER'   */  POWER,       POWER,     POWER,         
  117. /* 0x5F - 'SLEEP'   */  SLEEP,       SLEEP,     SLEEP,       
  118. /* 0x60 - ???       */  0,           0,         0,       
  119. /* 0x61 - ???       */  0,           0,         0,         
  120. /* 0x62 - ???       */  0,           0,         0,         
  121. /* 0x63 - WAKE      */  WAKE,        WAKE,      WAKE,         
  122. /* 0x64 - ???       */  0,           0,         0,         
  123. /* 0x65 - ???       */  0,           0,         0,         
  124. /* 0x66 - ???       */  0,           0,         0,         
  125. /* 0x67 - ???       */  0,           0,         0,         
  126. /* 0x68 - ???       */  0,           0,         0,         
  127. /* 0x69 - ???       */  0,           0,         0,         
  128. /* 0x6A - ???       */  0,           0,         0,         
  129. /* 0x6B - ???       */  0,           0,         0,         
  130. /* 0x6C - ???       */  0,           0,         0,         
  131. /* 0x6D - ???       */  0,           0,         0,         
  132. /* 0x6E - ???       */  0,           0,         0,         
  133. /* 0x6F - ???       */  0,           0,         0,         
  134. /* 0x70 - ???       */  0,           0,         0,         
  135. /* 0x71 - ???       */  0,           0,         0,         
  136. /* 0x72 - ???       */  0,           0,         0,         
  137. /* 0x73 - ???       */  0,           0,         0,         
  138. /* 0x74 - ???       */  0,           0,         0,         
  139. /* 0x75 - ???       */  0,           0,         0,         
  140. /* 0x76 - ???       */  0,           0,         0,         
  141. /* 0x77 - ???       */  0,           0,         0,         
  142. /* 0x78 - ???       */  0,           0,         0,         
  143. /* 0x78 - ???       */  0,           0,         0,         
  144. /* 0x7A - ???       */  0,           0,         0,         
  145. /* 0x7B - ???       */  0,           0,         0,         
  146. /* 0x7C - ???       */  0,           0,         0,         
  147. /* 0x7D - ???       */  0,           0,         0,         
  148. /* 0x7E - ???       */  0,           0,         0,       
  149. /* 0x7F - ???       */  0,           0,         0       
  150. };       
  151.       
  152. #endif      

 

// 答题框内的代码仅为待实现代码,执行或提交代码时,仅包含待实现部分,不要包含其它代码。 // CodeCheck/Cmetrics工具也仅扫描待实现部分。 // 若需要完整框架用于本地调试,请点击答题框上面的“下载完整框架代码”进行下载。 #include <string> #include <vector> #include <map> using namespace std; struct Compare { bool operator()(const pair<int, vector<int>>& p1, const pair<int, vector<int>>& p2) const{ if ( p1.first != p2.first) { return p1.first < p2.first; } else { for (int i = 0 ; i < p1.second.size(); ++i) { if ((p1.second)[i] != (p2.second)[i]) return (p1.second)[i] < (p2.second)[i]; } } return false; } }; class MiniDb { private: map<int, pair<int, string>> keyMap; map<pair<int, vector<int>>, vector<int>, Compare> dataMap; public: MiniDb() { } void Create(int tableId, int colNum, const string& keys) { //pair<int, string> p = {colNum, keys}; //keyMap.insert(tableId, p); } void Insert(int tableId, const vector<int>& values) { auto it = keyMap.find(tableId); if (it != keyMap.end()) { vector<int> mark; for (int i = 0; i < ((it->second).second).size(); ++i) { mark.emplace_back(values[((it->second).second)[i] - 'a']); } pair<int, vector<int>> p = {tableId, mark}; dataMap[p] = values; } } vector<vector<int>> Select(int tableId, const vector<string>& conditions) { vector<vector<int>> result; for (auto it = dataMap.begin(); it != dataMap.end(); ++it) { if (it->first.first == tableId) { result.emplace_back(it->second); } } int num = result.size(); for (int i = 0; i < conditions.size(); ++i) { int key = conditions[i] - 'a'; int value = std::stoi(conditions[i].substr(2, conditions[i].size() - 2)); int mark = 0; for (int i = 0; i < num; ++i) { if (result[i][key] == value) { result[mark] == result[i]; mark++; } } num = mark; } vector<vector<int>> resultLast; for (int i = 0; i < num; ++i) { resultLast[i] = result[i]; } return resultLast; } }; 运行时报错main.cpp: In member function 'std::vector<std::vector<int> > MiniDb::Select(int, const std::vector<std::__cxx11::basic_string<char> >&)': main.cpp:75:37: error: no match for 'operator-' (operand types are 'const value_type' {aka 'const std::__cxx11::basic_string<char>'} and 'char') int key = conditions[i] - 'a'; In file included from /usr/include/c++/8/bits/stl_algobase.h:67, from /usr/include/c++/8/bits/char_traits.h:39, from /usr/include/c++/8/ios:40, from main.cpp:6: /usr/include/c++/8/bits/stl_iterator.h:392:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr decltype ((__y.base() - __x.base())) std::operator-(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_IteratorR>&)' operator-(const reverse_iterator<_IteratorL>& __x, ^~~~~~~~ /usr/include/c++/8/bits/stl_iterator.h:392:5: note: template argument deduction/substitution failed: main.cpp:75:39: note: 'const value_type' {aka 'const std::__cxx11::basic_string<char>'} is not derived from 'const std::reverse_iterator<_Iterator>' int key = conditions[i] - 'a'; ^~~ In file included from /usr/include/c++/8/bits/stl_algobase.h:67, from /usr/include/c++/8/bits/char_traits.h:39, from /usr/include/c++/8/ios:40, from main.cpp:6: /usr/include/c++/8/bits/stl_iterator.h:1188:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr decltype ((__x.base() - __y.base())) std::operator-(const std::move_iterator<_IteratorL>&, const std::move_iterator<_IteratorR>&)' operator-(const move_iterator<_IteratorL>& __x, ^~~~~~~~ /usr/include/c++/8/bits/stl_iterator.h:1188:5: note: template argument deduction/substitution failed: main.cpp:75:39: note: 'const value_type' {aka 'const std::__cxx11::basic_string<char>'} is not derived from 'const std::move_iterator<_IteratorL>' int key = conditions[i] - 'a'; ^~~ In file included from /usr/include/c++/8/vector:65, from main.cpp:19: /usr/include/c++/8/bits/stl_bvector.h:210:3: note: candidate: 'std::ptrdiff_t std::operator-(const std::_Bit_iterator_base&, const std::_Bit_iterator_base&)' operator-(const _Bit_iterator_base& __x, const _Bit_iterator_base& __y) ^~~~~~~~ /usr/include/c++/8/bits/stl_bvector.h:210:3: note: no known conversion for argument 1 from 'const value_type' {aka 'const std::__cxx11::basic_string<char>'} to 'const std::_Bit_iterator_base&' In file included from /usr/include/c++/8/bits/stl_algobase.h:67, from /usr/include/c++/8/bits/char_traits.h:39, from /usr/include/c++/8/ios:40, from main.cpp:6: /usr/include/c++/8/bits/stl_iterator.h:954:5: note: candidate: 'template<class _IteratorL, class _IteratorR, class _Container> decltype ((__lhs.base() - __rhs.base())) __gnu_cxx::operator-(const __gnu_cxx::__normal_iterator<_IteratorL, _Container>&, const __gnu_cxx::__normal_iterator<_IteratorR, _Container>&)' operator-(const __normal_iterator<_IteratorL, _Container>& __lhs, ^~~~~~~~ /usr/include/c++/8/bits/stl_iterator.h:954:5: note: template argument deduction/substitution failed: main.cpp:75:39: note: 'const value_type' {aka 'const std::__cxx11::basic_string<char>'} is not derived from 'const __gnu_cxx::__normal_iterator<_IteratorL, _Container>' int key = conditions[i] - 'a'; ^~~ In file included from /usr/include/c++/8/bits/stl_algobase.h:67, from /usr/include/c++/8/bits/char_traits.h:39, from /usr/include/c++/8/ios:40, from main.cpp:6: /usr/include/c++/8/bits/stl_iterator.h:966:5: note: candidate: 'template<class _Iterator, class _Container> typename __gnu_cxx::__normal_iterator<_Iterator, _Container>::difference_type __gnu_cxx::operator-(const __gnu_cxx::__normal_iterator<_Iterator, _Container>&, const __gnu_cxx::__normal_iterator<_Iterator, _Container>&)' operator-(const __normal_iterator<_Iterator, _Container>& __lhs, ^~~~~~~~ /usr/include/c++/8/bits/stl_iterator.h:966:5: note: template argument deduction/substitution failed: main.cpp:75:39: note: 'const value_type' {aka 'const std::__cxx11::basic_string<char>'} is not derived from 'const __gnu_cxx::__normal_iterator<_Iterator, _Container>' int key = conditions[i] - 'a'; ^~~
06-04
/* * Shows how to use a 4 x 4 keypad, commonly seen in Arduino starter kits, with the library * https://www.aliexpress.com/w/wholesale-Arduino-4*4-Matrix-Keyboard.html * It maps the 16 buttons to the first 16 buttons of the controller * Only certain combinations work for multiple presses over 2 buttons */ #include <Arduino.h> #include <Keypad.h> // https://github.com/Chris--A/Keypad #include <BleGamepad.h> // https://github.com/lemmingDev/ESP32-BLE-Gamepad BleGamepad bleGamepad("ESP32 Keypad", "lemmingDev", 100); // Shows how you can customise the device name, manufacturer name and initial battery level #define ROWS 4 #define COLS 4 uint8_t rowPins[ROWS] = {2, 13, 14, 25}; // ESP32 pins used for rows --> adjust to suit --> Pinout on board: R1, R2, R3, R4 uint8_t colPins[COLS] = {4, 23, 21, 22}; // ESP32 pins used for columns --> adjust to suit --> Pinout on board: Q1, Q2, Q3, Q4 uint8_t keymap[ROWS][COLS] = { {1, 2, 3, 4}, // Buttons 1, 2, 3, 4 --> Used for calulating the bitmask for sending to the library {5, 6, 7, 8}, // Buttons 5, 6, 7, 8 --> Adjust to suit which buttons you want the library to send {9, 10, 11, 12}, // Buttons 9, 10, 11, 12 --> {13, 14, 15, 16} // Buttons 13, 14, 15, 16 --> Eg. The value 12 in the array refers to button 12 }; Keypad customKeypad = Keypad(makeKeymap(keymap), rowPins, colPins, ROWS, COLS); void setup() { BleGamepadConfiguration bleGamepadConfig; bleGamepadConfig.setAutoReport(false); // Disable auto reports --> You then need to force HID updates with bleGamepad.sendReport() bleGamepad.begin(&bleGamepadConfig); // Begin library with set values // changing bleGamepadConfig after the begin function has no effect, unless you call the begin function again } void loop() { KeypadUpdate(); delay(10); } void KeypadUpdate() { customKeypad.getKeys(); for (int i = 0; i < LIST_MAX; i++) // Scan the whole key list. //LIST_MAX is provided by the Keypad library and gives the number of buttons of the Keypad instance { if (customKeypad.key[i].stateChanged) // Only find keys that have changed state. { uint8_t keystate = customKeypad.key[i].kstate; if (bleGamepad.isConnected()) { if (keystate == PRESSED) { bleGamepad.press(customKeypad.key[i].kchar); } // Press or release button based on the current state if (keystate == RELEASED) { bleGamepad.release(customKeypad.key[i].kchar); } bleGamepad.sendReport(); // Send the HID report after values for all button states are updated, and at least one button state had changed } } } }
06-09
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值