增加换页,取消font分区

This commit is contained in:
james 2024-08-05 19:36:23 +08:00
parent 48ce5126c8
commit 7c71bb5be2
5 changed files with 126 additions and 79 deletions

28
.config
View File

@ -776,7 +776,33 @@ CONFIG_PKG_CJSON_VER="v1.7.17"
#
# LVGL: powerful and easy-to-use embedded GUI library
#
# CONFIG_PKG_USING_LVGL is not set
CONFIG_PKG_USING_LVGL=y
CONFIG_PKG_LVGL_PATH="/packages/multimedia/LVGL/LVGL"
CONFIG_PKG_LVGL_THREAD_PRIO=20
CONFIG_PKG_LVGL_THREAD_STACK_SIZE=4096
CONFIG_PKG_LVGL_DISP_REFR_PERIOD=5
# CONFIG_PKG_USING_LVGL_SQUARELINE is not set
# CONFIG_PKG_LVGL_USING_EXAMPLES is not set
CONFIG_PKG_LVGL_USING_DEMOS=y
CONFIG_PKG_LVGL_USING_V080311=y
# CONFIG_PKG_LVGL_USING_V080310 is not set
# CONFIG_PKG_LVGL_USING_V08039 is not set
# CONFIG_PKG_LVGL_USING_V08038 is not set
# CONFIG_PKG_LVGL_USING_V08037 is not set
# CONFIG_PKG_LVGL_USING_V08036 is not set
# CONFIG_PKG_LVGL_USING_V08035 is not set
# CONFIG_PKG_LVGL_USING_V08034 is not set
# CONFIG_PKG_LVGL_USING_V08033 is not set
# CONFIG_PKG_LVGL_USING_V08032 is not set
# CONFIG_PKG_LVGL_USING_V08031 is not set
# CONFIG_PKG_LVGL_USING_V08030 is not set
# CONFIG_PKG_LVGL_USING_V08020 is not set
# CONFIG_PKG_LVGL_USING_V8_3_LATEST_VERSION is not set
# CONFIG_PKG_LVGL_USING_V09000 is not set
# CONFIG_PKG_LVGL_USING_V09010 is not set
# CONFIG_PKG_LVGL_USING_LATEST_VERSION is not set
CONFIG_PKG_LVGL_VER_NUM=0x080311
CONFIG_PKG_LVGL_VER="v8.3.11"
# CONFIG_PKG_USING_LV_MUSIC_DEMO is not set
# CONFIG_PKG_USING_GUI_GUIDER_DEMO is not set
# end of LVGL: powerful and easy-to-use embedded GUI library

View File

@ -56,7 +56,7 @@ static int onboard_fal_mount(void)
fal_init();
/* 在 spi flash 中名为 "filesystem" 的分区上创建一个块设备 */
struct rt_device *flash_dev = fal_blk_device_create(FS_PARTITION_NAME);
fal_blk_device_create("font");
// fal_blk_device_create("font");
if (flash_dev == NULL)
{
LOG_E("Can't create a block device on '%s' partition.", FS_PARTITION_NAME);
@ -87,36 +87,36 @@ static int onboard_fal_mount(void)
int ret;
/* 创建目录 */
ret = mkdir("/fal/test", 0x777);
if (ret < 0)
{
/* 创建目录失败 */
rt_kprintf("dir error!\n");
}
else
{
/* 创建目录成功 */
rt_kprintf("mkdir ok!\n");
}
/* 挂载块设备"font"到 DFS 目录/fal/test中 */
if (dfs_mount("font", "/fal/test", "elm", 0, 0) == 0)
{
LOG_I("font initialized!");
}
else
{
dfs_mkfs("elm", "font");
if (dfs_mount("font", "/fal/test", "elm", 0, 0) == 0)
{
LOG_I("font initialized!");
}
else
{
LOG_E("Failed to initialize font!");
LOG_D("You should create a filesystem(font) on the block device first!");
}
}
// /* 创建目录 */
// ret = mkdir("/fal/test", 0x777);
// if (ret < 0)
// {
// /* 创建目录失败 */
// rt_kprintf("dir error!\n");
// }
// else
// {
// /* 创建目录成功 */
// rt_kprintf("mkdir ok!\n");
// }
// /* 挂载块设备"font"到 DFS 目录/fal/test中 */
// if (dfs_mount("font", "/fal/test", "elm", 0, 0) == 0)
// {
// LOG_I("font initialized!");
// }
// else
// {
// dfs_mkfs("elm", "font");
// if (dfs_mount("font", "/fal/test", "elm", 0, 0) == 0)
// {
// LOG_I("font initialized!");
// }
// else
// {
// LOG_E("Failed to initialize font!");
// LOG_D("You should create a filesystem(font) on the block device first!");
// }
// }
return RT_EOK;
}
#endif /*BSP_USING_FLASH_FATFS*/

View File

@ -28,6 +28,9 @@ int HAL_Snprintf(char *str, const int len, const char *fmt, ...);
char buffer[1026] = {};
char tmp[1026];
extern int snake_len;
rt_atomic_t page_chosen = 1;
#define PAGE_MAX 2
#define GPIO_LED_B GET_PIN(F, 11)
#define GPIO_LED_R GET_PIN(F, 12)
@ -178,12 +181,19 @@ 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;
}
// 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);
// rt_kprintf("\n%f %f tmp:%s\n",Humi,Temp,tmp);
// make_file();
// show_lcd();
if (page_chosen == 2)
{
show_lcd();
}
sprintf(tmp, "{\"params\":{\"temperature\":%.2f,\"humidity\":%.2f,\"LightLux\":%.2f,\"Psdata\":%d,\"Snakelen\":%d}}", Temp, Humi, brightness, ps_data, snake_len);
return;
}

