My app keep crashing when I call a screen change from a bluetooth write function. The central sends a message to the peripheral. The peripheral wakes up the display and tries to show a lvgl screen with a single label. I see it for a second. I keep thinking I need a message queue or a different thread for the display. I can try a few things but didn't want to guess.
This is the write callback on the peripheral:
static ssize_t write_vnd(struct bt_conn *conn, const struct bt_gatt_attr *attr, const void *buf, uint16_t len, uint16_t offset, uint8_t flags) { //this means a write has happened to the peripheral, the controller has written uint8_t *value = attr->user_data; if (offset + len > VND_MAX_LEN) { return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); } memcpy(value + offset, buf, len); value[offset + len] = 0; screenmanager_show_token(); eventhandler_reset(); return len; }
it calls the:
void screenmanager_show_token() { //clear the current screen and show the next lv_obj_clean(lv_scr_act()); screen_token_init(); }
which is just:
void screen_token_init() { lv_obj_t *token_label; token_label = lv_label_create(lv_scr_act()); lv_label_set_text(token_label, "Hello World"); lv_obj_align(token_label, LV_ALIGN_TOP_MID, 0, 0); }