Description
I need to use image button through littlevgl filesystem. It reads the image from the spiffs, but a “No” word appears in the top of the image when i press it.
What MCU/Processor/Board and compiler are you using?
ESP32 on Arduino IDE
What do you want to achieve?
An image button without the “No” word.
Code to reproduce
The drive implementation:
void spiffs_drv_init(){
lv_fs_drv_init(&drv); /*Basic initialization*/
drv.letter = 'D'; /*An uppercase letter to identify the drive */
drv.file_size = sizeof(File); /*Size required to store a file object*/
//drv.rddir_size = sizeof(my_dir_object); /*Size required to store a directory object (used by dir_open/close/read)*/
//drv.ready_cb = my_ready_cb; /*Callback to tell if the drive is ready to use */
drv.open_cb = my_open_cb; /*Callback to open a file */
drv.close_cb = my_close_cb; /*Callback to close a file */
drv.remove_cb = my_remove_cb; /*Callback to remove a file */
drv.read_cb = my_read_cb; /*Callback to read a file */
drv.write_cb = my_write_cb; /*Callback to write a file */
drv.seek_cb = my_seek_cb; /*Callback to seek in a file (Move cursor) */
drv.tell_cb = my_tell_cb; /*Callback to tell the cursor position */
//drv.size_cb = my_size_cb; /*Callback to tell a file's size */
//drv.rename_cb = my_size_cb; /*Callback to rename a file */
//drv.dir_open_cb = my_dir_open_cb; /*Callback to open directory to read its content */
//drv.dir_read_cb = my_dir_read_cb; /*Callback to read a directory's content */
//drv.dir_close_cb = my_dir_close_cb; /*Callback to close a directory */
//drv.free_space_cb = my_size_cb; /*Callback to tell free space on the drive */
//drv.user_data = my_user_data; /*Any custom data if required*/
lv_fs_drv_register(&drv); /*Finally register the drive*/
}
lv_fs_res_t my_open_cb(lv_fs_drv_t *drv, void *file_p, const char *fn, lv_fs_mode_t mode){
(void) drv; /*Unused*/
if (f) {
return LV_FS_RES_OK;
}
char buf[100];
sprintf(buf,"/%s",fn);
f = SPIFFS.open(buf, mode == LV_FS_MODE_WR ? FILE_WRITE : FILE_READ);
if(!f || f.isDirectory()){
return LV_FS_RES_UNKNOWN;
} else{
return LV_FS_RES_OK;
}
}
lv_fs_res_t my_close_cb(lv_fs_drv_t *drv, void *file_p){
(void) drv; /*Unused*/
f.close();
return LV_FS_RES_OK;
}
lv_fs_res_t my_read_cb(lv_fs_drv_t *drv, void *file_p,
void *buf, uint32_t btr, uint32_t *br){
(void) drv; /*Unused*/
*br = f.read((uint8_t*)buf, btr);
Serial.println("READ");
return LV_FS_RES_OK;
}
lv_fs_res_t my_write_cb(lv_fs_drv_t *drv, void *file_p,
const void *buf, uint32_t btw, uint32_t *bw){
(void) drv; /*Unused*/
*bw = f.write((const uint8_t*)buf, btw);
return LV_FS_RES_OK;
}
lv_fs_res_t my_seek_cb(lv_fs_drv_t *drv, void *file_p, uint32_t pos){
(void) drv; /*Unused*/
f.seek(pos);
return LV_FS_RES_OK;
}
lv_fs_res_t my_tell_cb(lv_fs_drv_t *drv, void *file_p, uint32_t *pos_p){
(void) drv; /*Unused*/
uint32_t tmp = f.position();
pos_p = &tmp;
return LV_FS_RES_OK;
}
lv_fs_res_t my_remove_cb(lv_fs_drv_t *drv, const char *fn){
(void) drv; /*Unused*/
char buf[100];
sprintf(buf,"/%s",fn);
if(SPIFFS.remove(buf)){
return LV_FS_RES_OK;
} else{
return LV_FS_RES_UNKNOWN;
}
}
Image button implementation:
lv_style_copy(&style_upper_bar, &lv_style_scr);
style_upper_bar.body.main_color = LV_COLOR_BLACK;
style_upper_bar.body.grad_color = LV_COLOR_BLACK;
style_upper_bar.body.opa = LV_OPA_50;
lv_style_copy(&style_img_pr, &lv_style_plain);
style_img_pr.image.color = LV_COLOR_BLACK;
style_img_pr.image.intense = LV_OPA_50;
style_img_pr.text.color = lv_color_hex3(0xaaa);
// ##################################
// Home button on the left side bar
lv_obj_t *test = lv_imgbtn_create(scr, NULL);
lv_imgbtn_set_src(test, LV_BTN_STATE_PR, "D:/background_small.bin");
lv_imgbtn_set_src(test, LV_BTN_STATE_REL, "D:/background_small.bin");
lv_imgbtn_set_src(test, LV_BTN_STATE_TGL_PR, "D:/background_small.bin");
lv_imgbtn_set_src(test, LV_BTN_STATE_TGL_REL, "D:/background_small.bin");
lv_imgbtn_set_src(test, LV_BTN_STATE_INA, "D:/background_small.bin");
lv_imgbtn_set_style(test, LV_BTN_STATE_PR, &style_img_pr);
lv_imgbtn_set_style(test, LV_BTN_STATE_TGL_PR, &style_img_pr);
lv_imgbtn_set_toggle(test, true);
lv_obj_align(test, NULL, LV_ALIGN_CENTER, 10, 0);
lv_btn_set_state(test, LV_BTN_STATE_TGL_REL);
//lv_btn_set_ink_in_time(test, 100);
// ##################################
Screenshot and/or video
This is the video dimostrating the problem.