I am trying to use LVGL with pros c++. Anything that I try causes either nothing to show up on the robot brain or a memory permission error will occur. I even tried to use the example programs provided with LVGL but all I got was a memory permission error. I know that there should be nothing wrong with the code because it works in the LVGL pcsimulator. Can anyone explain how to get LVGL to display on the robot brain?
I’ve also been having this issue. Strangely enough, I had a LVGL program that ran consistently through PROS C++ that will no longer run on the brain without a memory permission error. This seems unprecedented since I didn’t really make any changes to the program that would have caused this to happen. I tried reverting to an earlier version of the program and testing the code on another teams’ brain. Nothing seems to work. This only happened today as well, and I had no issues last week with the same program.
Just one thing to check that we experienced: if you are running any tasks, make sure they have a sleep in them. We had a sleep get deleted out of a task and that caused the lvgl stuff to stop displaying. Once it got added back, it started working fine again.
I don’t have (disallowed by team) access to the brain the week before a tournament so I can’t try anything until Sunday. I know we have LVGL working on Kernel version 3.1.4 and earlier, I don’t know if we updated to 3.1.5 (released Jan 7).
Maybe @edjubuh can shed some light on this.
It’s kind of hard to say what’s going wrong without actually looking at the code.
A couple things to watch out for:
- @creatorthomas mentioned this, but make sure you’re not starving the LVGL task. The task that tells LVGL to render updates runs at a fairly low priority, so if you have tasks at any higher priority that do not yield (aka delay), you have a very good chance of making sure no updates happen.
- start very small and work your way up. I’ve had a few issues myself when working on testing LVGL, and generally my solutions have involved tearing down the complex test I’ve written in one shot and building it back up component by component.
I’ve seen a number of people reporting difficulties in getting started with LVGL, and for that I apologise. Hopefully by the end of this weekend I’ll get my v5 back, and I’ll be able to make a few example programs that can be used as a foundation.
In the meantime, you can check out LLEMU’s source code for a little bit of inspiration. It’s a little complex, but the basic elements are all there in one form or another.
Edit:
For what it’s worth, we haven’t made any significant changes that should impact this (and if LLEMU runs, other LVGL things should run as well), but I’ll verify this weekend.
I got access to a brain and bat. I saw the same exception and looked through the code again. I forgot to remove the LCD calls from opcontrol. Once I removed them the lvgl gui displayed. So make sure you remove all referenced to the emulated LCD.
Here is the code that works adopted from the LVGL button example.
gui.h
#ifndef GUI_H
#define GUI_H
//extern int auton_sel;
void gui(void);
#endif // GUI_H
gui.cpp
#include "gui.h"
#include "main.h"
#include <stdlib.h>
static lv_res_t btn_click_action(lv_obj_t * btn)
{
static lv_obj_t *label = lv_label_create(lv_scr_act(), NULL);
uint8_t id = lv_obj_get_free_num(btn);
char mytext[64];
sprintf(mytext, "Button %d is released\n", id);
lv_label_set_text(label, mytext);
lv_obj_align(label, NULL, LV_ALIGN_IN_BOTTOM_MID, 0, 5);
/* The button is released.
* Make something here */
return LV_RES_OK; /*Return OK if the button is not deleted*/
}
void gui(void) {
/*Create a title label*/
lv_obj_t *label = lv_label_create(lv_scr_act(), NULL);
lv_label_set_text(label, "Select a Button");
lv_obj_align(label, NULL, LV_ALIGN_IN_TOP_MID, 0, 0);
/*Create a normal button*/
static lv_obj_t *btn1 = lv_btn_create(lv_scr_act(), NULL);
lv_cont_set_fit(btn1, true, true); /*Enable resizing horizontally and vertically*/
lv_obj_align(btn1, NULL, LV_ALIGN_IN_LEFT_MID, 0, 0);
lv_obj_set_free_num(btn1, 1); /*Set a unique number for the button*/
lv_btn_set_action(btn1, LV_BTN_ACTION_CLICK, btn_click_action);
/*Add a label to the button*/
label = lv_label_create(btn1, NULL);
lv_label_set_text(label, "Choice 1");
/*Copy the button and set toggled state. (The release action is copied too)*/
static lv_obj_t *btn2 = lv_btn_create(lv_scr_act(), btn1);
lv_obj_align(btn2, NULL, LV_ALIGN_CENTER, 0, 0);
// lv_btn_set_state(btn2, LV_BTN_STATE_TGL_REL); /*Set toggled state*/
lv_obj_set_free_num(btn2, 2); /*Set a unique number for the button*/
lv_btn_set_action(btn2, LV_BTN_ACTION_CLICK, btn_click_action);
/*Add a label to the toggled button*/
label = lv_label_create(btn2, NULL);
lv_label_set_text(label, "Choice 2");
/*Copy the button and set inactive state.*/
static lv_obj_t *btn3 = lv_btn_create(lv_scr_act(), btn1);
lv_obj_align(btn3, NULL, LV_ALIGN_IN_RIGHT_MID, 0, 10);
//lv_btn_set_state(btn3, LV_BTN_STATE_INA); /*Set inactive state*/
lv_obj_set_free_num(btn3, 3); /*Set a unique number for the button*/
lv_btn_set_action(btn3, LV_BTN_ACTION_CLICK, btn_click_action);
/*Add a label to the inactive button*/
label = lv_label_create(btn3, NULL);
lv_label_set_text(label, "Choice 3");
}