磊磊映画 发表于 2022-6-6 07:34:36

请教: 大神帮忙看看 LVGL 8.0 表盘设置动态刷新导致重启

平台:esp32platformio 加插件方式开发arduino    esp32 导入了LVGL 8.0
         
arduino 这里使用C++ 开发的 搞起来非常不方便,很多函数不知道如何调用。


现在打算用LVGL 做个车速表盘,用lv_meter 的demo 跑起来,但是demo只初始化一次就用动画方式无线刷新表盘了。

实际用起来需要函数调用周期性刷新的 所以 将 动态刷新部分抽象出了一个函数供外部调用,就是这个接口 TemplateView::Screen_update(int speed)

这个接口放到TemplateView 文件中 初始化部分调用 是能够正常显示的,说明函数功能正常的。


但是把这个接口放到

/*2022-6-5 19:07:31
**共外部调用
**
*/
void TemplateView::Screen_update(int speed)
{

   
    static int pre_value =0;
        TemplateView* instance = (TemplateView*)timer->user_data;
   
    Serial.println(speed);
    /*2022年6月5日 20:15:34
    **全注释掉这里就不重启了
    **
    */
    #if    0
    if(speed>1)
    {
      lv_anim_init(&a);
      lv_anim_set_exec_cb(&a,set_value);
      lv_anim_set_var(&a, indic);
      lv_anim_set_values(&a, pre_value, speed);
      Serial.println(pre_value);
      
      lv_anim_set_time(&a, 100);
      lv_anim_set_path_cb(&a, &lv_anim_path_overshoot); /* 设置路径(曲线) */
      lv_anim_start(&a);
      pre_value = speed;
    }
   
    #endif
       
      
}





