Important: unclear posts may not receive useful answers.
Before posting
- Get familiar with Markdown to format and structure your post
- Be sure to update lvgl from the latest version from the
master
branch.- Be sure you have checked the relevant part of the documentation.
- If applicable use the Simulator to eliminate hardware related issues.
Delete this section if you read and applied the mentioned points.
Description
What MCU/Processor/Board and compiler are you using?
arm with embedded Linux
What LVGL version are you using?
V7
What do you want to achieve?
using File as an image button source.
What have you tried so far?
first of all, I have initialized lvgl file system ( lv_fs_drv_t) and registered it.
second, convert a png file to a .binary file.
Third, use the path of the file as the source of a imgbtn object.
now the imgbtn appear for a few second and disappear with the “Segmentation fault” error.
The code block(s) should be formatted like:
in main fuction ==>
lv_fs_drv_t drv;
lv_fs_drv_init(&drv); /*Basic initialization*/
drv.letter = 'S'; /*An uppercase letter to identify the drive */
drv.file_size =2048;//sizeof(my_file_object); /*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)*/
/*Callback to tell if the drive is ready to use */
drv.open_cb = fs_open; /*Callback to open a file */
drv.close_cb = fs_fclose; /*Callback to close a file */
drv.read_cb = fs_fread; /*Callback to read a file */
drv.seek_cb = fs_fseek; /*Callback to seek in a file (Move cursor) */
drv.tell_cb = fs_ftell; /*Callback to tell the cursor position */
lv_fs_drv_register(&drv); /*Finally register the drive*/
declare of the function =>
static lv_fs_res_t fs_open (lv_fs_drv_t * drv, void * file_p, const char * path, lv_fs_mode_t mode)
{
lv_fs_res_t res = LV_FS_RES_NOT_IMP;
lv_fs_file_t * file_1 = (lv_fs_file_t *)file_p;
if(mode == LV_FS_MODE_WR)
{
file_1->file_d = fopen(path, "w");
}
else if(mode == LV_FS_MODE_RD)
{
file_1->file_d = fopen(path, "r");
}
else if(mode == (LV_FS_MODE_WR | LV_FS_MODE_RD))
{
file_1->file_d = fopen(path, "w+");
}
if(file_1->file_d == NULL)
return LV_FS_RES_FS_ERR;
return LV_FS_RES_OK;
}
lv_fs_res_t fs_fread(struct _lv_fs_drv_t * drv, void * file_p, void * buf, uint32_t btr, uint32_t * br)
{
lv_fs_file_t * file_1 = (lv_fs_file_t *)file_p;
*br = fread(buf, 1, btr, file_1->file_d);
printf("br = %d\n", *br);
return 0;
}
lv_fs_res_t fs_fclose(struct _lv_fs_drv_t * drv, void * file_p)
{
printf("close file\n");
lv_fs_file_t * file_1 = (lv_fs_file_t *)file_p;
fclose(file_1->file_d);
return 0;
}
static lv_fs_res_t fs_fseek (lv_fs_drv_t * drv, void * file_p, uint32_t pos)
{
lv_fs_res_t res = LV_FS_RES_NOT_IMP;
printf("fseek pos=%d\n",pos);
lv_fs_file_t * file_1 = (lv_fs_file_t *)file_p;
fseek(file_1,pos,SEEK_SET);
printf("fseek pos=%d\n",pos);
res = LV_FS_RES_OK;
return res;
}
later in main fuction ==>
lv_obj_t * mainmenuPanel[6];
lv_obj_t * mainmenuBtn[6];
lv_obj_t * mainmenuLabel[6];
for(ii=0 ; ii < 6 ; ii++)
{
mainmenuPanel[ii] = lv_cont_create(win,NULL);
lv_obj_set_size(mainmenuPanel[ii],220,84);
mainmenuBtn[ii] = lv_imgbtn_create(mainmenuPanel[ii],NULL);
lv_obj_set_size(mainmenuBtn[ii],64,64);
mainmenuLabel[ii] = lv_label_create(mainmenuPanel[ii],NULL);
lv_obj_set_style_local_bg_opa(mainmenuBtn[ii],LV_CONT_PART_MAIN,LV_STATE_DEFAULT,0);
lv_obj_set_style_local_border_opa(mainmenuPanel[ii],LV_CONT_PART_MAIN,LV_STATE_DEFAULT,0);
lv_obj_set_style_local_bg_opa(mainmenuPanel[ii],LV_CONT_PART_MAIN,LV_STATE_DEFAULT,0);
lv_obj_align(mainmenuPanel[ii],NULL,LV_ALIGN_IN_TOP_LEFT, 32+(/*800/3*/ 210 ) * (ii%3), 64+(32+400/4) * (ii / 3) );
lv_obj_align(mainmenuBtn[ii],NULL,LV_ALIGN_IN_TOP_MID, 0,0 );
lv_obj_align(mainmenuLabel[ii],NULL,LV_ALIGN_IN_BOTTOM_MID, 0,0 );
}
lv_imgbtn_set_src(mainmenuBtn,LV_BTN_STATE_PRESSED,"S/images/MainMenu_Record_888.bin");
lv_imgbtn_set_src(mainmenuBtn,LV_BTN_STATE_RELEASED,"S/images/MainMenu_Record_888.bin");
Screenshot and/or video
the image button appears for a few second and then system crashes