红外遥控成功
This commit is contained in:
parent
823ddd46ec
commit
d5b82bdaa9
|
@ -35,9 +35,10 @@ int main(void)
|
|||
main_init();
|
||||
rt_pin_mode(PIN_LED_B, PIN_MODE_OUTPUT);
|
||||
rt_pin_write(PIN_LED_B, PIN_LOW);
|
||||
system("snake game");
|
||||
system("snake");
|
||||
rt_wlan_config_autoreconnect(RT_TRUE);
|
||||
rt_wlan_connect("Dong", "abcd07691234");
|
||||
system("myproject");
|
||||
mytime();
|
||||
|
||||
/* init Wi-Fi auto connect feature */
|
||||
|
|
|
@ -20,6 +20,9 @@
|
|||
``` c
|
||||
Snake_Thread = rt_thread_create("Snake_Thread", snake_entry, RT_NULL, THREAD_STACK_SIZE, 10, THREAD_TIMESLICE);
|
||||
```
|
||||
不注释又闪了,
|
||||
加到myproject,没唤醒时没事,唤醒后闪,重启也闪
|
||||
![alt text](image-2.png)
|
||||
### GET_PIN(F, 11) 的头文件
|
||||
|
||||
``` c
|
||||
|
@ -42,4 +45,13 @@ Snake_Thread = rt_thread_create("Snake_Thread", snake_entry, RT_NULL, THREAD_STA
|
|||
| 0x38 | 电源键 |
|
||||
| 0xA8 | 静音 |
|
||||
| 0x88 | 菜单 |
|
||||
| 0x28 | 退出 |
|
||||
| 0x28 | 退出 |
|
||||
|
||||
### 等待消息
|
||||
写成这样,导致一直等待,所以一直没反应
|
||||
``` c
|
||||
if(page_chosen == 1)
|
||||
{
|
||||
rt_mdelay(1000);
|
||||
}
|
||||
```
|
Binary file not shown.
After Width: | Height: | Size: 11 KiB |
|
@ -12,7 +12,35 @@
|
|||
/* 配置 LED 灯引脚 */
|
||||
#define PIN_LED_B GET_PIN(F, 11) // PF11 : LED_B --> LED
|
||||
#define PIN_LED_R GET_PIN(F, 12) // PF12 : LED_R --> LED
|
||||
#define PAGE_MAX 2
|
||||
|
||||
extern rt_atomic_t now_direction;
|
||||
extern rt_atomic_t snake_pressed;
|
||||
extern rt_atomic_t page_chosen ;
|
||||
extern int snake_max;
|
||||
extern char tmp[10];
|
||||
|
||||
void snake_compare(rt_uint8_t key)
|
||||
{
|
||||
rt_sprintf(tmp, "%02X", key);
|
||||
rt_atomic_store(&snake_pressed, snake_max + 1);
|
||||
|
||||
if (rt_strcmp(tmp, "30") == 0)
|
||||
if (rt_atomic_load(&now_direction) != 2)
|
||||
rt_atomic_store(&now_direction, 0);
|
||||
|
||||
if (rt_strcmp(tmp, "E8") == 0)
|
||||
if (rt_atomic_load(&now_direction) != 3)
|
||||
rt_atomic_store(&now_direction, 1);
|
||||
if (rt_strcmp(tmp, "B0") == 0)
|
||||
if (rt_atomic_load(&now_direction) != 0)
|
||||
rt_atomic_store(&now_direction, 2);
|
||||
if (rt_strcmp(tmp, "68") == 0)
|
||||
if (rt_atomic_load(&now_direction) != 1)
|
||||
rt_atomic_store(&now_direction, 3);
|
||||
if (rt_strcmp(tmp, "88") == 0)
|
||||
page_chosen = (page_chosen % PAGE_MAX) + 1;
|
||||
}
|
||||
|
||||
void myir_entry(void *parameter)
|
||||
{
|
||||
|
@ -31,25 +59,23 @@ void myir_entry(void *parameter)
|
|||
rt_pin_write(PIN_LED_R, PIN_HIGH);
|
||||
rt_pin_write(PIN_LED_B, PIN_HIGH);
|
||||
|
||||
while (count > 0)
|
||||
while (1)
|
||||
{
|
||||
if (infrared_read("nec", &infrared_data) == RT_EOK)
|
||||
{
|
||||
/* 读取到红外数据,红灯亮起 */
|
||||
rt_pin_write(PIN_LED_R, PIN_LOW);
|
||||
LOG_I("RECEIVE OK: addr:0x%02X key:0x%02X repeat:%d", infrared_data.data.nec.addr,
|
||||
infrared_data.data.nec.key, infrared_data.data.nec.repeat);
|
||||
infrared_data.data.nec.key, infrared_data.data.nec.repeat);
|
||||
snake_compare(infrared_data.data.nec.key);
|
||||
}
|
||||
rt_thread_mdelay(10);
|
||||
rt_thread_mdelay(50);
|
||||
|
||||
/* 熄灭蓝灯 */
|
||||
rt_pin_write(PIN_LED_B, PIN_HIGH);
|
||||
/* 熄灭红灯 */
|
||||
rt_pin_write(PIN_LED_R, PIN_HIGH);
|
||||
count++;
|
||||
// if( count % 100 == 0)
|
||||
// rt_kprintf("count = %d\n", count);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -10,7 +10,8 @@
|
|||
#include <dfs_posix.h>
|
||||
#include <drv_lcd.h>
|
||||
#include "mysnake.h"
|
||||
|
||||
#include "infrared.h"
|
||||
#include <ulog.h>
|
||||
|
||||
char DEMO_PRODUCT_KEY[IOTX_PRODUCT_KEY_LEN + 1] = {0};
|
||||
char DEMO_DEVICE_NAME[IOTX_DEVICE_NAME_LEN + 1] = {0};
|
||||
|
@ -49,14 +50,14 @@ rt_uint16_t ps_data;
|
|||
float brightness;
|
||||
int lcd_y;
|
||||
int int_tmp;
|
||||
struct infrared_decoder_data infrared_data;
|
||||
|
||||
// extern void myir_entry(void *parameter);
|
||||
extern void myir_entry(void *parameter);
|
||||
|
||||
void ath_init(void);
|
||||
void mqt_init(void);
|
||||
int ap3_init(void);
|
||||
// void inf_init(void);
|
||||
|
||||
void inf_init(void);
|
||||
|
||||
#define EXAMPLE_TRACE(fmt, ...) \
|
||||
do \
|
||||
|
@ -186,10 +187,13 @@ void tmp_payload(void)
|
|||
Temp = aht10_read_temperature(Dev);
|
||||
brightness = ap3216c_read_ambient_light(dev);
|
||||
ps_data = ap3216c_read_ps_data(dev);
|
||||
if (ps_data > 14)
|
||||
{
|
||||
page_chosen = (page_chosen % PAGE_MAX) + 1;
|
||||
}
|
||||
// if (infrared_read("nec", &infrared_data) == RT_EOK)
|
||||
// {
|
||||
// /* 读取到红外数据,红灯亮起 */
|
||||
// // rt_pin_write(PIN_LED_R, PIN_LOW);
|
||||
// LOG_I("RECEIVE OK: addr:0x%02X key:0x%02X repeat:%d", infrared_data.data.nec.addr,
|
||||
// infrared_data.data.nec.key, infrared_data.data.nec.repeat);
|
||||
// }
|
||||
// icm20608_get_accel(icm20608_device_t dev, rt_int16_t *accel_x, rt_int16_t *accel_y, rt_int16_t *accel_z)
|
||||
// memset(tmp, 0, sizeof(tmp));
|
||||
// sprintf(tmp, "Temp: %.1f;Humi: %.1f;Count: %d\n", Temp, Humi,++cnt);
|
||||
|
@ -199,6 +203,10 @@ void tmp_payload(void)
|
|||
{
|
||||
show_lcd();
|
||||
}
|
||||
if (ps_data > 14)
|
||||
{
|
||||
page_chosen = (page_chosen % PAGE_MAX) + 1;
|
||||
}
|
||||
sprintf(tmp, "{\"params\":{\"temperature\":%.2f,\"humidity\":%.2f,\"LightLux\":%.2f,\"Psdata\":%d,\"Snakelen\":%d}}", Temp, Humi, brightness, ps_data, snake_len);
|
||||
return;
|
||||
}
|
||||
|
@ -305,7 +313,7 @@ static void mqtt_example_main(void *parameter)
|
|||
|
||||
rt_thread_t MQTT_Thread = RT_NULL;
|
||||
rt_thread_t Snake_Thread = RT_NULL;
|
||||
// rt_thread_t Infrared_Thread = RT_NULL;
|
||||
rt_thread_t Infrared_Thread = RT_NULL;
|
||||
|
||||
void ath_init(void)
|
||||
{
|
||||
|
@ -361,28 +369,31 @@ MSH_CMD_EXPORT_ALIAS(snk_init, snake, "snake game");
|
|||
// return 0;
|
||||
|
||||
// }
|
||||
// void inf_init(void)
|
||||
// {
|
||||
// Infrared_Thread = rt_thread_create("Infrared_Thread", myir_entry, RT_NULL, THREAD_STACK_SIZE, THREAD_PRIORITY, THREAD_TIMESLICE);
|
||||
void inf_init(void)
|
||||
{
|
||||
Infrared_Thread = rt_thread_create("Infrared_Thread", myir_entry, RT_NULL, THREAD_STACK_SIZE, THREAD_PRIORITY, THREAD_TIMESLICE);
|
||||
|
||||
// if (Infrared_Thread != RT_NULL)
|
||||
// {
|
||||
// rt_thread_startup(Infrared_Thread);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// rt_kprintf("Infrared Thread Create Failed!\n");
|
||||
// }
|
||||
// }
|
||||
// MSH_CMD_EXPORT_ALIAS(inf_init, inf, "Infrared");
|
||||
if (Infrared_Thread != RT_NULL)
|
||||
{
|
||||
rt_thread_startup(Infrared_Thread);
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_kprintf("Infrared Thread Create Failed!\n");
|
||||
}
|
||||
}
|
||||
MSH_CMD_EXPORT_ALIAS(inf_init, inf, "Infrared");
|
||||
void my_project(void)
|
||||
{
|
||||
// /* 选择 NEC 解码器 */
|
||||
// ir_select_decoder("nec");
|
||||
|
||||
ath_init();
|
||||
|
||||
mqt_init();
|
||||
|
||||
ap3_init();
|
||||
|
||||
// inf_init();
|
||||
inf_init();
|
||||
}
|
||||
MSH_CMD_EXPORT_ALIAS(my_project, myproject, run my project);
|
|
@ -110,7 +110,7 @@ void snake_entry(void *parameter)
|
|||
snake_head = (snake_head + 1) % (SNAKE_MAX);
|
||||
snake_list[snake_head][0] = new_head_x;
|
||||
snake_list[snake_head][1] = new_head_y;
|
||||
rt_thread_mdelay(900);
|
||||
}
|
||||
rt_thread_mdelay(900);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue