ble nano hid over gatt

Dependencies:   BLE_API mbed-dev nRF51822

test_keymap.txt

Committer:
cho45
Date:
2016-08-31
Revision:
60:b899414e1d34
Parent:
47:5bf2ae8cc710

File content as of revision 60:b899414e1d34:

//#!clang++ -O2 -std=c++1y test_keymap.txt -o /tmp/a.out && /tmp/a.out ; ;:

#include <stdio.h>
#include <stdint.h>
#include <iostream>
static unsigned tap_n = 0;
template <class T, class U>
void is(T got, U expected, const char* desc = "") {
    if (tap_n++ == 0) {
        std::atexit([]{
            std::cout << "1.." << tap_n << std::endl;
        });
    }

    if (got == expected) {
        std::cout << "ok " << tap_n;
        if (desc[0]) std::cout << " - " << desc;
        std::cout << std::endl;
    } else {
        std::cout << "not ok " << tap_n;
        if (desc[0]) std::cout << " - " << desc;
        std::cout << std::endl;
        std::cout << "# got:" << got << " expected:" << expected << std::endl;
    }
}

static uint8_t lastAppendKey;
static uint8_t lastDeleteKey;
class HIDController {
public:
    static void appendReportData(uint8_t key) {
        lastAppendKey = key;
    }

    static void deleteReportData(uint8_t key) {
        lastDeleteKey = key;
    }
};

#define DEBUG_PRINTF_KEYEVENT(...) printf(__VA_ARGS__)

#include "keymap.h"

int main() {
    printf("test\n");

    Keymap keymap = new Keymap();

    keymap->execute(1, 1, true);
    is(lastAppendKey, _1);
    keymap->execute(1, 1, false);
    is(lastDeleteKey, _1);
    keymap->execute(1, 0, true);
    is(lastAppendKey, _esc);

    keymap->execute(2, 14, true);
    is((int)lastAppendKey, _bracketL);
    keymap->execute(2, 14, false);

    // Fn
    keymap->execute(5, 14, true);
    keymap->execute(2, 14, true);
    is((int)lastAppendKey, _arrowU);
    // 先に Fn を離す
    keymap->execute(5, 14, false);
    keymap->execute(2, 14, false);
    is((int)lastDeleteKey, _arrowU);

    return 0;
}


// レイヤーの仕様
//
// 切替えキー (例: Fn) はそのあと押したキーにしか効かない
// 切替えキーが途中で離されても、押されたキーが離されるまでそのまま
//