Here’s a working example that displays image from SD Card with the version of lvgl that’s currently in PROS. It’s based on the lvgl sample code, unfortunately that’s either been updated for V6 or is just plain wrong, I don’t know.
#include <stdio.h>
#include "main.h"
typedef FILE * pc_file_t;
static lv_fs_res_t pcfs_open( void * file_p, const char * fn, lv_fs_mode_t mode)
{
errno = 0;
const char * flags = "";
if(mode == LV_FS_MODE_WR) flags = "wb";
else if(mode == LV_FS_MODE_RD) flags = "rb";
else if(mode == (LV_FS_MODE_WR | LV_FS_MODE_RD)) flags = "a+";
char buf[256];
sprintf(buf, "/%s", fn);
pc_file_t f = fopen(buf, flags);
if(f == NULL)
return LV_FS_RES_UNKNOWN;
else {
fseek(f, 0, SEEK_SET);
pc_file_t * fp = (pc_file_t *)file_p;
*fp = f;
}
return LV_FS_RES_OK;
}
static lv_fs_res_t pcfs_close( void * file_p)
{
pc_file_t * fp = (pc_file_t *)file_p;
fclose(*fp);
return LV_FS_RES_OK;
}
static lv_fs_res_t pcfs_read( void * file_p, void * buf, uint32_t btr, uint32_t * br)
{
pc_file_t * fp = (pc_file_t *)file_p;
*br = fread(buf, 1, btr, *fp);
return LV_FS_RES_OK;
}
static lv_fs_res_t pcfs_seek( void * file_p, uint32_t pos)
{
pc_file_t * fp = (pc_file_t *)file_p;
fseek(*fp, pos, SEEK_SET);
return LV_FS_RES_OK;
}
static lv_fs_res_t pcfs_tell( void * file_p, uint32_t * pos_p)
{
pc_file_t * fp = (pc_file_t *)file_p;
*pos_p = ftell(*fp);
return LV_FS_RES_OK;
}
void opcontrol() {
lv_fs_drv_t pcfs_drv; /*A driver descriptor*/
memset(&pcfs_drv, 0, sizeof(lv_fs_drv_t)); /*Initialization*/
pcfs_drv.file_size = sizeof(pc_file_t); /*Set up fields...*/
pcfs_drv.letter = 'S';
pcfs_drv.open = pcfs_open;
pcfs_drv.close = pcfs_close;
pcfs_drv.read = pcfs_read;
pcfs_drv.seek = pcfs_seek;
pcfs_drv.tell = pcfs_tell;
lv_fs_add_drv(&pcfs_drv);
lv_obj_t * img_var = lv_img_create(lv_scr_act(), NULL);
lv_img_set_src(img_var, "S:/usd/test_128_888.bin");
lv_obj_set_pos(img_var, 0, 0);
while (true) {
pros::delay(20);
}
}
This was the image I used for testing, converted from png using the old converter.
test_128_888.bin.zip (1.7 KB)
Image should be in root of SD card, the /usd path is a PROS thing.
Update 9/27/2019
For PROS kernel 3.2.0, which contains lvgl version 5.3, the new (or is that current) image converter should be used.
Select “True color with Alpha” for the color format
Select “Binary RGB888” for the output format