UP 模拟器 加入key的模拟支持

This commit is contained in:
JiXieShi
2024-06-22 22:51:58 +08:00
parent 0c7c6bb1e9
commit 5876461531
9 changed files with 201 additions and 35 deletions

View File

@@ -1,17 +1,17 @@
#include <stdio.h>
#include "key.h"
#include "log.h"
#include "tool.h"
#include "t_key.h"
#include <windows.h>
#include <process.h>
#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);
}
}

View File

@@ -7,16 +7,16 @@
#include <windows.h>
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);