外部文件 Template调用时 不注释 lv_meter 相关代码(#if 0注释部分)就会重启, 注释掉lv_meter 就不会重启,说明lv_meter 相关代码导致的重启。

请大神帮忙定位原因,是不是lv_meter 不能放到别的文件里去调用? 为什么一执行就重启?主要还是想通过外部的速度去刷新表盘指针。




崩溃时捕获的日志:
meter

50
Guru Meditation Error: Core0 panic'ed (StoreProhibited). Exception was unhandled.

Core0 register dump:
PC      : 0x40152bc8PS      : 0x00060a30A0      : 0x800e7724A1      : 0x3fff4200
A2      : 0x00000000A3      : 0x00000044A4      : 0x0000000aA5      : 0x00000000
A6      : 0x00ff0000A7      : 0xff000000A8      : 0x00000000A9      : 0x00000020
A10   : 0x00000002A11   : 0x3f4594dcA12   : 0xcc88035fA13   : 0x3ffc611c
A14   : 0x00ff0000A15   : 0xff000000SAR   : 0x0000000aEXCCAUSE: 0x0000001d
EXCVADDR: 0x00000000LBEG    : 0x400917adLEND    : 0x400917bdLCOUNT: 0xffffffff


Backtrace:0x40152bc5:0x3fff42000x400e7721:0x3fff4220 0x400d477c:0x3fff4240 0x400d44db:0x3fff4260 0x400e9d5a:0x3fff4280 0x400d8204:0x3fff42b0





外部调用:

void Template::onTimerUpdate(lv_timer_t* timer)
{
        Template* instance = (Template*)timer->user_data;
    TemplateView* screen;

    static int   i =0;

    ///Serial.println("update\r\n");
    if(0==i%2)
    {
         instance->Update();
         Serial.println("num\r\n");
    }
    if(1==i%2)
    {
      
             Serial.println("meter\r\n");
         screen->Screen_update(50);
   
    }
    i++;
   
}
























#include "TemplateView.h"
#include "App/Configs/Version.h"
#include "lvgl.h"
///#include "src/widgets/lv_gauge.h"



using namespace Page;




static lv_obj_t * meter;

static void set_value(void * indic, int32_t v)
{
    lv_meter_set_indicator_end_value(meter, (lv_meter_indicator_t *)indic, v);
}


/*2022-6-5 19:07:31zhanglei
**共外部调用
**
*/
void TemplateView::Screen_update(int speed)
{

   
    static int pre_value =0;
        TemplateView* instance = (TemplateView*)timer->user_data;
   
    Serial.println(speed);
    /*2022年6月5日 20:15:34zhanglei
    **全注释掉这里就不重启了
    **
    */
    #if    0
    if(speed>1)
    {
      lv_anim_init(&a);
      lv_anim_set_exec_cb(&a,set_value);
      lv_anim_set_var(&a, indic);
      lv_anim_set_values(&a, pre_value, speed);
      Serial.println(pre_value);
      
      lv_anim_set_time(&a, 100);
      lv_anim_set_path_cb(&a, &lv_anim_path_overshoot); /* 设置路径(曲线) */
      lv_anim_start(&a);
      pre_value = speed;
    }
   
    #endif
       
      
}

/*2022-6-5 19:07:31zhanglei
**共外部调用
**
*/
void TemplateView::Screen_update2(lv_timer_t* timer)
{

   
    static int pre_value =0;
        TemplateView* instance = (TemplateView*)timer->user_data;
   
    //Serial.println(speed);
    /*2022年6月5日 20:15:34zhanglei
    **全注释掉这里就不重启了
    **
    */
    #if    0
    if(speed>1)
    {
      lv_anim_init(&a);
      lv_anim_set_exec_cb(&a,set_value);
      lv_anim_set_var(&a, indic);
      lv_anim_set_values(&a, pre_value, speed);
      Serial.println(pre_value);
      
      lv_anim_set_time(&a, 100);
      lv_anim_set_path_cb(&a, &lv_anim_path_overshoot); /* 设置路径(曲线) */
      lv_anim_start(&a);
      pre_value = speed;
    }
   
    #endif
       
      
}


/*2022-6-4 15:08:58
** 速度界面控件
**
*/
void TemplateView::TopInfo_Create(lv_obj_t* par)
{   
    #if1
   
    lv_obj_t* cont = lv_obj_create(par);
    lv_obj_remove_style_all(cont);
    lv_obj_set_size(cont, LV_HOR_RES, 142);
    #if    1
    /*2022-6-4 21:44:03zhanglei
    **方便两层叠加 改成透明处理
    **
    */
    lv_obj_set_style_bg_opa(cont, LV_OPA_TRANSP   , 0);//改成半透明
    lv_obj_set_style_bg_color(cont, lv_color_hex(0x333333), 0);

    lv_obj_set_style_radius(cont, 27, 0);
    lv_obj_set_y(cont, -36);
    ui.topInfo.cont = cont;

    lv_obj_t* label = lv_label_create(cont);
    lv_obj_set_style_text_font(label, Resource.GetFont("bahnschrift_65"), 0);
    lv_obj_set_style_text_color(label, lv_color_white(), 0);
    lv_label_set_text(label, "00");
    lv_obj_align(label, LV_ALIGN_TOP_MID, 0, 83);
    ui.topInfo.labelSpeed = label;
    #endif
    #if    0
    label = lv_label_create(cont);
    lv_obj_set_style_text_font(label, Resource.GetFont("bahnschrift_17"), 0);
    lv_obj_set_style_text_color(label, lv_color_white(), 0);
    lv_label_set_text(label, "km/h");
    lv_obj_align_to(label, ui.topInfo.labelSpeed, LV_ALIGN_OUT_BOTTOM_MID, 0, 8);
    ui.topInfo.labelUint = label;
    #endif
    #endif

    #defineSTANDARD

    #ifdefSTANDARD
    meter = lv_meter_create(lv_scr_act());
    lv_obj_center(meter);
    lv_obj_set_size(meter, 200, 200);

    /*Add a scale first*/
    lv_meter_scale_t * scale = lv_meter_add_scale(meter);
    lv_meter_set_scale_ticks(meter, scale, 41, 2, 10, lv_palette_main(LV_PALETTE_GREY));
    lv_meter_set_scale_major_ticks(meter, scale, 8, 4, 15, lv_color_black(), 10);

   

    /*Add a blue arc to the start*/
    indic = lv_meter_add_arc(meter, scale, 5, lv_palette_main(LV_PALETTE_BLUE), 0);
    lv_meter_set_indicator_start_value(meter, indic, 0);
    lv_meter_set_indicator_end_value(meter, indic, 20);

    /*Make the tick lines blue at the start of the scale*/
    indic = lv_meter_add_scale_lines(meter, scale, lv_palette_main(LV_PALETTE_BLUE), lv_palette_main(LV_PALETTE_BLUE),
                                     false, 0);
    lv_meter_set_indicator_start_value(meter, indic, 0);
    lv_meter_set_indicator_end_value(meter, indic, 70);

    /*Add a red arc to the end*/
    indic = lv_meter_add_arc(meter, scale, 5, lv_palette_main(LV_PALETTE_RED), 0);
    lv_meter_set_indicator_start_value(meter, indic, 70);
    lv_meter_set_indicator_end_value(meter, indic, 100);

    /*Make the tick lines red at the end of the scale*/
    indic = lv_meter_add_scale_lines(meter, scale, lv_palette_main(LV_PALETTE_RED), lv_palette_main(LV_PALETTE_RED), false,
                                     0);
    lv_meter_set_indicator_start_value(meter, indic, 70);
    lv_meter_set_indicator_end_value(meter, indic, 100);

    /*Add a needle line indicator*/
    indic = lv_meter_add_needle_line(meter, scale, 4, lv_palette_main(LV_PALETTE_ORANGE), -10);
    #endif


    #if0
    /*Create an animation to set the value*/
    lv_anim_init(&a);
    lv_anim_set_exec_cb(&a,set_value);
    lv_anim_set_var(&a, indic);
    lv_anim_set_values(&a, 0, 40);
    lv_anim_set_time(&a, 2000);
    lv_anim_set_path_cb(&a, &lv_anim_path_overshoot); /* 设置路径(曲线) */
    lv_anim_start(&a);
   

    //Screen_update(100);
   

    #else
    lv_anim_t a;
    lv_anim_init(&a);
    lv_anim_set_exec_cb(&a, set_value);
    lv_anim_set_var(&a, indic);
    lv_anim_set_values(&a, 0, 100);
    lv_anim_set_time(&a, 2000);
    lv_anim_set_repeat_delay(&a, 100);
    lv_anim_set_playback_time(&a, 500);
    lv_anim_set_playback_delay(&a, 100);
    lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINITE);
    lv_anim_start(&a);
   
    #endif

    #ifdef    MIDDLE_LEVEL
   meter = lv_meter_create(lv_scr_act());
    lv_obj_center(meter);
    lv_obj_set_size(meter, 200, 200);

    /*Remove the circle from the middle*/
    lv_obj_remove_style(meter, NULL, LV_PART_INDICATOR);

    /*Add a scale first*/
    lv_meter_scale_t * scale = lv_meter_add_scale(meter);
    lv_meter_set_scale_ticks(meter, scale, 11, 2, 10, lv_palette_main(LV_PALETTE_GREY));
    lv_meter_set_scale_major_ticks(meter, scale, 1, 2, 30, lv_color_hex3(0xeee), 15);
    lv_meter_set_scale_range(meter, scale, 0, 100, 270, 90);

    /*Add a three arc indicator*/
    lv_meter_indicator_t * indic1 = lv_meter_add_arc(meter, scale, 10, lv_palette_main(LV_PALETTE_RED), 0);
    lv_meter_indicator_t * indic2 = lv_meter_add_arc(meter, scale, 10, lv_palette_main(LV_PALETTE_GREEN), -10);
    lv_meter_indicator_t * indic3 = lv_meter_add_arc(meter, scale, 10, lv_palette_main(LV_PALETTE_BLUE), -20);

    /*Create an animation to set the value*/
    lv_anim_t a;
    lv_anim_init(&a);
    lv_anim_set_exec_cb(&a, set_value);
    lv_anim_set_values(&a, 0, 100);
    lv_anim_set_repeat_delay(&a, 100);
    lv_anim_set_playback_delay(&a, 100);
    lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINITE);

    lv_anim_set_time(&a, 2000);
    lv_anim_set_playback_time(&a, 500);
    lv_anim_set_var(&a, indic1);
    lv_anim_start(&a);

    lv_anim_set_time(&a, 1000);
    lv_anim_set_playback_time(&a, 1000);
    lv_anim_set_var(&a, indic2);
    lv_anim_start(&a);

    lv_anim_set_time(&a, 1000);
    lv_anim_set_playback_time(&a, 2000);
    lv_anim_set_var(&a, indic3);
    lv_anim_start(&a);
    #endif


}

