遥控页面更换及暂停
This commit is contained in:
parent
890d9292a8
commit
aee981d847
|
@ -39,6 +39,7 @@ int main(void)
|
||||||
rt_wlan_config_autoreconnect(RT_TRUE);
|
rt_wlan_config_autoreconnect(RT_TRUE);
|
||||||
rt_wlan_connect("Dong", "abcd07691234");
|
rt_wlan_connect("Dong", "abcd07691234");
|
||||||
system("myproject");
|
system("myproject");
|
||||||
|
// system("mqtt");
|
||||||
mytime();
|
mytime();
|
||||||
|
|
||||||
/* init Wi-Fi auto connect feature */
|
/* init Wi-Fi auto connect feature */
|
||||||
|
|
|
@ -16,30 +16,40 @@
|
||||||
|
|
||||||
extern rt_atomic_t now_direction;
|
extern rt_atomic_t now_direction;
|
||||||
extern rt_atomic_t snake_pressed;
|
extern rt_atomic_t snake_pressed;
|
||||||
extern rt_atomic_t page_chosen ;
|
extern rt_atomic_t page_chosen;
|
||||||
|
extern rt_atomic_t page_first;
|
||||||
|
extern rt_atomic_t page_stop;
|
||||||
extern int snake_max;
|
extern int snake_max;
|
||||||
extern char tmp[10];
|
extern char tmp[10];
|
||||||
|
|
||||||
void snake_compare(rt_uint8_t key)
|
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 (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);
|
||||||
|
|
||||||
if (rt_strcmp(tmp, "E8") == 0|| rt_strcmp(tmp, "99") == 0)
|
if (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);
|
||||||
if (rt_strcmp(tmp, "B0") == 0|| rt_strcmp(tmp, "4B") == 0)
|
if (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);
|
||||||
if (rt_strcmp(tmp, "68") == 0|| rt_strcmp(tmp, "83") == 0)
|
if (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);
|
||||||
// if (rt_strcmp(tmp, "88") == 0)
|
if (repeat == 0 && (rt_strcmp(tmp, "88") == 0 || rt_strcmp(tmp, "11") == 0))
|
||||||
// page_chosen = (page_chosen % PAGE_MAX) + 1;
|
{
|
||||||
|
page_chosen = (page_chosen % PAGE_MAX) + 1;
|
||||||
|
page_first = 1;
|
||||||
|
rt_kprintf("page_chosen = %d\n", page_chosen);
|
||||||
|
}
|
||||||
|
if (repeat == 0 && (rt_strcmp(tmp, "73") == 0 ))
|
||||||
|
{
|
||||||
|
page_stop = (page_stop + 1) % 2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void myir_entry(void *parameter)
|
void myir_entry(void *parameter)
|
||||||
|
@ -67,7 +77,7 @@ void myir_entry(void *parameter)
|
||||||
rt_pin_write(PIN_LED_R, PIN_LOW);
|
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,
|
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);
|
snake_compare(infrared_data.data.nec.key, infrared_data.data.nec.repeat);
|
||||||
}
|
}
|
||||||
rt_thread_mdelay(50);
|
rt_thread_mdelay(50);
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,8 @@ char buffer[1026] = {};
|
||||||
char tmp[1026];
|
char tmp[1026];
|
||||||
extern int snake_len;
|
extern int snake_len;
|
||||||
rt_atomic_t page_chosen = 1;
|
rt_atomic_t page_chosen = 1;
|
||||||
|
rt_atomic_t page_first = 1;
|
||||||
|
rt_atomic_t page_stop = 0;
|
||||||
|
|
||||||
#define PAGE_MAX 2
|
#define PAGE_MAX 2
|
||||||
|
|
||||||
|
@ -199,14 +201,21 @@ void tmp_payload(void)
|
||||||
// sprintf(tmp, "Temp: %.1f;Humi: %.1f;Count: %d\n", Temp, Humi,++cnt);
|
// sprintf(tmp, "Temp: %.1f;Humi: %.1f;Count: %d\n", Temp, Humi,++cnt);
|
||||||
// rt_kprintf("\n%f %f tmp:%s\n",Humi,Temp,tmp);
|
// rt_kprintf("\n%f %f tmp:%s\n",Humi,Temp,tmp);
|
||||||
// make_file();
|
// make_file();
|
||||||
// if (page_chosen == 2)
|
if (page_chosen == 2 && !page_stop)
|
||||||
// {
|
{
|
||||||
// show_lcd();
|
if (page_first)
|
||||||
// }
|
{
|
||||||
// if (ps_data > 14)
|
my_round(20);
|
||||||
// {
|
page_first = 0;
|
||||||
// page_chosen = (page_chosen % PAGE_MAX) + 1;
|
}
|
||||||
// }
|
|
||||||
|
show_lcd();
|
||||||
|
}
|
||||||
|
if (ps_data > 14)
|
||||||
|
{
|
||||||
|
page_chosen = (page_chosen % PAGE_MAX) + 1;
|
||||||
|
page_first = 1;
|
||||||
|
}
|
||||||
sprintf(tmp, "{\"params\":{\"temperature\":%.2f,\"humidity\":%.2f,\"LightLux\":%.2f,\"Psdata\":%d,\"Snakelen\":%d}}", Temp, Humi, brightness, ps_data, snake_len);
|
sprintf(tmp, "{\"params\":{\"temperature\":%.2f,\"humidity\":%.2f,\"LightLux\":%.2f,\"Psdata\":%d,\"Snakelen\":%d}}", Temp, Humi, brightness, ps_data, snake_len);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -338,6 +347,7 @@ void mqt_init(void)
|
||||||
rt_kprintf("MQTT Thread Create Failed!\n");
|
rt_kprintf("MQTT Thread Create Failed!\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// MSH_CMD_EXPORT_ALIAS(mqt_init, mqtt, run my mqtt);
|
||||||
int ap3_init(void)
|
int ap3_init(void)
|
||||||
{
|
{
|
||||||
const char *i2c_bus_name = "i2c2";
|
const char *i2c_bus_name = "i2c2";
|
||||||
|
|
|
@ -8,10 +8,12 @@
|
||||||
|
|
||||||
#define LCD_MAX 240
|
#define LCD_MAX 240
|
||||||
#define SNAKE_SIZE 20
|
#define SNAKE_SIZE 20
|
||||||
#define SNAKE_MAX LCD_MAX / SNAKE_SIZE
|
#define SNAKE_MAX (LCD_MAX / SNAKE_SIZE)
|
||||||
rt_atomic_t now_direction = 3;
|
rt_atomic_t now_direction = 3;
|
||||||
rt_atomic_t snake_pressed = 0;
|
rt_atomic_t snake_pressed = 0;
|
||||||
extern rt_atomic_t page_chosen;
|
extern rt_atomic_t page_chosen;
|
||||||
|
extern rt_atomic_t page_first;
|
||||||
|
extern rt_atomic_t page_stop;
|
||||||
int snake_max = SNAKE_MAX * 3;
|
int snake_max = SNAKE_MAX * 3;
|
||||||
int snake_len = 3;
|
int snake_len = 3;
|
||||||
|
|
||||||
|
@ -51,13 +53,26 @@ void snake_entry(void *parameter)
|
||||||
snake_address(snake_list[2][0], snake_list[2][1], SNAKE_SIZE, BLACK);
|
snake_address(snake_list[2][0], snake_list[2][1], SNAKE_SIZE, BLACK);
|
||||||
snake_food[0] = rand() % SNAKE_MAX;
|
snake_food[0] = rand() % SNAKE_MAX;
|
||||||
snake_food[1] = rand() % SNAKE_MAX;
|
snake_food[1] = rand() % SNAKE_MAX;
|
||||||
snake_address(snake_food[0], snake_food[1], SNAKE_SIZE, GREEN);
|
// snake_address(snake_food[0], snake_food[1], SNAKE_SIZE, GREEN);
|
||||||
int new_head_x = 0, new_head_y = 0;
|
int new_head_x = 0, new_head_y = 0;
|
||||||
int new_direction = 0;
|
int new_direction = 0,snake_now=0;
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
if (page_chosen == 1)
|
if (page_chosen == 1&&!page_stop)
|
||||||
{
|
{
|
||||||
|
if (page_first == 1)
|
||||||
|
{
|
||||||
|
page_first = 0;
|
||||||
|
lcd_fill(0, 0, 240, 240, WHITE);
|
||||||
|
snake_address(snake_food[0], snake_food[1], SNAKE_SIZE, GREEN);
|
||||||
|
snake_now = snake_tail-1;
|
||||||
|
// for (int i = 0; i = snake_len && i < SNAKE_MAX - 1; i++)
|
||||||
|
do{
|
||||||
|
snake_now=(snake_now+1)%SNAKE_MAX;
|
||||||
|
snake_address(snake_list[snake_now][0], snake_list[snake_now][1], SNAKE_SIZE, BLACK);
|
||||||
|
}while(snake_now!=snake_head);
|
||||||
|
}
|
||||||
|
|
||||||
if (!snake_pressed)
|
if (!snake_pressed)
|
||||||
{
|
{
|
||||||
// 50%的概率保持当前方向,20%的概率随机改变方向
|
// 50%的概率保持当前方向,20%的概率随机改变方向
|
||||||
|
|
Loading…
Reference in New Issue