LVGL Image Display From C Array

I have read the other threads on this particular issue but they did not help me, so I figured it’d be better to just show the code and get some specific help.

#include "main.h"
#if LV_USE_IMG

#define POTENTIOMETER_PORT 'A'


lv_obj_t * Auto1;
lv_obj_t * Auto2;
lv_obj_t * Auto3;
lv_obj_t * Auto4;
lv_obj_t * AutoLBL1;
lv_obj_t * AutoLBL2;
lv_obj_t * AutoLBL3;
lv_obj_t * AutoLBL4;
lv_obj_t * WarningMSG1;
lv_obj_t * WarningMSG2;

static lv_obj_t * Logo;



LV_IMG_DECLARE(ConvertedDQ2);





lv_style_t myButtonStyleREL; //released style
lv_style_t myButtonStylePR; //pressed style

static lv_res_t btn_click_action(lv_obj_t * btn)
{
	uint8_t id = lv_obj_get_free_num(btn); //id usefull when there are multiple 
buttons

/*	if(id == 0)
	{
			char buffer[100];
 sprintf(buffer, "button was clicked %i milliseconds from start", pros::millis());
 lv_label_set_text(AutoLBL1, buffer);
	}
*/
	return LV_RES_OK;
}
/**
 * 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()
 { 

 }


void disabled() {

}



void competition_initialize() {
// auton selector HERE

lv_style_copy(&myButtonStyleREL, &lv_style_plain);
myButtonStyleREL.body.main_color = lv_color_hex(0x804000); //%25
myButtonStyleREL.body.grad_color = lv_color_hex(0x003d66); //%25
myButtonStyleREL.body.radius = 10;
myButtonStyleREL.text.color = lv_color_hex(0x999999);

lv_style_copy(&myButtonStylePR, &lv_style_plain);
myButtonStylePR.body.main_color = lv_color_hex(0xff9933); //%60
myButtonStylePR.body.grad_color = lv_color_hex(0x006bb3); //%60
myButtonStylePR.body.radius = 10;
myButtonStylePR.text.color = LV_COLOR_MAKE(255, 255, 255);

//auto1
Auto1 = lv_btn_create(lv_scr_act(), NULL); //create button, lv_scr_act() is deafult 
screen object
lv_obj_set_free_num(Auto1, 0); //set button is to 0
//auto2
Auto2 = lv_btn_create(lv_scr_act(), NULL); //create button, lv_scr_act() is deafult 
screen object
lv_obj_set_free_num(Auto2, 1); //set button is to 0
//auto3
Auto3 = lv_btn_create(lv_scr_act(), NULL); //create button, lv_scr_act() is deafult 
screen object
lv_obj_set_free_num(Auto3, 2); //set button is to 0
//auto4
Auto4 = lv_btn_create(lv_scr_act(), NULL); //create button, lv_scr_act() is deafult 
screen object
lv_obj_set_free_num(Auto4, 3); //set button is to 0




//auto1
lv_btn_set_action(Auto1, LV_BTN_ACTION_CLICK, btn_click_action); //set function 
to be called on button click
lv_btn_set_style(Auto1, LV_BTN_STYLE_REL, &myButtonStyleREL); //set the 
released style
lv_btn_set_style(Auto1, LV_BTN_STYLE_PR, &myButtonStylePR); //set the pressed 
style
lv_obj_set_size(Auto1, 250, 30); //set the button size (acceptable default: 200,50)
lv_obj_align(Auto1, NULL, LV_ALIGN_CENTER, 0, -85); //set the position to CENTER
//auto2
lv_btn_set_action(Auto2, LV_BTN_ACTION_CLICK, btn_click_action); //set function 
to be called on button click
lv_btn_set_style(Auto2, LV_BTN_STYLE_REL, &myButtonStyleREL); //set the 
released style
lv_btn_set_style(Auto2, LV_BTN_STYLE_PR, &myButtonStylePR); //set the pressed 
style
lv_obj_set_size(Auto2, 250, 30); //set the button size (acceptable default: 200,50)
lv_obj_align(Auto2, NULL, LV_ALIGN_CENTER, 0, -40); //set the position to CENTER
//auto3
lv_btn_set_action(Auto3, LV_BTN_ACTION_CLICK, btn_click_action); //set function 
to be called on button click
lv_btn_set_style(Auto3, LV_BTN_STYLE_REL, &myButtonStyleREL); //set the released style
lv_btn_set_style(Auto3, LV_BTN_STYLE_PR, &myButtonStylePR); //set the pressed 
style
lv_obj_set_size(Auto3, 250, 30); //set the button size (acceptable default: 200,50)
lv_obj_align(Auto3, NULL, LV_ALIGN_CENTER, 0, 5); //set the position to CENTER
//auto4
lv_btn_set_action(Auto4, LV_BTN_ACTION_CLICK, btn_click_action); //set function 
to be called on button click
lv_btn_set_style(Auto4, LV_BTN_STYLE_REL, &myButtonStyleREL); //set the 
released style
lv_btn_set_style(Auto4, LV_BTN_STYLE_PR, &myButtonStylePR); //set the pressed 
style
lv_obj_set_size(Auto4, 250, 30); //set the button size (acceptable default: 200,50)
lv_obj_align(Auto4, NULL, LV_ALIGN_CENTER, 0, 50); //set the position to CENTER





//auto1
AutoLBL1 = lv_label_create(Auto1, NULL); //create label and puts it inside of the 
button
lv_label_set_text(AutoLBL1, "Routine 1"); //sets label text
//auto2
AutoLBL2 = lv_label_create(Auto2, NULL); //create label and puts it inside of the 
button
lv_label_set_text(AutoLBL2, "Routine 2"); //sets label text
//auto3
AutoLBL3 = lv_label_create(Auto3, NULL); //create label and puts it inside of the 
button
lv_label_set_text(AutoLBL3, "Routine 3"); //sets label text
//auto4
AutoLBL4 = lv_label_create(Auto4, NULL); //create label and puts it inside of the 
button
lv_label_set_text(AutoLBL4, "Routine 4"); //sets label text





WarningMSG1 = lv_label_create(lv_scr_act(), NULL); //create label and puts it on the 
screen
lv_label_set_text(WarningMSG1, "Please check that the selected"); //sets label text
lv_obj_align(WarningMSG1, NULL, LV_ALIGN_CENTER, 0, 80);
WarningMSG2 = lv_label_create(lv_scr_act(), NULL); //create label and puts it on the 
screen
lv_label_set_text(WarningMSG2, "autonomous routine is correct!!"); //sets label text
lv_obj_align(WarningMSG2, NULL, LV_ALIGN_CENTER, 00, 100);


//lv_img_set_auto_size(Logo, true);
Logo = lv_img_create(lv_scr_act(), NULL);
lv_img_set_src(Logo, &ConvertedDQ2);
lv_obj_align(Logo, NULL, LV_ALIGN_CENTER, 0, 0);



}

#endif


void autonomous() {}

void opcontrol() {

}

Sorry I am posting in chunks because I don’t have a lot of time.

Here are the important parts from the c-array.

#include "display/lvgl.h"

#ifndef LV_ATTRIBUTE_MEM_ALIGN
#define LV_ATTRIBUTE_MEM_ALIGN
#endif

#ifndef LV_ATTRIBUTE_IMG_CONVERTEDDQ2
#define LV_ATTRIBUTE_IMG_CONVERTEDDQ2
#endif


const lv_img_dsc_t ConvertedDQ2 = {
.header.always_zero = 0,
.header.w = 420,
.header.h = 210,
.data_size = 30843,
.header.cf = LV_IMG_CF_RAW,
.data = ConvertedDQ2_map,
};

I just get a gray screen when I try to make all of this work.
Sidenote:
In the c-array I changed the include from #include “lvgl/lvgl.h” to #include “display/lvgl.h”

I also had to add the width and height dimensions because there was no number there.

The error I get says something like expected primary expression, then it references the header part of the code in multiple places as the location of the errors.

The c array file has been placed in my project’s folder inside of the include folder.

are you using the correct version of image converter ?

1 Like

Well I cannot be sure cause I can’t find the/an old one for reference, but I believe I am. It looks just like the one in the screenshot.

Also I do not believe I have an include for the c array file inside of my main.h file, which doesn’t seem to be a problem but others definitely would know better than me. To my knowledge the only time it really has to be referenced is with the LV_IMG_DECLARE command.