[PROS] LVGL not working

Hello,

I am trying to make an autonomous selector with LVGL. It works fine in the simulator. However, when I put the code in my PROS project, none of the functions are recognized. I’ve included apix.h in the main.h file. Thanks.

We don’t have anything to work with here. You haven’t posted any code. What version of the PROS kernel is your project using? Run pros c info-project. Which version of LVGL did you write your code for? PROS 3 uses lvgl 5.3.3 by default and PROS 4 uses lvgl 8.3.4 by default.

I am running PROS 4, and my code is written for lvgl 8.3.4.

main.cpp:

#include "main.h"
/**
 * A callback function for LLEMU's center button.
 *
 * When this callback is fired, it will toggle line 2 of the LCD text between
 * "I was pressed!" and nothing.
 */
void on_center_button() {

}

void onClick(lv_event_t * e) {
  lv_event_code_t code = lv_event_get_code(e);
  lv_obj_t * obj = lv_event_get_target(e);

  if(code == LV_EVENT_VALUE_CHANGED) {
    uint32_t id = lv_buttonmatrix_get_selected_button(obj);
    const char * txt = lv_buttonmatrix_get_button_text(obj, id);
    if(id == 0) {
      // Set autonomous case
    }
    if (id == 1)
    {
      // Set autonomous case
    }
  }
}

/**
 * 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() {
static const char * map[] = {
    "Far", "\n", "Near", "\n", "Skills", NULL
};

static const char * mapOther[] = {
    "Program 1", "\n", "Program 2", "\n", "Program 3", "\n", "Program 4", NULL
};

//Create tab page style
static lv_style_t * tabPage;
lv_style_init(&tabPage);
lv_style_set_pad_all(&tabPage, 0);

//Create tabs
lv_obj_t * tabView = lv_tabview_create(lv_scr_act());
lv_tabview_set_tab_bar_size(tabView, 50);
lv_obj_t * bluePage = lv_tabview_add_tab(tabView, "Competition");
lv_obj_t * redPage = lv_tabview_add_tab(tabView, "Other");
lv_obj_add_style(bluePage, &tabPage, LV_PART_MAIN);
lv_obj_add_style(redPage, &tabPage, LV_PART_MAIN);
//Create buttons on blue tab
lv_obj_t * blueMatrix = lv_btnmatrix_create(bluePage);
lv_btnmatrix_set_map(blueMatrix, map);
lv_obj_set_size(blueMatrix, 480, 190);
lv_obj_add_event_cb(blueMatrix, onClick, LV_EVENT_VALUE_CHANGED, NULL);
//Create buttons on red tab
lv_obj_t * redMatrix = lv_btnmatrix_create(redPage);
lv_btnmatrix_set_map(redMatrix, mapOther);
lv_obj_set_size(redMatrix, 480, 190);
}
/**
 * Runs while the robot is in the disabled state of Field Management System or
 * the VEX Competition Switch, following either autonomous or opcontrol. When
 * the robot is enabled, this task will exit.
 */
void disabled() {}

/**
 * Runs after initialize(), and before autonomous when connected to the Field
 * Management System or the VEX Competition Switch. This is intended for
 * competition-specific initialization routines, such as an autonomous selector
 * on the LCD.
 *
 * This task will exit when the robot is enabled and autonomous or opcontrol
 * starts.
 */
void competition_initialize() {}

/**
 * Runs the user autonomous code. This function will be started in its own task
 * with the default priority and stack size whenever the robot is enabled via
 * the Field Management System or the VEX Competition Switch in the autonomous
 * mode. Alternatively, this function may be called in initialize or opcontrol
 * for non-competition testing purposes.
 *
 * If the robot is disabled or communications is lost, the autonomous task
 * will be stopped. Re-enabling the robot will restart the task, not re-start it
 * from where it left off.
 */
void autonomous() {}

/**
 * Runs the operator control code. This function will be started in its own task
 * with the default priority and stack size whenever the robot is enabled via
 * the Field Management System or the VEX Competition Switch in the operator
 * control mode.
 *
 * If no competition control is connected, this function will run immediately
 * following initialize().
 *
 * If the robot is disabled or communications is lost, the
 * operator control task will be stopped. Re-enabling the robot will restart the
 * task, not resume it from where it left off.
 */
