但是为什么换了一个函数之后就可以正常运行,
void lv_demo_widgets(void)
{
if(LV_HOR_RES <= 320) disp_size = DISP_SMALL;
else if(LV_HOR_RES < 720) disp_size = DISP_MEDIUM;
else disp_size = DISP_LARGE;
font_large = LV_FONT_DEFAULT;
font_normal = LV_FONT_DEFAULT;
lv_coord_t tab_h;
if(disp_size == DISP_LARGE) {
tab_h = 70;
#if LV_FONT_MONTSERRAT_24
font_large = &lv_font_montserrat_24;
#else
LV_LOG_WARN("LV_FONT_MONTSERRAT_24 is not enabled for the widgets demo. Using LV_FONT_DEFAULT instead.");
#endif
#if LV_FONT_MONTSERRAT_16
font_normal = &lv_font_montserrat_16;
#else
LV_LOG_WARN("LV_FONT_MONTSERRAT_16 is not enabled for the widgets demo. Using LV_FONT_DEFAULT instead.");
#endif
}
else if(disp_size == DISP_MEDIUM) {
tab_h = 45;
#if LV_FONT_MONTSERRAT_20
font_large = &lv_font_montserrat_20;
#else
LV_LOG_WARN("LV_FONT_MONTSERRAT_20 is not enabled for the widgets demo. Using LV_FONT_DEFAULT instead.");
#endif
#if LV_FONT_MONTSERRAT_14
font_normal = &lv_font_montserrat_14;
#else
LV_LOG_WARN("LV_FONT_MONTSERRAT_14 is not enabled for the widgets demo. Using LV_FONT_DEFAULT instead.");
#endif
}
else { /* disp_size == DISP_SMALL */
tab_h = 45;
#if LV_FONT_MONTSERRAT_18
font_large = &lv_font_montserrat_18;
#else
LV_LOG_WARN("LV_FONT_MONTSERRAT_18 is not enabled for the widgets demo. Using LV_FONT_DEFAULT instead.");
#endif
#if LV_FONT_MONTSERRAT_12
font_normal = &lv_font_montserrat_12;
#else
LV_LOG_WARN("LV_FONT_MONTSERRAT_12 is not enabled for the widgets demo. Using LV_FONT_DEFAULT instead.");
#endif
}
#if LV_USE_THEME_DEFAULT
lv_theme_default_init(NULL, lv_palette_main(LV_PALETTE_BLUE), lv_palette_main(LV_PALETTE_RED), LV_THEME_DEFAULT_DARK,
font_normal);
#endif
lv_style_init(&style_text_muted);
lv_style_set_text_opa(&style_text_muted, LV_OPA_50);
lv_style_init(&style_title);
lv_style_set_text_font(&style_title, font_large);
lv_style_init(&style_icon);
lv_style_set_text_color(&style_icon, lv_theme_get_color_primary(NULL));
lv_style_set_text_font(&style_icon, font_large);
lv_style_init(&style_bullet);
lv_style_set_border_width(&style_bullet, 0);
lv_style_set_radius(&style_bullet, LV_RADIUS_CIRCLE);
tv = lv_tabview_create(lv_scr_act(), LV_DIR_TOP, tab_h);
lv_obj_set_style_text_font(lv_scr_act(), font_normal, 0);
if(disp_size == DISP_LARGE) {
lv_obj_t * tab_btns = lv_tabview_get_tab_btns(tv);
lv_obj_set_style_pad_left(tab_btns, LV_HOR_RES / 2, 0);
lv_obj_t * logo = lv_img_create(tab_btns);
LV_IMG_DECLARE(img_lvgl_logo);
lv_img_set_src(logo, &img_lvgl_logo);
lv_obj_align(logo, LV_ALIGN_LEFT_MID, -LV_HOR_RES / 2 + 25, 0);
lv_obj_t * label = lv_label_create(tab_btns);
lv_obj_add_style(label, &style_title, 0);
lv_label_set_text(label, "LVGL v8");
lv_obj_align_to(label, logo, LV_ALIGN_OUT_RIGHT_TOP, 10, 0);
label = lv_label_create(tab_btns);
lv_label_set_text(label, "Widgets demo");
lv_obj_add_style(label, &style_text_muted, 0);
lv_obj_align_to(label, logo, LV_ALIGN_OUT_RIGHT_BOTTOM, 10, 0);
}
lv_obj_t * t1 = lv_tabview_add_tab(tv, "Profile");
lv_obj_t * t2 = lv_tabview_add_tab(tv, "Analytics");
lv_obj_t * t3 = lv_tabview_add_tab(tv, "Shop");
profile_create(t1);
analytics_create(t2);
shop_create(t3);
color_changer_create(tv);
} void lv_demo_benchmark(void)
{
benchmark_init();
/*Manually start scenes*/
next_scene_timer_cb(NULL);
} static void benchmark_init(void)
{
lv_disp_t * disp = lv_disp_get_default();
disp->driver->monitor_cb = monitor_cb;
/*Force to run at maximum frame rate*/
if(run_max_speed) {
if(disp->refr_timer) {
disp_ori_timer_period = disp->refr_timer->period;
lv_timer_set_period(disp->refr_timer, 1);
}
lv_timer_t * anim_timer = lv_anim_get_timer();
anim_ori_timer_period = anim_timer->period;
lv_timer_set_period(anim_timer, 1);
}
lv_obj_t * scr = lv_scr_act();
lv_obj_remove_style_all(scr);
lv_obj_set_style_bg_opa(scr, LV_OPA_COVER, 0);
title = lv_label_create(scr);
lv_obj_set_pos(title, LV_DPI_DEF / 30, LV_DPI_DEF / 30);
subtitle = lv_label_create(scr);
lv_obj_align_to(subtitle, title, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 0);
scene_bg = lv_obj_create(scr);
lv_obj_remove_style_all(scene_bg);
lv_obj_set_size(scene_bg, lv_obj_get_width(scr), lv_obj_get_height(scr) - subtitle->coords.y2 - LV_DPI_DEF / 30);
lv_obj_align(scene_bg, LV_ALIGN_BOTTOM_MID, 0, 0);
lv_style_init(&style_common);
lv_obj_update_layout(scr);
}
static void next_scene_timer_cb(lv_timer_t * timer)
{
LV_UNUSED(timer);
lv_obj_clean(scene_bg);
next_scene_timer = NULL;
if(opa_mode) {
if(scene_act >= 0) {
if(scenes[scene_act].time_sum_opa == 0) scenes[scene_act].time_sum_opa = 1;
scenes[scene_act].fps_opa = (1000 * scenes[scene_act].refr_cnt_opa) / scenes[scene_act].time_sum_opa;
if(scenes[scene_act].create_cb) scene_act++; /*If still there are scenes go to the next*/
}
else {
scene_act++;
}
opa_mode = false;
}
else {
if(scenes[scene_act].time_sum_normal == 0) scenes[scene_act].time_sum_normal = 1;
scenes[scene_act].fps_normal = (1000 * scenes[scene_act].refr_cnt_normal) / scenes[scene_act].time_sum_normal;
opa_mode = true;
}
if(scenes[scene_act].create_cb) {
lv_label_set_text_fmt(title, "%"LV_PRId32"/%"LV_PRId32": %s%s", scene_act * 2 + (opa_mode ? 1 : 0),
(int32_t)(dimof(scenes) * 2) - 2, scenes[scene_act].name, opa_mode ? " + opa" : "");
if(opa_mode) {
lv_label_set_text_fmt(subtitle, "Result of \"%s\": %"LV_PRId32" FPS", scenes[scene_act].name,
scenes[scene_act].fps_normal);
}
else {
if(scene_act > 0) {
lv_label_set_text_fmt(subtitle, "Result of \"%s + opa\": %"LV_PRId32" FPS", scenes[scene_act - 1].name,
scenes[scene_act - 1].fps_opa);
}
else {
lv_label_set_text(subtitle, "");
}
}
rnd_reset();
scenes[scene_act].create_cb();
next_scene_timer = lv_timer_create(next_scene_timer_cb, SCENE_TIME, NULL);
lv_timer_set_repeat_count(next_scene_timer, 1);
}
/*Ready*/
else {
/*Restore original frame rate*/
if(run_max_speed) {
lv_timer_t * anim_timer = lv_anim_get_timer();
lv_timer_set_period(anim_timer, anim_ori_timer_period);
lv_disp_t * disp = lv_disp_get_default();
lv_timer_t * refr_timer = _lv_disp_get_refr_timer(disp);
if(refr_timer) {
lv_timer_set_period(refr_timer, disp_ori_timer_period);
}
}
generate_report(); /* generate report */
}
}
demo函数无法运行,另一个函数可运行,为什么?