Important: unclear posts may not receive useful answers.
ints.
Description
What MCU/Processor/Board and compiler are you using?
ESP32nodeMCU
What LVGL version are you using?
LVGL8.2 , arduino framework, platformIO
What do you want to achieve?
I want to display png image from file system
What have you tried so far?
My LCD driver and touch driver are validated so i will focus on my filesystem driver
i have downloaded and installed lv_png.h for gitHub :GitHub - lvgl/lv_lib_png: PNG decoder for LVGL
the sources files are into the src directory of my project
//setting done into lv_conf.h:
#define LV_USE_PNG 1
#define LV_USE_FS 1
#define LV_USE_FS_STDIO 'F'
#define LV_PNG_USE_LV_FILESYSTEM 1
// main file
#include <lvgl.h>
#include <TFT_eSPI.h>
#include"GT911.h"
#include"ui.h"
#include "mbedtls/base64.h"
//#include <SD_MMC.h>
#include <FS.h>
#include <SD.h>
#include "lv_lib_png/lv_png.h"
:
//file system callbacks
void * SDopen_cb(lv_fs_drv_t * drv, const char * path, lv_fs_mode_t mode){
Serial.print("ds sd open");
Serial.print("path:");
Serial.println(path);
File *file = new File(SD.open(path, FILE_READ));
Serial.println(file->available());
if (!(*file)) {
Serial.print("impossible d ouvrir fichier: ");
Serial.println(path);
delete file;
return NULL; // Return NULL on failure
}
Serial.print("file size :");
Serial.println(file->size());
file->seek(0);
return (file);
}
//Callback to close a file
static lv_fs_res_t SDclose_cb(lv_fs_drv_t * drv, void * file_p){
Serial.println("dans close");
File *file = (File *)file_p;
file->close();
return LV_FS_RES_OK;
}
//Callback to read a file
static lv_fs_res_t SDread_cb(lv_fs_drv_t * drv, void * file_p, void * buf, uint32_t btr, uint32_t * br){
File *file = (File *)file_p;
static uint32_t file_pos = 0; // Static variable to keep track of the file position
*br = file->read((uint8_t *)buf, btr);
return LV_FS_RES_OK;
}
//Callback to seek in a file (Move cursor)
static lv_fs_res_t SDseek_cb(lv_fs_drv_t * drv, void * file_p, uint32_t pos, lv_fs_whence_t whence){
Serial.println("dans seek");
//File *file = *reinterpret_cast<File **>(file_p);
File *file = (File *)file_p;
uint32_t new_pos;
switch (whence) {
case LV_FS_SEEK_SET:
new_pos = pos;
break;
case LV_FS_SEEK_CUR:
new_pos = file->position() + pos;
break;
case LV_FS_SEEK_END:
new_pos = file->size() - pos;
break;
default:
return LV_FS_RES_INV_PARAM;
}
// Seek to the new position
if (!file->seek(new_pos)) {
return LV_FS_RES_UNKNOWN;
}
return LV_FS_RES_OK;
}
// callback to write a file
lv_fs_res_t SDtell_cb(lv_fs_drv_t *drv, void *file_p, uint32_t *pos_p) {
(void)drv; /*Unused*/
Serial.println("SDtell_cb");
File *file = (File *)file_p;
*pos_p = file->position();
return LV_FS_RES_OK;
}
bool SDready_cb(lv_fs_drv_t *drv){
return true;
}
//filesystem initialization ,declaration...
lv_png_init(); `
_lv_fs_init();
static lv_fs_drv_t fs_drv; /*Needs to be static or global*/
lv_fs_drv_init(&fs_drv); /*Basic initialization*/
fs_drv.letter = 'F'; /*An uppercase letter to identify the drive */
//fs_drv.cache_size = my_cache_size_fs; /*Cache size for reading in bytes. 0 to not cache.*/
fs_drv.cache_size = 0;
fs_drv.ready_cb=SDready_cb;
fs_drv.open_cb = SDopen_cb; /*Callback to open a file */
fs_drv.close_cb = SDclose_cb; /*Callback to close a file */
fs_drv.read_cb = SDread_cb; /*Callback to read a file */
fs_drv.seek_cb = SDseek_cb; /*Callback to seek in a file (Move cursor) */
fs_drv.tell_cb = SDtell_cb; /*Callback to tell the cursor position */
lv_fs_drv_register(&fs_drv);
//UI configuration:
screenMain = lv_obj_create(NULL);
//lv_group_t *group1 = lv_group_create();
//lv_group_add_obj(group1, lv_scr_act());
//lv_indev_set_group(indev1, group1);
label = lv_label_create(screenMain);
lv_label_set_text(label, "test sdcard");
lv_obj_set_size(label, 240, 40);
lv_obj_set_pos(label, 0, 15);
img=lv_img_create(screenMain);
lv_obj_set_width(img, 214);
lv_obj_set_height(img, 184);
lv_obj_set_pos(img, 32, 100);
lv_img_cache_invalidate_src(NULL);
lv_img_set_src(img,"F:/photo.png");
btn1 = lv_btn_create(screenMain);
lv_obj_add_event_cb(btn1, event_handler_btn,LV_EVENT_ALL,NULL);
lv_obj_set_width(btn1, 200);
lv_obj_set_height(btn1, 32);
lv_obj_set_pos(btn1, 100, 320);
lv_obj_t * label1 = lv_label_create(btn1);
lv_label_set_text(label1, "load image");
lv_scr_load(screenMain);
void loop()
{
lv_timer_handler(); /* let the GUI do its work */
//delay(1);
}
LVGL return :
error 78: failed to open file for reading`, but if i use a .bin file as source for image LVGL is able to open the file and display it to the screen.
This error code seems to be not from by openfile callback.
Please help me
Code to reproduce
Add a code snippet which can run in the simulator. It should contain only the relevant code that compiles without errors when separated from your main code base.
The code block(s) should be formatted like:
/*You code here*/
Screenshot and/or video
If possible, add screenshots and/or videos about the current state.