diff --git a/demo/key/test.c b/demo/key/test.c index 4ce516c..90cef24 100644 --- a/demo/key/test.c +++ b/demo/key/test.c @@ -1,17 +1,17 @@ #include #include "key.h" #include "log.h" -#include "tool.h" #include "t_key.h" #include +#include +#include "sim_key.h" uint8_t Key_Pin(uint8_t l) { - uint8_t k = rand() % 2; -// LOGT("KEY", "P:%d-%d", l,k); - return k; + 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: @@ -39,18 +39,33 @@ void Key_Call(Key_t *key) { } void Test_Key() { + 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_t k1, k2; - key_init(&k1, Key_Pin, 1, 0); - key_init(&k2, Key_Pin, 1, 1); key_attach(&k1, KEY_ALL_EVENT, Key_Call); key_attach(&k2, KEY_ALL_EVENT, Key_Call); + key_attach(&k3, KEY_ALL_EVENT, Key_Call); + key_attach(&k4, KEY_ALL_EVENT, Key_Call); + key_attach(&k5, KEY_ALL_EVENT, Key_Call); + key_attach(&k6, KEY_ALL_EVENT, Key_Call); +// key_attach(&ks, KEY_ALL_EVENT, Key_Call); + key_start(&k1); key_start(&k2); + key_start(&k3); + key_start(&k4); + key_start(&k5); + key_start(&k6); +// key_start(&ks); while (1) { // 每5ms调用一次key_ticks函数 key_ticks(); - Sleep(5); // 使用Windows平台的Sleep函数进行5ms延时 + Sleep(5); } } \ No newline at end of file diff --git a/demo/oled/test.c b/demo/oled/test.c index 8ed094e..8010975 100644 --- a/demo/oled/test.c +++ b/demo/oled/test.c @@ -7,16 +7,16 @@ #include uint8_t Cmd(uint8_t *data, size_t l) { - Buf_Print("Cmd", data, l, 16); +// Buf_Print("Cmd", data, l, 16); } uint8_t Data(uint8_t *data, size_t l) { - Buf_Print("Data", data, l, 16); +// Buf_Print("Data", data, l, 16); } void Refresh_Call(OLED_T *dev) { - LOGT("OLED", "CALL"); - Buf_Print("Buf", dev->buf, dev->width * (dev->height / 8), 128); +// LOGT("OLED", "CALL"); +// Buf_Print("Buf", dev->buf, dev->width * (dev->height / 8), 128); SIM_OLED_DrawFromBuffer(dev->buf, dev->width, dev->height / 8); } @@ -35,14 +35,18 @@ void Test_OLED() { }; OLED_Init(&oled); OLED_CLS(&oled); - OLED_DrawRect(&oled, 0, 0, 127, 63); - OLED_ShowString(&oled, 12, 24, "Hello JXS", 16); +// OLED_DrawRect(&oled, 0, 0, 127, 63); + OLED_ShowString(&oled, 32, 0, "Main Page", 12); + OLED_ShowString(&oled, 36, 12, "1.PageA", 12); + OLED_ShowString(&oled, 36, 24, "2.PageB", 12); + OLED_ShowString(&oled, 36, 36, "3.PageC", 12); SIM_OLED_START(); int s = 0; char buf[30]; - while (s < 10) { + + while (1) { sprintf(buf, "DATA:%d", s); - OLED_ShowString(&oled, 2, 2, buf, 12); + OLED_ShowString(&oled, 2, 51, buf, 12); OLED_Refresh(&oled); s++; Sleep(500); diff --git a/lib/inc/key/key.h b/lib/inc/key/key.h index 9f246af..a9dd2c0 100644 --- a/lib/inc/key/key.h +++ b/lib/inc/key/key.h @@ -1,4 +1,4 @@ -#ifndef HW_LIB_KEY_H +#ifndef HW_LIB_SIM_KEY_H #define HW_LIB_KEY_H #ifdef __cplusplus extern "C" { @@ -8,7 +8,7 @@ extern "C" { #include #define KEY_TICKS_INTERVAL 5 // 定时器间隔时间,单位为毫秒 -#define DEBOUNCE_TICKS 3 // 按键去抖动计数阈值,最大为7(0 ~ 7) +#define DEBOUNCE_TICKS 0 // 按键去抖动计数阈值,最大为7(0 ~ 7) #define SHORT_TICKS (300 / KEY_TICKS_INTERVAL) // 短按阈值,单位为定时器间隔的倍数 #define LONG_TICKS (1000 / KEY_TICKS_INTERVAL) // 长按阈值,单位为定时器间隔的倍数 #define KEY_STOP_FREE 1 // 按键停止释放状态标识 @@ -99,4 +99,4 @@ void key_ticks(void); #ifdef __cplusplus } #endif -#endif //HW_LIB_KEY_H +#endif //HW_LIB_SIM_KEY_H diff --git a/main.c b/main.c index 347923b..b19ff50 100644 --- a/main.c +++ b/main.c @@ -10,23 +10,24 @@ #include "t_oled.h" #include "tool.h" #include - - +#include +#include int main() { srand((unsigned) time(NULL)); - int i = 1; - POUT((++i) + (++i)); +// int i = 1; +// POUT((++i) + (++i)); +// +// char str[] = "123.456"; +// float result = Str2Float(str); +// printf("Result: %.3f\n", result); +// Test_RunTime("SPI", Test_spi); +// Test_RunTime("IIC", Test_iic); +// Test_RunTime("ArgPase", Test_argpase); +// Test_RunTime("List", Test_List); +// Test_RunTime("Key", Test_Key); - char str[] = "123.456"; - float result = Str2Float(str); - printf("Result: %.3f\n", result); - Test_RunTime("SPI", Test_spi); - Test_RunTime("IIC", Test_iic); - Test_RunTime("ArgPase", Test_argpase); - Test_RunTime("List", Test_List); - Test_RunTime("Queue", Test_Queue); +// Test_RunTime("Queue", Test_Queue); // Test_RunTime("Task", Test_task); Test_RunTime("OLED", Test_OLED); -// Test_RunTime("Key", Test_Key); return 0; } diff --git a/sim/key/key.cpp b/sim/key/key.cpp new file mode 100644 index 0000000..7b4f9e5 --- /dev/null +++ b/sim/key/key.cpp @@ -0,0 +1,83 @@ +#include "sim_key.h" +#include "log.h" + +#include +#include + +uint8_t SIM_Key_Scan() { + uint8_t key = 0; + if (_kbhit()) { + char keys = _getch(); + switch (keys) { + //上键 + case 72: + case 'w': + case 'W': + key = SIM_KEY_UP; + break; + + case 80: + case 's': + case 'S': + key = SIM_KEY_DOWN; + break; + + //左键 + case 75: + case 'a': + case 'A': + key = SIM_KEY_LEFT; + break; + + //右键 + case 77: + case 'd': + case 'D': + key = SIM_KEY_RIGHT; + break; + case 'q': + case 'Q': + key = SIM_KEY_SET; + break; + case 'e': + case 'E': + key = SIM_KEY_ENABLE; + break; + case 'r': + case 'R': + key = SIM_KEY_RESET; + break; + } + } + return key; +} + +uint8_t SIM_Key_UP(uint8_t) { + return GetAsyncKeyState(VK_UP); +} + +uint8_t SIM_Key_DOWN(uint8_t l) { +// uint8_t k=GetAsyncKeyState(VK_DOWN); +// LOGT("SIM","KEYID:%d-DOWN:%d",l,k); + return GetAsyncKeyState(VK_DOWN); +} + +uint8_t SIM_Key_LEFT(uint8_t) { + return GetAsyncKeyState(VK_LEFT); +} + +uint8_t SIM_Key_RIGHT(uint8_t) { + return GetAsyncKeyState(VK_RIGHT); +} + +uint8_t SIM_Key_ENABLE(uint8_t) { + return GetAsyncKeyState(VK_RETURN); +} + +uint8_t SIM_Key_SET(uint8_t) { + return GetAsyncKeyState(VK_RSHIFT); +} + +uint8_t SIM_SIM_Key_RESET(uint8_t) { + return GetAsyncKeyState(VK_END); +} \ No newline at end of file diff --git a/sim/key/sim_key.h b/sim/key/sim_key.h new file mode 100644 index 0000000..2be8b26 --- /dev/null +++ b/sim/key/sim_key.h @@ -0,0 +1,36 @@ +#ifndef HW_LIB_SIM_KEY_H +#define HW_LIB_SIM_KEY_H +#ifdef __cplusplus +extern "C" { +#endif +#include "stdint.h" + +typedef enum Key_map { + SIM_KEY_UP = 1, + SIM_KEY_DOWN, + SIM_KEY_LEFT, + SIM_KEY_RIGHT, + SIM_KEY_ENABLE, + SIM_KEY_SET, + SIM_KEY_RESET +} Key_Map_t; + +uint8_t SIM_Key_Scan(); + +uint8_t SIM_Key_UP(uint8_t l); + +uint8_t SIM_Key_DOWN(uint8_t l); + +uint8_t SIM_Key_LEFT(uint8_t l); + +uint8_t SIM_Key_RIGHT(uint8_t l); + +uint8_t SIM_Key_ENABLE(uint8_t l); + +uint8_t SIM_Key_SET(uint8_t l); + +uint8_t SIM_Key_RESET(uint8_t l); +#ifdef __cplusplus +} +#endif +#endif //HW_LIB_SIM_KEY_H diff --git a/sim/oled/oled.cpp b/sim/oled/oled.cpp index f4464af..78d53c0 100644 --- a/sim/oled/oled.cpp +++ b/sim/oled/oled.cpp @@ -37,6 +37,7 @@ void drawOledPixel(int oledX, int oledY) { void SIM_OLED_DrawFromBuffer(uint8_t *buf, uint8_t width, uint8_t height) { + BeginBatchDraw(); cleardevice(); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { @@ -47,6 +48,7 @@ void SIM_OLED_DrawFromBuffer(uint8_t *buf, uint8_t width, uint8_t height) { } } } + EndBatchDraw(); } diff --git a/sim/thread/sim_thread.h b/sim/thread/sim_thread.h new file mode 100644 index 0000000..9866234 --- /dev/null +++ b/sim/thread/sim_thread.h @@ -0,0 +1,14 @@ +#ifndef HW_LIB_SIM_THREAD_H +#define HW_LIB_SIM_THREAD_H +#ifdef __cplusplus +extern "C" { +#endif + +typedef void (*Thread_Func_t)(void *pArg); + +void ThreadCreat(Thread_Func_t func, unsigned int stackSize, void *pArg); +void ThreadStop(); +#ifdef __cplusplus +} +#endif +#endif //HW_LIB_SIM_THREAD_H diff --git a/sim/thread/thread.cpp b/sim/thread/thread.cpp new file mode 100644 index 0000000..40e5ff2 --- /dev/null +++ b/sim/thread/thread.cpp @@ -0,0 +1,11 @@ +#include "sim_thread.h" +#include +#include + +void ThreadCreat(Thread_Func_t func, unsigned int stackSize, void *pArg) { + _beginthread(func, stackSize, pArg); +} + +void ThreadStop() { + _endthread(); +}