先附上代码
程序需求是想通过串口传入数据,进而实现事件触发的效果。
/*回调函数*/
static void scr_event(lv_event_t *e)
{
lv_obj_t * label = (lv_obj_t*)lv_event_get_user_data(e);
Serial.print("callback is ok");
lv_label_set_text(label, "OPEN");
}
void set_caiya_gui(void)
{
/*屏幕1*/
scr1 = lv_obj_create(lv_scr_act());//在默认屏幕上创建屏幕1
lv_obj_set_style_bg_color(scr1,lv_color_hex(0xeeffcc), LV_STATE_DEFAULT);
lv_obj_set_size(scr1, LV_HOR_RES, LV_VER_RES);// 设置到屏幕大小
//设置按钮
lv_obj_t* label = lv_label_create(scr1); // 创建label
lv_obj_align(label, LV_ALIGN_CENTER, 0, 0); // label居屏幕中心对齐
lv_label_set_text(label, "ONE"); // label显示ONE
lv_obj_add_event_cb(scr1, scr_event, LV_EVENT_CLICKED, label);
}
void setup()
{
tft.init(); //初始化
mylvglinit(); //LVGL初始化
set_caiya_gui();
Serial.begin(115200);
}
void loop()
{
lv_timer_handler(); /* let the GUI do its work */
delay(5);
if(Serial.available())
{
rev=Serial.read();
Serial.print("rev=");
Serial.println(rev);
//lv_event_send(scr1,LV_EVENT_CLICKED,scr2);
if(rev == 'a')
{
//手动发送事件到对象
lv_event_send(scr1,LV_EVENT_CLICKED,NULL);
}
}
}
问题可以聚焦在回调函数中
static void scr_event(lv_event_t *e)
{
lv_obj_t * label = (lv_obj_t*)lv_event_get_user_data(e);
Serial.print("callback is ok");
lv_label_set_text(label, "OPEN");
}
//这里是将label写成"OPEN",但是没效果,但是Serial.print("callback is ok");可以输出
不知道问题出在哪里,各位麻烦解答一下/(ㄒoㄒ)/~~
环境是VScode+platformIO
[env:esp32dev
platform espressif32
board esp32dev
framework arduino
lib deps
bodmer/TFT eSPI@2.5.36
1vgl/1vg1@8.3.7