indeed, the example works
i tried to narrow it down, reduced my 4200 lines code to a minimum to demonstrate the issue.
It seems that only when a task handler is called within the main loop() function the screen is generated with the message box
here is some code, it creates a button, when clicked a messagebox is created, a delay of 2 seconds shows that even when i call the task handler in the function it does not work, after 2 seconds i go back to the main loop which basically calles task handler every 10 msec and the messagebox shows up, ofter 5 seconds more it is closed, that works
im lost as to why i cant get the messagebox to appear outside the main loop
#include “FS.h”
#include <SPI.h>
#include <lvgl.h>
#include <Ticker.h>
#include <TFT_eSPI.h>
#define LVGL_TICK_PERIOD 20
// touch screen calibration file
#define CALIBRATION_FILE “/calibData”
#define CS_LCD 15
#define CS_TOUCH 5
Ticker tick; /* timer for interrupt handler /
TFT_eSPI tft = TFT_eSPI(); / TFT instance */
static lv_disp_buf_t disp_buf;
static lv_color_t buf[LV_HOR_RES_MAX * LV_VER_RES_MAX / 10];
// touch screen calib
uint16_t calibrationData[5];
uint8_t calDataOK = 0;
// timers
unsigned long lvgl_timer;
unsigned long timer1;
/* Display flushing */
void my_disp_flush(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p)
{ uint32_t w = (area->x2 - area->x1 + 1);
uint32_t h = (area->y2 - area->y1 + 1);
tft.startWrite();
tft.setAddrWindow(area->x1, area->y1, w, h);
tft.pushColors(&color_p->full, w * h, true);
tft.endWrite();
lv_disp_flush_ready(disp);
}
/Read the touchpad/
bool my_touchpad_read(lv_indev_drv_t * indev_driver, lv_indev_data_t * data)
{
uint16_t touchX, touchY;
bool touched = tft.getTouch(&touchX, &touchY, 600);
if (!touched)
{
data->state = LV_INDEV_STATE_REL;
return false;
}
else
{
data->state = LV_INDEV_STATE_PR;
}
if (touchX > 480 || touchY > 320)
{
}
else
{
/Set the coordinates/
data->point.x = touchX;
data->point.y = touchY;
}
return false; /Return false
because we are not buffering and no more data to read/
}
/* Interrupt driven periodic handler */
static void lv_tick_handler(void)
{
lv_tick_inc(LVGL_TICK_PERIOD);
}
static lv_obj_t *tabview;
static lv_obj_t *tabmain;
static lv_obj_t *mbox;
static lv_style_t style_modal;
static lv_obj_t *obj;
boolean destroy = false;
void setup() {
Serial.begin(115200);
pinMode(CS_LCD, OUTPUT);
pinMode(CS_TOUCH, OUTPUT);
digitalWrite(CS_LCD, HIGH);
digitalWrite(CS_TOUCH, HIGH);
lv_init();
tft.init();
tft.setRotation(3); /* Landscape orientation */
// check file system
if (!SPIFFS.begin()) {
SPIFFS.format();
SPIFFS.begin();
}
// delay to settle pins
delay(250);
// check if calibration file exists
if (SPIFFS.exists(CALIBRATION_FILE)) {
File f = SPIFFS.open(CALIBRATION_FILE, “r”);
if (f) {
if (f.readBytes((char *)calibrationData, 14) == 14)
calDataOK = 1;
f.close();
}
}
if (calDataOK) {
// calibration data valid
tft.setTouch(calibrationData);
} else {
// data not valid. recalibrate
calibratescreen();
}
lv_disp_buf_init(&disp_buf, buf, NULL, (LV_HOR_RES_MAX * LV_VER_RES_MAX / 10));
/Initialize the display/
lv_disp_drv_t disp_drv;
lv_disp_drv_init(&disp_drv);
disp_drv.hor_res = 480;
disp_drv.ver_res = 320;
disp_drv.flush_cb = my_disp_flush;
disp_drv.buffer = &disp_buf;
lv_disp_drv_register(&disp_drv);
/Initialize the (dummy) input device driver/
lv_indev_drv_t indev_drv;
lv_indev_drv_init(&indev_drv);
indev_drv.type = LV_INDEV_TYPE_POINTER;
indev_drv.read_cb = my_touchpad_read;
lv_indev_drv_register(&indev_drv);
/Initialize the graphics library’s tick/
tick.attach_ms(LVGL_TICK_PERIOD, lv_tick_handler);
setupscreens();
lv_style_init(&style_modal);
lv_style_set_bg_color(&style_modal, LV_STATE_DEFAULT, LV_COLOR_BLACK);
lvgl_timer = millis() - 200;
timer1 = millis();
}
void loop() {
if (destroy) {
if (millis() >= timer1 + 5000) {
delete_box();
destroy = false;
}
}
if (millis() >= lvgl_timer + 10) {
lv_task_handler();
lvgl_timer = millis();
}
}
void setupscreens(void) {
// tabs
tabview = lv_tabview_create(lv_scr_act(), NULL);
tabmain = lv_tabview_add_tab(tabview, “”);
lv_tabview_set_btns_pos(tabview, LV_TABVIEW_TAB_POS_NONE);
// main screen
lv_obj_t * btn10 = lv_btn_create(tabmain, NULL);
lv_obj_set_event_cb(btn10, event_test1);
lv_obj_t * label = lv_label_create(btn10, NULL);
lv_label_set_text(label, “test 1”);
lv_obj_set_width(btn10, 140);
lv_obj_set_height(btn10, 55);
lv_obj_align(btn10, NULL, LV_ALIGN_IN_TOP_LEFT, 10, 10);
}
static void event_test1(lv_obj_t * obj, lv_event_t event) {
if (event == LV_EVENT_CLICKED ) {
create_box();
timer1 = millis();
}
}
static void event_calibrate(lv_obj_t * obj, lv_event_t event)
{
if (event == LV_EVENT_CLICKED) {
calibratescreen();
lv_obj_invalidate(lv_scr_act());
}
}
void calibratescreen(void)
{
// clear screen
tft.fillScreen(0xFFFFFF);
tft.calibrateTouch(calibrationData, TFT_WHITE, TFT_RED, 15);
// store data
File f = SPIFFS.open(CALIBRATION_FILE, “w”);
if (f) {
f.write((const unsigned char *)calibrationData, 14);
f.close();
}
}
static void create_box(void) {
obj = lv_obj_create(lv_scr_act(), NULL);
lv_obj_reset_style_list(obj, LV_OBJ_PART_MAIN);
lv_obj_add_style(obj, LV_OBJ_PART_MAIN, &style_modal);
lv_obj_set_pos(obj, 0, 0);
lv_obj_set_size(obj, LV_HOR_RES, LV_VER_RES);
mbox = lv_msgbox_create(obj, NULL);
lv_msgbox_set_text(mbox, “Busy…”);
lv_obj_align(mbox, NULL, LV_ALIGN_CENTER, 0, 0);
lv_obj_invalidate(lv_scr_act());
lv_task_handler();
destroy = true;
delay(2000);
timer1 = millis();
}
static void delete_box(void) {
lv_obj_del_async(lv_obj_get_parent(mbox));
mbox = NULL; /* happens before object is actually deleted! */
}