void TemplateView::BottomInfo_Create(lv_obj_t* par)
{
    lv_obj_t* cont = lv_obj_create(par);
    lv_obj_remove_style_all(cont);
    lv_obj_set_style_bg_color(cont, lv_color_black(), 0);
    lv_obj_set_size(cont, LV_HOR_RES, 90);
    lv_obj_align(cont, LV_ALIGN_TOP_MID, 0, 106);

    lv_obj_set_flex_flow(cont, LV_FLEX_FLOW_ROW_WRAP);

    lv_obj_set_flex_align(
      cont,
      LV_FLEX_ALIGN_SPACE_EVENLY,
      LV_FLEX_ALIGN_CENTER,
      LV_FLEX_ALIGN_CENTER
    );

    ui.bottomInfo.cont = cont;

    const char* unitText =
    {
      "AVG",
      "Time",
      "Trip",
      "Calorie"
    };

    for (int i = 0; i < ARRAY_SIZE(ui.bottomInfo.labelInfoGrp); i++)
    {
      SubInfoGrp_Create(
            cont,
            &(ui.bottomInfo.labelInfoGrp),
            unitText
      );
    }
}

void TemplateView::SubInfoGrp_Create(lv_obj_t* par, SubInfo_t* info, const char* unitText)
{
    lv_obj_t* cont = lv_obj_create(par);
    lv_obj_remove_style_all(cont);
    lv_obj_set_size(cont, 93, 39);

    lv_obj_set_flex_flow(cont, LV_FLEX_FLOW_COLUMN);
    lv_obj_set_flex_align(
      cont,
      LV_FLEX_ALIGN_SPACE_AROUND,
      LV_FLEX_ALIGN_CENTER,
      LV_FLEX_ALIGN_CENTER
    );

    lv_obj_t* label = lv_label_create(cont);
    lv_obj_set_style_text_font(label, Resource.GetFont("bahnschrift_17"), 0);
    lv_obj_set_style_text_color(label, lv_color_white(), 0);
    info->lableValue = label;

    label = lv_label_create(cont);
    lv_obj_set_style_text_font(label, Resource.GetFont("bahnschrift_13"), 0);
    lv_obj_set_style_text_color(label, lv_color_hex(0xb3b3b3), 0);
    lv_label_set_text(label, unitText);
    info->lableUnit = label;

    info->cont = cont;
}

