ble nano hid over gatt
Dependencies: BLE_API mbed-dev nRF51822
Diff: keymap.h
- Revision:
- 5:65d4e94735b6
- Child:
- 6:f1c3ea8bc850
diff -r 54cb552e50c4 -r 65d4e94735b6 keymap.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/keymap.h Thu Jul 21 00:38:09 2016 +0900 @@ -0,0 +1,50 @@ +#include "keyboard.h" +#include "keyboard--short-names.h" + +static const uint8_t ROWS = 8; +static const uint8_t COLS = 16; + +// unimplemented in hardware is __ +#define __________ 0 +// unimplemented in firmware is _undef +#define _undef 0 + +static const uint8_t KEYMAP_DEFINITION[ROWS][COLS] = { + /*0*/{ _undef , _F1 , _F2 , _F3 , _F4 , _F5 , _F6 , __________ , __________ , _F7 , _F8 , _F9 , _F10 , _F11 , _F12 , _undef } , + /*1*/{ _esc , _1 , _2 , _3 , _4 , _5 , _6 , _7 , _6 , _7 , _8 , _9 , _0 , _dash , _equal , _backslash } , + /*2*/{ _tab , _Q , _W , _E , _R , _T , _Y , _T , __________ , _Y , _U , _I , _O , _P , _bracketL , _grave } , + /*3*/{ _ctrlL , _A , _S , _D , _F , _G , _H , _G , __________ , _H , _J , _K , _L , _semicolon , _quote , _bracketR } , + /*4*/{ _shiftL , _Z , _X , _C , _V , _B , _N , _B , __________ , _N , _M , _comma , _period , _slash , _shiftR , _bs } , + /*5*/{ _altL , _guiL , _space , __________ , __________ , _undef , __________ , __________ , __________ , __________ , _arrowU , _space , _guiR , _altR , _undef , _return } , + /*6*/{ __________ , __________ , __________ , __________ , __________ , __________ , __________ , __________ , __________ , _arrowL , _arrowD , _arrowR , __________ , __________ , __________ , __________ } , + /*7*/{ __________ , __________ , __________ , __________ , __________ , __________ , __________ , __________ , __________ , __________ , __________ , __________ , __________ , __________ , __________ , __________ } , +}; + +#undef __________ +#undef _undef + +class Keymap { + KeyboardService* keyboardService; + +public: + Keymap(KeyboardService* _keyboardService) : + keyboardService(_keyboardService) + { + } + + uint8_t mappingFor(int col, int row) const { + return KEYMAP_DEFINITION[row][col]; + } + + void execute(int col, int row, bool pressed) { + uint8_t key = KEYMAP_DEFINITION[row][col]; + if (key) { + if (pressed) { + keyboardService->appendReportData(key); + } else { + keyboardService->deleteReportData(key); + } + } + } +}; +