#include <stdio.h>
#include "key.h"
#include "log.h"
#include "t_key.h"
#include <windows.h>
#include <process.h>
#include "sim_key.h"

uint8_t Key_Pin(uint8_t l) {
    if (SIM_Key_Scan() == SIM_KEY_UP) {
//        LOGT("SCAN","ID:%d-UP",l);
        return 1;
    } else return 0;
}
void Key_Call(Key_t *key) {
    switch (key->event) {
        case KEY_PRESS_DOWN:
            LOGT("KEY", "ID:%d EVENT:%s", key->key_id, "PressTheEvent");
            break;// 按下事件
        case KEY_PRESS_UP:
            LOGT("KEY", "ID:%d EVENT:%s", key->key_id, "BounceIncident");
            break;// 弹起事件
        case KEY_PRESS_REPEAT:
            LOGT("KEY", "ID:%d EVENT:%s", key->key_id, "RepeatThePressEvent");
            break;// 重复按下事件
        case KEY_SINGLE_CLICK:
            LOGT("KEY", "ID:%d EVENT:%s", key->key_id, "ClickEvent");
            break;// 单击事件
        case KEY_DOUBLE_CLICK:
            LOGT("KEY", "ID:%d EVENT:%s", key->key_id, "DoubleClickTheEvent");
            break;// 双击事件
        case KEY_LONG_PRESS_START:
            LOGT("KEY", "ID:%d EVENT:%s", key->key_id, "LongPressToStartTheEvent");
            break;// 长按开始事件
        case KEY_LONG_PRESS_HOLD:
            LOGT("KEY", "ID:%d EVENT:%s", key->key_id, "LongPressToHoldTheEvent");
            break;// 长按保持事件
    }
}

int Test_Key(void *pVoid) {
    Key_t k1, k2, k3, k4, k5, k6, ks;
    key_init(&k1, SIM_KEY_UP, 1, SIM_Key_UP);
    key_init(&k2, SIM_KEY_DOWN, 1, SIM_Key_DOWN);
    key_init(&k3, SIM_KEY_LEFT, 1, SIM_Key_LEFT);
    key_init(&k4, SIM_KEY_RIGHT, 1, SIM_Key_RIGHT);
    key_init(&k5, SIM_KEY_ENABLE, 1, SIM_Key_ENABLE);
    key_init(&k6, SIM_KEY_SET, 1, SIM_Key_SET);
//    key_init(&ks,Key_Pin,1,7);

    key_attach(&k1, KEY_ALL_EVENT, Key_Call, true);
    key_attach(&k2, KEY_ALL_EVENT, Key_Call, true);
    key_attach(&k3, KEY_ALL_EVENT, Key_Call, true);
    key_attach(&k4, KEY_ALL_EVENT, Key_Call, true);
    key_attach(&k5, KEY_ALL_EVENT, Key_Call, true);
    key_attach(&k6, KEY_ALL_EVENT, Key_Call, true);
//    key_attach(&ks, KEY_ALL_EVENT, Key_Call,true);

    while (1) {
        // 每5ms调用一次key_ticks函数
        key_ticks();
        Sleep(5);
    }
}
