diff --git a/code/esp32c3_espidf/main/hello_world_main.c b/code/esp32c3_espidf/main/hello_world_main.c index daa5b13..f24ba8a 100644 --- a/code/esp32c3_espidf/main/hello_world_main.c +++ b/code/esp32c3_espidf/main/hello_world_main.c @@ -127,6 +127,7 @@ void app_main(void) // lcd_send_full_buf(); // t = custom_tick_get(); // ESP_LOGI(TAG, "NOW is%lu", t); + //this_work_loop(); lv_task_handler(); vTaskDelay(1); // 必须让出CPU diff --git a/code/esp32c3_espidf/main/lv_apps/helloworld/lv_helloworld.c b/code/esp32c3_espidf/main/lv_apps/helloworld/lv_helloworld.c index 9933f7e..8fb7f6d 100644 --- a/code/esp32c3_espidf/main/lv_apps/helloworld/lv_helloworld.c +++ b/code/esp32c3_espidf/main/lv_apps/helloworld/lv_helloworld.c @@ -8,27 +8,44 @@ LV_FONT_DECLARE(my_cn_font); /** * Create styles from scratch for buttons. */ + +unsigned int t=0; +char str[32]={0}; + +lv_obj_t *label3 ; //lv_label_create(lv_screen_active()); /*Add a label to the button*/ + static lv_style_t style_label; + + void this_work_loop(){ + t++; + //sprintf(str,"xxx:%lu",t); + //lv_label_set_text(label3, str); + //lv_obj_add_style(label3, &style_label, 0); + lv_label_set_text_fmt(label3,"这是啥xxx:%d",t); + + +} + void lv_example_get_started_1(void) { // 1. 加载中文字体 - lv_font_t* cn_font_16 = load_chinese_font_from_spiffs("S:/spiffs/cn_font.bin"); - if (cn_font_16 == NULL) { - ESP_LOGE(TAG, "无法加载中文字体,使用默认字体"); - cn_font_16 = &my_cn_font; // 回退到默认字体 + lv_font_t *cn_font_16 = &my_cn_font; // load_chinese_font_from_spiffs("S:/spiffs/cn_font.bin"); + if (cn_font_16 == NULL) + { + ESP_LOGE(TAG, "无法加载中文字体"); + // cn_font_16 = &my_cn_font; // 回退到默认字体 } - /*Change the active screen's background color*/ lv_obj_set_style_bg_color(lv_screen_active(), lv_color_hex(0x003a57), LV_PART_MAIN); - static lv_style_t style_label; + lv_style_init(&style_label); - lv_style_set_text_font(&style_label, cn_font_16); // 关键:设置字体 + //lv_style_set_text_font(&style_label, cn_font_16); // 关键:设置字体 /*Create a white label, set its text and align it to the center*/ lv_obj_t *label = lv_label_create(lv_screen_active()); - lv_obj_add_style(label, &style_label, 0); + //lv_obj_add_style(label, &style_label, 0); lv_label_set_text(label, "Hello world 你好世界!"); lv_obj_set_style_text_color(lv_screen_active(), lv_color_hex(0xffffff), LV_PART_MAIN); lv_obj_align(label, LV_ALIGN_CENTER, 0, 0); @@ -40,4 +57,15 @@ void lv_example_get_started_1(void) lv_obj_t *label2 = lv_label_create(btn); /*Add a label to the button*/ lv_label_set_text(label2, "Button"); /*Set the labels text*/ lv_obj_center(label2); -} \ No newline at end of file + + label3=lv_label_create(lv_screen_active()); /*Add a label to the button*/ + + //lv_label_set_text(label3, "xxx:"); /*Set the labels text*/ + lv_obj_set_pos(label3, 200, 150); + + lv_timer_create(this_work_loop, 1000, NULL); + +} + + + diff --git a/code/esp32c3_espidf/main/lv_apps/helloworld/lv_helloworld.h b/code/esp32c3_espidf/main/lv_apps/helloworld/lv_helloworld.h index f5104a4..1653c8b 100644 --- a/code/esp32c3_espidf/main/lv_apps/helloworld/lv_helloworld.h +++ b/code/esp32c3_espidf/main/lv_apps/helloworld/lv_helloworld.h @@ -5,5 +5,6 @@ #include "esp_log.h" void lv_example_get_started_1(void); +void this_work_loop(); #endif \ No newline at end of file diff --git a/code/font/cn_font.bin b/code/font/cn_font.bin index 73b5af4..1dc5dc2 100644 Binary files a/code/font/cn_font.bin and b/code/font/cn_font.bin differ diff --git a/code/font/make_font_bin_test.cmd b/code/font/make_font_bin_test.cmd new file mode 100644 index 0000000..b20950b --- /dev/null +++ b/code/font/make_font_bin_test.cmd @@ -0,0 +1 @@ +lv_font_conv --font HarmonyOS_Sans_SC_Regular.ttf --size 16 --bpp 1 --range 0x20-0x7F --range 0x3000-0x303F --format bin --output cn_font.bin \ No newline at end of file diff --git a/code/font/make_test_font.cmd b/code/font/make_test_font.cmd new file mode 100644 index 0000000..7e4e2da --- /dev/null +++ b/code/font/make_test_font.cmd @@ -0,0 +1 @@ +lv_font_conv --font HarmonyOS_Sans_SC_Regular.ttf --size 16 --bpp 1 --symbols "你好世界ABC123℃" --format bin --output test_cn_font.bin \ No newline at end of file diff --git a/code/font/test_cn_font.bin b/code/font/test_cn_font.bin new file mode 100644 index 0000000..c5aef4e Binary files /dev/null and b/code/font/test_cn_font.bin differ