注释接收+repeat=0才执行

This commit is contained in:
dgjames 2024-12-21 17:53:28 +08:00
parent e9a2c845e4
commit b06ad9518e
2 changed files with 42 additions and 42 deletions

View File

@ -29,7 +29,7 @@ void snake_compare(rt_uint8_t key, rt_uint8_t repeat)
rt_sprintf(tmp, "%02X", key); rt_sprintf(tmp, "%02X", key);
rt_atomic_store(&snake_pressed, snake_max + 1); rt_atomic_store(&snake_pressed, snake_max + 1);
// 上 // 上
if (rt_strcmp(tmp, "30") == 0 || rt_strcmp(tmp, "53") == 0) if (repeat == 0 &&rt_strcmp(tmp, "30") == 0 || rt_strcmp(tmp, "53") == 0)
{ {
if (rt_atomic_load(&now_direction) != 2) if (rt_atomic_load(&now_direction) != 2)
rt_atomic_store(&now_direction, 0); rt_atomic_store(&now_direction, 0);
@ -39,7 +39,7 @@ void snake_compare(rt_uint8_t key, rt_uint8_t repeat)
} }
// 左 // 左
if (rt_strcmp(tmp, "E8") == 0 || rt_strcmp(tmp, "99") == 0) if (repeat == 0 &&rt_strcmp(tmp, "E8") == 0 || rt_strcmp(tmp, "99") == 0)
{ {
if (rt_atomic_load(&now_direction) != 3) if (rt_atomic_load(&now_direction) != 3)
rt_atomic_store(&now_direction, 1); rt_atomic_store(&now_direction, 1);
@ -48,7 +48,7 @@ void snake_compare(rt_uint8_t key, rt_uint8_t repeat)
} }
// 下 // 下
if (rt_strcmp(tmp, "B0") == 0 || rt_strcmp(tmp, "4B") == 0) if (repeat == 0 &&rt_strcmp(tmp, "B0") == 0 || rt_strcmp(tmp, "4B") == 0)
{ {
if (rt_atomic_load(&now_direction) != 0) if (rt_atomic_load(&now_direction) != 0)
rt_atomic_store(&now_direction, 2); rt_atomic_store(&now_direction, 2);
@ -57,7 +57,7 @@ void snake_compare(rt_uint8_t key, rt_uint8_t repeat)
} }
// 右 // 右
if (rt_strcmp(tmp, "68") == 0 || rt_strcmp(tmp, "83") == 0) if (repeat == 0 &&rt_strcmp(tmp, "68") == 0 || rt_strcmp(tmp, "83") == 0)
{ {
if (rt_atomic_load(&now_direction) != 1) if (rt_atomic_load(&now_direction) != 1)
rt_atomic_store(&now_direction, 3); rt_atomic_store(&now_direction, 3);

View File

@ -404,34 +404,34 @@ void cdc_entry(void *parameter)
} }
} }
/* 用于接收消息的信号量 */ // /* 用于接收消息的信号量 */
static struct rt_semaphore rx_sem; // static struct rt_semaphore rx_sem;
/* 接收数据回调函数 */ // /* 接收数据回调函数 */
static rt_err_t uart_input(rt_device_t dev, rt_size_t size) // static rt_err_t uart_input(rt_device_t dev, rt_size_t size)
{ // {
/* 串口接收到数据后产生中断,调用此回调函数,然后发送接收信号量 */ // /* 串口接收到数据后产生中断,调用此回调函数,然后发送接收信号量 */
rt_sem_release(&rx_sem); // rt_sem_release(&rx_sem);
return RT_EOK; // return RT_EOK;
} // }
static void serial_thread_entry(void *parameter) // static void serial_thread_entry(void *parameter)
{ // {
char ch[105]; // char ch[105];
while (1) // while (1)
{ // {
/* 从串口读取一个字节的数据,没有读取到则等待接收信号量 */ // /* 从串口读取一个字节的数据,没有读取到则等待接收信号量 */
int Size; // int Size;
while ((Size=rt_device_read(serial, -1, &ch, 104) )!= 1) // while ((Size=rt_device_read(serial, -1, &ch, 104) )!= 1)
{ // {
/* 阻塞等待接收信号量,等到信号量后再次读取数据 */ // /* 阻塞等待接收信号量,等到信号量后再次读取数据 */
rt_sem_take(&rx_sem, RT_WAITING_FOREVER); // rt_sem_take(&rx_sem, RT_WAITING_FOREVER);
} // }
rt_kprintf("%s",ch); // rt_kprintf("%s",ch);
} // }
} // }
@ -465,24 +465,24 @@ void serial_init(void)
/* step3控制串口设备。通过控制接口传入命令控制字与控制参数 */ /* step3控制串口设备。通过控制接口传入命令控制字与控制参数 */
rt_device_control(serial, RT_DEVICE_CTRL_CONFIG, &config); rt_device_control(serial, RT_DEVICE_CTRL_CONFIG, &config);
/* 以 DMA 接收及轮询发送方式打开串口设备 */ /* 以 中断 接收及轮询发送方式打开串口设备 */
rt_device_open(serial, RT_DEVICE_FLAG_INT_RX); rt_device_open(serial, RT_DEVICE_FLAG_INT_RX);
/* 设置接收回调函数 */ // /* 设置接收回调函数 */
rt_device_set_rx_indicate(serial, uart_input); // rt_device_set_rx_indicate(serial, uart_input);
char str[] = "hello RTT\r\n"; char str[] = "hello RTT\r\n";
/* 发送字符串 */ /* 发送字符串 */
rt_device_write(serial, 0, str, (sizeof(str) - 1)); rt_device_write(serial, 0, str, (sizeof(str) - 1));
/* 创建 serial 线程 */ // /* 创建 serial 线程 */
rt_thread_t thread = rt_thread_create("serial", serial_thread_entry, RT_NULL, 1024, 25, 10); // rt_thread_t thread = rt_thread_create("serial", serial_thread_entry, RT_NULL, 1024, 25, 10);
/* 创建成功则启动线程 */ // /* 创建成功则启动线程 */
if (thread != RT_NULL) // if (thread != RT_NULL)
{ // {
rt_thread_startup(thread); // rt_thread_startup(thread);
} // }
else // else
{ // {
rt_kprintf("serial Thread Create Failed!\n"); // rt_kprintf("serial Thread Create Failed!\n");
} // }
} }
void mqt_init(void) void mqt_init(void)
{ {