Need help with putting together different parts of my LVGL code

So I used LVGL to create a bunch a different things for our robot. Here are the three things that my code is supposed to do:

  1. An auton selector where you can click on a button corresponding to the auton
  2. A pop-up that confirms the auton choice
  3. Displays team logo at the start of opcontrol() (uses a c array)

I can get part 1 and part 2 to work properly, but then part three doesn’t work. The opposite is also true; I can get part 3 to work but not without commenting out part 1 and part 2. I attached my code as a zip file because there are too many lines to put into this post. Also, I only attached the relevant code and stripped the files of our normal drive code.

Disclaimers about my code:

  • the code is very hastily done and probably isn’t efficient
  • some of the variables don’t do anything or are misnomers (eg. blueBack doesn’t always have a blue background) => it’s a byproduct of hastily written code (266.1 KB)

 * Runs initialization code. This occurs as soon as the program is started.
 * All other competition modes are blocked by initialize; it is recommended
 * to keep execution time for this mode under a few seconds.
void initialize() {
	pros::Task autonSel(autonSelector, (void*)"PROS", TASK_PRIORITY_DEFAULT, TASK_STACK_DEPTH_DEFAULT, "Auton Selector");
	while (getComplete() == 0) {
		printf("this is auton id %d, & complete %d\n", getAutonId(), getComplete());
	printf("THIS IS AUTON #: %d", getAutonId());
	pros::Task delTask(autonSel);

Here are my ideas on why it might not be working…

When you say part three doesn’t work, are you sure initialize function is done running.

All other competition modes are blocked by initialize

You have a while loop, so is it possible that that this loop is still running and so the opcontrol function never starts.

What is pros::Task delTask(autonSel); supposed to mean? That would not be how you delete a task, instead you are just creating another one.

It is possible that your program…

  • creates the new task
  • opcontrol runs
  • and then the function autonSelector runs replacing the screen object

Also you do not need to use a task for the autonSelector function.


I made a task for the auton selector because I thought that it was somehow interfering with the code in opcontrol(), so I wanted a way to stop it for sure.

I think that you’re right; I wasn’t deleting the task properly. I’ll update it and check whether that change fixes it.

Your robot gui should not be a task. LVGL has its own task and you just need to setup how you want it to work. Here is an example of an auton select done by 5090Z last year with some additions by me where noted.

If you look in initialize() you see a function call to robot_gui(). This sets up the LVGL display for use.

void initialize() {
  pros::delay(50); // sometimes LVGL won't draw the screen if there is no delay or it is not inverted on the brain
	auton_ptr = &auton_non;
  auton_go = 0;

Then if you look in robot_gui(), when an auton is selected it changes the tab to a status screen. This exists only for execution of auton from opcontrol but could be for any entry in to auton by moving lv_tabview_set_tab_act outside of the “if”.

 // run selected auton function when not in auton and not disabled
  if (!pros::competition::is_autonomous() && !pros::competition::is_disabled()) {
    lv_tabview_set_tab_act(tv, 6, false);

since it looks like you’re not using tabs, you probably need to use lv_scr_load(logo_scr). where logo_scr is where you put your logo. If you do this in opcontrol, i’d make it a function call to your gui code and keep lvgl separate from other code.

note that the code linked does not de-allocate.

ed: changing the screen could be done before exiting auton, or when entering opcontrol, but again i’d do that in a function call to the gui code and not directly call lvgl functions from opcontrol.


So I understand your suggestions but I’m confused about this last part.

It looks like you are de-allocating some or all of the auton gui. In the example I linked, the programmer did not de-allocate the LVGL auton gui or any of the selection tabs. I took advantage of that to add initiating auton from opcontrol b/c I don’t have a comp switch.