ble nano hid over gatt
Dependencies: BLE_API mbed-dev nRF51822
test_keymap.txt@60:b899414e1d34, 2016-08-31 (annotated)
- Committer:
- cho45
- Date:
- Wed Aug 31 13:44:47 2016 +0000
- Revision:
- 60:b899414e1d34
- Parent:
- 47:5bf2ae8cc710
??????????
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
cho45 | 47:5bf2ae8cc710 | 1 | //#!clang++ -O2 -std=c++1y test_keymap.txt -o /tmp/a.out && /tmp/a.out ; ;: |
cho45 | 47:5bf2ae8cc710 | 2 | |
cho45 | 47:5bf2ae8cc710 | 3 | #include <stdio.h> |
cho45 | 47:5bf2ae8cc710 | 4 | #include <stdint.h> |
cho45 | 47:5bf2ae8cc710 | 5 | #include <iostream> |
cho45 | 47:5bf2ae8cc710 | 6 | static unsigned tap_n = 0; |
cho45 | 47:5bf2ae8cc710 | 7 | template <class T, class U> |
cho45 | 47:5bf2ae8cc710 | 8 | void is(T got, U expected, const char* desc = "") { |
cho45 | 47:5bf2ae8cc710 | 9 | if (tap_n++ == 0) { |
cho45 | 47:5bf2ae8cc710 | 10 | std::atexit([]{ |
cho45 | 47:5bf2ae8cc710 | 11 | std::cout << "1.." << tap_n << std::endl; |
cho45 | 47:5bf2ae8cc710 | 12 | }); |
cho45 | 47:5bf2ae8cc710 | 13 | } |
cho45 | 47:5bf2ae8cc710 | 14 | |
cho45 | 47:5bf2ae8cc710 | 15 | if (got == expected) { |
cho45 | 47:5bf2ae8cc710 | 16 | std::cout << "ok " << tap_n; |
cho45 | 47:5bf2ae8cc710 | 17 | if (desc[0]) std::cout << " - " << desc; |
cho45 | 47:5bf2ae8cc710 | 18 | std::cout << std::endl; |
cho45 | 47:5bf2ae8cc710 | 19 | } else { |
cho45 | 47:5bf2ae8cc710 | 20 | std::cout << "not ok " << tap_n; |
cho45 | 47:5bf2ae8cc710 | 21 | if (desc[0]) std::cout << " - " << desc; |
cho45 | 47:5bf2ae8cc710 | 22 | std::cout << std::endl; |
cho45 | 47:5bf2ae8cc710 | 23 | std::cout << "# got:" << got << " expected:" << expected << std::endl; |
cho45 | 47:5bf2ae8cc710 | 24 | } |
cho45 | 47:5bf2ae8cc710 | 25 | } |
cho45 | 47:5bf2ae8cc710 | 26 | |
cho45 | 47:5bf2ae8cc710 | 27 | static uint8_t lastAppendKey; |
cho45 | 47:5bf2ae8cc710 | 28 | static uint8_t lastDeleteKey; |
cho45 | 47:5bf2ae8cc710 | 29 | class HIDController { |
cho45 | 47:5bf2ae8cc710 | 30 | public: |
cho45 | 47:5bf2ae8cc710 | 31 | static void appendReportData(uint8_t key) { |
cho45 | 47:5bf2ae8cc710 | 32 | lastAppendKey = key; |
cho45 | 47:5bf2ae8cc710 | 33 | } |
cho45 | 47:5bf2ae8cc710 | 34 | |
cho45 | 47:5bf2ae8cc710 | 35 | static void deleteReportData(uint8_t key) { |
cho45 | 47:5bf2ae8cc710 | 36 | lastDeleteKey = key; |
cho45 | 47:5bf2ae8cc710 | 37 | } |
cho45 | 47:5bf2ae8cc710 | 38 | }; |
cho45 | 47:5bf2ae8cc710 | 39 | |
cho45 | 47:5bf2ae8cc710 | 40 | #define DEBUG_PRINTF_KEYEVENT(...) printf(__VA_ARGS__) |
cho45 | 47:5bf2ae8cc710 | 41 | |
cho45 | 47:5bf2ae8cc710 | 42 | #include "keymap.h" |
cho45 | 47:5bf2ae8cc710 | 43 | |
cho45 | 47:5bf2ae8cc710 | 44 | int main() { |
cho45 | 47:5bf2ae8cc710 | 45 | printf("test\n"); |
cho45 | 47:5bf2ae8cc710 | 46 | |
cho45 | 47:5bf2ae8cc710 | 47 | Keymap keymap = new Keymap(); |
cho45 | 47:5bf2ae8cc710 | 48 | |
cho45 | 47:5bf2ae8cc710 | 49 | keymap->execute(1, 1, true); |
cho45 | 47:5bf2ae8cc710 | 50 | is(lastAppendKey, _1); |
cho45 | 47:5bf2ae8cc710 | 51 | keymap->execute(1, 1, false); |
cho45 | 47:5bf2ae8cc710 | 52 | is(lastDeleteKey, _1); |
cho45 | 47:5bf2ae8cc710 | 53 | keymap->execute(1, 0, true); |
cho45 | 47:5bf2ae8cc710 | 54 | is(lastAppendKey, _esc); |
cho45 | 47:5bf2ae8cc710 | 55 | |
cho45 | 47:5bf2ae8cc710 | 56 | keymap->execute(2, 14, true); |
cho45 | 47:5bf2ae8cc710 | 57 | is((int)lastAppendKey, _bracketL); |
cho45 | 47:5bf2ae8cc710 | 58 | keymap->execute(2, 14, false); |
cho45 | 47:5bf2ae8cc710 | 59 | |
cho45 | 47:5bf2ae8cc710 | 60 | // Fn |
cho45 | 47:5bf2ae8cc710 | 61 | keymap->execute(5, 14, true); |
cho45 | 47:5bf2ae8cc710 | 62 | keymap->execute(2, 14, true); |
cho45 | 47:5bf2ae8cc710 | 63 | is((int)lastAppendKey, _arrowU); |
cho45 | 47:5bf2ae8cc710 | 64 | // 先に Fn を離す |
cho45 | 47:5bf2ae8cc710 | 65 | keymap->execute(5, 14, false); |
cho45 | 47:5bf2ae8cc710 | 66 | keymap->execute(2, 14, false); |
cho45 | 47:5bf2ae8cc710 | 67 | is((int)lastDeleteKey, _arrowU); |
cho45 | 47:5bf2ae8cc710 | 68 | |
cho45 | 47:5bf2ae8cc710 | 69 | return 0; |
cho45 | 47:5bf2ae8cc710 | 70 | } |
cho45 | 47:5bf2ae8cc710 | 71 | |
cho45 | 47:5bf2ae8cc710 | 72 | |
cho45 | 47:5bf2ae8cc710 | 73 | // レイヤーの仕様 |
cho45 | 47:5bf2ae8cc710 | 74 | // |
cho45 | 47:5bf2ae8cc710 | 75 | // 切替えキー (例: Fn) はそのあと押したキーにしか効かない |
cho45 | 47:5bf2ae8cc710 | 76 | // 切替えキーが途中で離されても、押されたキーが離されるまでそのまま |
cho45 | 47:5bf2ae8cc710 | 77 | // |