void opcontrol() {
	pros::Controller master(pros::E_CONTROLLER_MASTER);
	pros::MotorGroup left_mg({1, -2, 3});    // Creates a motor group with forwards ports 1 & 3 and reversed port 2
	pros::MotorGroup right_mg({-4, 5, -6});  // Creates a motor group with forwards port 5 and reversed ports 4 & 6


	while (true) {
		pros::lcd::print(0, "%d %d %d", (pros::lcd::read_buttons() & LCD_BTN_LEFT) >> 2,
		                 (pros::lcd::read_buttons() & LCD_BTN_CENTER) >> 1,
		                 (pros::lcd::read_buttons() & LCD_BTN_RIGHT) >> 0);  // Prints status of the emulated screen LCDs

		// Arcade control scheme
		int dir = master.get_analog(ANALOG_LEFT_Y);    // Gets amount forward/backward from left joystick
		int turn = master.get_analog(ANALOG_RIGHT_X);  // Gets the turn left/right from right joystick
		left_mg.move(dir - turn);                      // Sets left motor voltage
		right_mg.move(dir + turn);                     // Sets right motor voltage
		pros::delay(20);                               // Run for 20 ms then update
	}
}

main.h

/**
 * \file main.h
 *
 * Contains common definitions and header files used throughout your PROS
 * project.
 *
 * \copyright Copyright (c) 2017-2023, Purdue University ACM SIGBots.
 * All rights reserved.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

#ifndef _PROS_MAIN_H_
#define _PROS_MAIN_H_

/**
 * If defined, some commonly used enums will have preprocessor macros which give
 * a shorter, more convenient naming pattern. If this isn't desired, simply
 * comment the following line out.
 *
 * For instance, E_CONTROLLER_MASTER has a shorter name: CONTROLLER_MASTER.
 * E_CONTROLLER_MASTER is pedantically correct within the PROS styleguide, but
 * not convenient for most student programmers.
 */
#define PROS_USE_SIMPLE_NAMES

/**
 * If defined, C++ literals will be available for use. All literals are in the
 * pros::literals namespace.
 *
 * For instance, you can do `4_mtr = 50` to set motor 4's target velocity to 50
 */
#define PROS_USE_LITERALS

#include "api.h"
#include "pros/apix.h"


/**
 * You should add more #includes here
 */
//#include "okapi/api.hpp"

/**
 * If you find doing pros::Motor() to be tedious and you'd prefer just to do
 * Motor, you can use the namespace with the following commented out line.
 *
 * IMPORTANT: Only the okapi or pros namespace may be used, not both
 * concurrently! The okapi namespace will export all symbols inside the pros
 * namespace.
 */
// using namespace pros;
// using namespace pros::literals;
// using namespace okapi;

/**
 * Prototypes for the competition control tasks are redefined here to ensure
 * that they can be called from user code (i.e. calling autonomous from a
 * button press in opcontrol() for testing purposes).
 */
#ifdef __cplusplus
extern "C" {
#endif
void autonomous(void);
void initialize(void);
void disabled(void);
void competition_initialize(void);
void opcontrol(void);
#ifdef __cplusplus
}
#endif

#ifdef __cplusplus
/**
 * You can add C++-only headers here
 */
//#include <iostream>
#endif

#endif  // _PROS_MAIN_H_

Can you please open the PROS Integrated Terminal and run the command pros c info-project ? You should see some information about your kernel version and other templates that are installed. One of those templates should be liblvgl . If it is not there, you will need to add it to your project. You can see a list of available versions for the template with the command pros c query-templates liblvgl -ea
(where -ea enables accessing the early-access-kernel-mainline depot). You can apply the template with the command pros c apply liblvgl@version . I believe the PROS 4 default is 8.3.8, but you are welcome to change it to whatever is available by using the pros c apply command.

Once the liblvgl template is applied, you can include lvgl in your file with #include "liblvgl/lvgl.h".

1 Like

liblvgl is there. I am only getting errors with lv_buttonmatrix_get_selected_button() and lv_tabview_set_tab_bar_size() that say “identifier “lv_tabview_set_tab_bar_size” is undefined” and “identifier “lv_buttonmatrix_get_selected_button” is undefined”

Is this an error that appears in the editor (ie linter error), or is it an error from the compilation process (compilation error, from when you run pros make)?

It appears in the editor

Can you try to compile the program? See if there is an actual error when you compile.

Yeah I stopped working on it for like a week and when I came back it was working lol. Thanks for your help though!