void TemplateView::BtnCont_Create(lv_obj_t* par)
{
    lv_obj_t* cont = lv_obj_create(par);
    lv_obj_remove_style_all(cont);
    lv_obj_set_size(cont, LV_HOR_RES, 40);
    lv_obj_align_to(cont, ui.bottomInfo.cont, LV_ALIGN_OUT_BOTTOM_MID, 0, 0);

    /*lv_obj_set_flex_flow(cont, LV_FLEX_FLOW_ROW);
    lv_obj_set_flex_place(
      cont,
      LV_FLEX_PLACE_SPACE_AROUND,
      LV_FLEX_PLACE_CENTER,
      LV_FLEX_PLACE_CENTER
    );*/

    ui.btnCont.cont = cont;

    ui.btnCont.btnMap = Btn_Create(cont, Resource.GetImage("locate"), -80);
    ui.btnCont.btnRec = Btn_Create(cont, Resource.GetImage("start"), 0);
    ui.btnCont.btnMenu = Btn_Create(cont, Resource.GetImage("menu"), 80);
}

lv_obj_t* TemplateView::Btn_Create(lv_obj_t* par, const void* img_src, lv_coord_t x_ofs)
{
    lv_obj_t* obj = lv_obj_create(par);
    lv_obj_remove_style_all(obj);
    lv_obj_set_size(obj, 40, 31);
    lv_obj_clear_flag(obj, LV_OBJ_FLAG_SCROLLABLE);

    lv_obj_align(obj, LV_ALIGN_CENTER, x_ofs, 0);
    lv_obj_set_style_bg_img_src(obj, img_src, 0);

    lv_obj_set_style_bg_opa(obj, LV_OPA_COVER, 0);
    lv_obj_set_style_width(obj, 45, LV_STATE_PRESSED);
    lv_obj_set_style_height(obj, 25, LV_STATE_PRESSED);
    lv_obj_set_style_bg_color(obj, lv_color_hex(0x666666), 0);
    lv_obj_set_style_bg_color(obj, lv_color_hex(0xbbbbbb), LV_STATE_PRESSED);
    lv_obj_set_style_bg_color(obj, lv_color_hex(0xff931e), LV_STATE_FOCUSED);
    lv_obj_set_style_radius(obj, 9, 0);

    static lv_style_transition_dsc_t tran;
    static const lv_style_prop_t prop[] = { LV_STYLE_WIDTH, LV_STYLE_HEIGHT, LV_STYLE_PROP_INV};
    lv_style_transition_dsc_init(
      &tran,
      prop,
      lv_anim_path_ease_out,
      200,
      0,
      nullptr
    );
    lv_obj_set_style_transition(obj, &tran, LV_STATE_PRESSED);
    lv_obj_set_style_transition(obj, &tran, LV_STATE_FOCUSED);

    lv_obj_update_layout(obj);

    return obj;
}