View File

@ -11,6 +11,7 @@
#define SNAKE_MAX LCD_MAX / SNAKE_SIZE
rt_atomic_t now_direction = 3;
rt_atomic_t snake_pressed = 0;
extern rt_atomic_t page_chosen;
int snake_max = SNAKE_MAX * 3;
int snake_len = 3;
@ -55,58 +56,61 @@ void snake_entry(void *parameter)
int new_direction = 0;
while (1)
{
if (!snake_pressed)
if (page_chosen == 1)
{
//50%的概率保持当前方向20%的概率随机改变方向
if (rand() % 100 < 50)
{
new_direction = rand() % 3;
now_direction = (now_direction + 3 + new_direction) % 4; // 防止反向,走回头路
}
}
else
{
rt_atomic_add(&snake_pressed, -1);
}
new_head_x = (snake_list[snake_head][0] + snake_direction[now_direction][0] + SNAKE_MAX) % (SNAKE_MAX);
new_head_y = (snake_list[snake_head][1] + snake_direction[now_direction][1] + SNAKE_MAX) % (SNAKE_MAX);
sprintf(tmp, "(%d,%d)", new_head_x, new_head_y);
// rt_kprintf("head:%d,%d\n", snake_list[snake_head][0], snake_list[snake_head][1]);
lcd_show_string(20, 20, 16, snake_dirshow[now_direction]);
lcd_show_string(20 + 16 * 4, 20, 16, tmp);
snake_address(new_head_x, new_head_y, SNAKE_SIZE, BLACK);
if (new_head_x == snake_food[0] && new_head_y == snake_food[1])
{
snake_food[0] = rand() % SNAKE_MAX;
snake_food[1] = rand() % SNAKE_MAX;
snake_address(snake_food[0], snake_food[1], SNAKE_SIZE, GREEN);
snake_len++;
sprintf(tmp, "%d", snake_len);
lcd_show_string(100, 105, 32, tmp);
// 防止蛇咬尾出现bug
if (snake_len >= SNAKE_MAX)
{
snake_address(snake_list[snake_tail][0], snake_list[snake_tail][1], SNAKE_SIZE, WHITE);
snake_tail = (snake_tail + 1) % (SNAKE_MAX);
}
}
else
{
if (snake_list[snake_tail][0] == snake_food[0] && snake_list[snake_tail][1] == snake_food[1])
if (!snake_pressed)
{
// 50%的概率保持当前方向20%的概率随机改变方向
if (rand() % 100 < 50)
{
new_direction = rand() % 3;
now_direction = (now_direction + 3 + new_direction) % 4; // 防止反向,走回头路
}
}
else
{
snake_address(snake_list[snake_tail][0], snake_list[snake_tail][1], SNAKE_SIZE, WHITE);
rt_atomic_add(&snake_pressed, -1);
}
snake_tail = (snake_tail + 1) % (SNAKE_MAX);
new_head_x = (snake_list[snake_head][0] + snake_direction[now_direction][0] + SNAKE_MAX) % (SNAKE_MAX);
new_head_y = (snake_list[snake_head][1] + snake_direction[now_direction][1] + SNAKE_MAX) % (SNAKE_MAX);
sprintf(tmp, "(%d,%d)", new_head_x, new_head_y);
// rt_kprintf("head:%d,%d\n", snake_list[snake_head][0], snake_list[snake_head][1]);
lcd_show_string(20, 20, 16, snake_dirshow[now_direction]);
lcd_show_string(20 + 16 * 4, 20, 16, tmp);
snake_address(new_head_x, new_head_y, SNAKE_SIZE, BLACK);
if (new_head_x == snake_food[0] && new_head_y == snake_food[1])
{
snake_food[0] = rand() % SNAKE_MAX;
snake_food[1] = rand() % SNAKE_MAX;
snake_address(snake_food[0], snake_food[1], SNAKE_SIZE, GREEN);
snake_len++;
sprintf(tmp, "%d", snake_len);
lcd_show_string(100, 105, 32, tmp);
// 防止蛇咬尾出现bug
if (snake_len >= SNAKE_MAX)
{
snake_address(snake_list[snake_tail][0], snake_list[snake_tail][1], SNAKE_SIZE, WHITE);
snake_tail = (snake_tail + 1) % (SNAKE_MAX);
}
}
else
{
if (snake_list[snake_tail][0] == snake_food[0] && snake_list[snake_tail][1] == snake_food[1])
{
}
else
{
snake_address(snake_list[snake_tail][0], snake_list[snake_tail][1], SNAKE_SIZE, WHITE);
}
snake_tail = (snake_tail + 1) % (SNAKE_MAX);
}
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);
}
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(300);
}
}

View File

@ -417,6 +417,13 @@
/* LVGL: powerful and easy-to-use embedded GUI library */
#define PKG_USING_LVGL
#define PKG_LVGL_THREAD_PRIO 20
#define PKG_LVGL_THREAD_STACK_SIZE 4096
#define PKG_LVGL_DISP_REFR_PERIOD 5
#define PKG_LVGL_USING_DEMOS
#define PKG_LVGL_USING_V080311
#define PKG_LVGL_VER_NUM 0x080311
/* end of LVGL: powerful and easy-to-use embedded GUI library */
/* u8g2: a monochrome graphic library */