void TemplateView::AppearAnimStart(bool reverse)
{
    lv_anim_timeline_set_reverse(ui.anim_timeline, reverse);
    lv_anim_timeline_start(ui.anim_timeline);
}
void TemplateView::onViewWillAppear()
{

   /// timer = lv_timer_create((lv_timer_cb_t)Screen_update2(), 500, this);

   

}

void TemplateView::Create(lv_obj_t* root)
{
        #if       1
        lv_obj_t* label = lv_label_create(root);
        lv_obj_set_style_text_font(label, &lv_font_montserrat_14, 0);
        lv_obj_set_style_text_color(label, lv_color_white(), 0);
        lv_obj_align(label, LV_ALIGN_TOP_MID, 0, 30);
        lv_label_set_text(label, "");
        ui.labelTitle = label;

        label = lv_label_create(root);
        lv_obj_set_style_text_font(label, &lv_font_montserrat_10, 0);
        lv_obj_set_style_text_color(label, lv_color_white(), 0);
        lv_label_set_text(label, "");
        lv_obj_align(label, LV_ALIGN_TOP_MID, 0, 50);
        ui.labelTick = label;

        lv_obj_t* img = lv_img_create(root);
        ///lv_img_set_src(img, Resource.GetImage("arm"));
        ///lv_obj_center(img);
        BottomInfo_Create(root);
    TopInfo_Create(root);
    BtnCont_Create(root);

        ui.canvas = img;

        ui.group = lv_group_create();
        lv_indev_set_group(lv_get_indev(LV_INDEV_TYPE_ENCODER), ui.group);

        lv_group_add_obj(ui.group, ui.canvas);
        lv_group_add_obj(ui.group, ui.labelTitle);
        lv_group_focus_obj(ui.canvas);


   
    /*
    **2022-6-4 10:09:09 zhanglei
    **add
    */
    #if1
   ui.anim_timeline = lv_anim_timeline_create();

#define ANIM_DEF(start_time, obj, attr, start, end) \
    {start_time, obj, LV_ANIM_EXEC(attr), start, end, 500, lv_anim_path_ease_out, true}

#define ANIM_OPA_DEF(start_time, obj) \
    ANIM_DEF(start_time, obj, opa_scale, LV_OPA_TRANSP, LV_OPA_COVER)

    lv_coord_t y_tar_top = lv_obj_get_y(ui.topInfo.cont);
    lv_coord_t y_tar_bottom = lv_obj_get_y(ui.bottomInfo.cont);
    lv_coord_t h_tar_btn = lv_obj_get_height(ui.btnCont.btnRec);

    lv_anim_timeline_wrapper_t wrapper[] =
    {
      ANIM_DEF(0, ui.topInfo.cont, y, -lv_obj_get_height(ui.topInfo.cont), y_tar_top),

      ANIM_DEF(200, ui.bottomInfo.cont, y, -lv_obj_get_height(ui.bottomInfo.cont), y_tar_bottom),
      ANIM_OPA_DEF(200, ui.bottomInfo.cont),

      ANIM_DEF(500, ui.btnCont.btnMap, height, 0, h_tar_btn),
      ANIM_DEF(600, ui.btnCont.btnRec, height, 0, h_tar_btn),
      ANIM_DEF(700, ui.btnCont.btnMenu, height, 0, h_tar_btn),
      LV_ANIM_TIMELINE_WRAPPER_END
    };
    lv_anim_timeline_add_wrapper(ui.anim_timeline, wrapper);



   
   
   
    #endif

        Serial.println("templateview init");

   




    #else

    lv_obj_remove_style_all(root);
    lv_obj_set_size(root, LV_HOR_RES, LV_VER_RES);

    BottomInfo_Create(root);
    TopInfo_Create(root);
    BtnCont_Create(root);

    ui.anim_timeline = lv_anim_timeline_create();

#define ANIM_DEF(start_time, obj, attr, start, end) \
    {start_time, obj, LV_ANIM_EXEC(attr), start, end, 500, lv_anim_path_ease_out, true}

#define ANIM_OPA_DEF(start_time, obj) \
    ANIM_DEF(start_time, obj, opa_scale, LV_OPA_TRANSP, LV_OPA_COVER)

    lv_coord_t y_tar_top = lv_obj_get_y(ui.topInfo.cont);
    lv_coord_t y_tar_bottom = lv_obj_get_y(ui.bottomInfo.cont);
    lv_coord_t h_tar_btn = lv_obj_get_height(ui.btnCont.btnRec);

    lv_anim_timeline_wrapper_t wrapper[] =
    {
      ANIM_DEF(0, ui.topInfo.cont, y, -lv_obj_get_height(ui.topInfo.cont), y_tar_top),

      ANIM_DEF(200, ui.bottomInfo.cont, y, -lv_obj_get_height(ui.bottomInfo.cont), y_tar_bottom),
      ANIM_OPA_DEF(200, ui.bottomInfo.cont),

      ANIM_DEF(500, ui.btnCont.btnMap, height, 0, h_tar_btn),
      ANIM_DEF(600, ui.btnCont.btnRec, height, 0, h_tar_btn),
      ANIM_DEF(700, ui.btnCont.btnMenu, height, 0, h_tar_btn),
      LV_ANIM_TIMELINE_WRAPPER_END
    };
    lv_anim_timeline_add_wrapper(ui.anim_timeline, wrapper);


        #endif
}

磊磊映画 发表于 2022-6-6 07:47:17

完整工程传到百度网盘了链接:https://pan.baidu.com/s/1Lq_h9PJn18XtXFMJoD8-Dw提取码:3z7f

磊磊映画 发表于 2022-6-6 16:40:50

顶一下有没有

嵌入之梦2 发表于 2023-2-5 21:03:31

请问楼主问题解决了吗?最近我使用ESP 32 移植lvgl gui刷屏一段时间后会死机,不知道问题出在哪?
页: [1]
查看完整版本: 请教: 大神帮忙看看 LVGL 8.0 表盘设置动态刷新导致重启