How to Open image file from Windows PC in simulator?

        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 = 'C';
	pcfs_drv.open_cb = pcfs_open;
	pcfs_drv.close_cb = pcfs_close;
	pcfs_drv.read_cb = pcfs_read;
	pcfs_drv.seek_cb = pcfs_seek;
	pcfs_drv.tell_cb = pcfs_tell;
	lv_fs_drv_register(&pcfs_drv);
	lv_obj_t * wp = lv_img_create(lv_disp_get_scr_act(NULL), NULL);
	lv_img_set_src(wp, "C:\LVGL\ZZZ.bin");

Hi

I am trying to load an image from c:\lvgl\zzz.bin and am getting ‘no data’ on the screen…

Any ideas?

Again, you seem to have skipped filling in the template. Please do that. There are marked headers for you to put your information in (i.e. Description, Code sample).

Thanks for the info, but I do not have anything to fill in - I think the post describes concisely the issue.

I am assuming that pcfs_open is from lv_tutorial_images.c.

A quick read of the relevant code shows that the path is always relative to whatever directory you are running the executable in (if you are using an IDE, that could be the Debug or Release folder, or the project folder).

So you are going to have to put zzz.bin in that directory and then try and open just zzz.bin (without any drive prefix).

Wow! Many Thanks!

Okay so the folder is the root of the LVGL lib.
Trouble is when I / run / debug, it works for only about 1 out of 10 times. The other times it just says no data. But if I stop and run over and over eventually it works, and then stop and try again and it stops working again…? Any Ideas?

Does it return on this line when it doesn’t work?

YES! This is correct.

This is indicative of a confused debugger. Since it’s in the main loop it obviously must have returned (unless you are using multiple threads).

Did you put a breakpoint on that line and then step into (not over)? I’m just checking the exact sequence of steps because some debuggers are a bit picky.

Exactly, and yes this is where it halts.

Okay, then let’s check the opposite block. Set a breakpoint on the call to fseek, and see if it gets reached when it fails.

When it does not work, it does indeed reach the line of code:

return LV_FS_RES_UNKNOWN;

To elaborate:

	if ((long int)f <= 0) {
                //if code reaches here, then will not work
                //(shows "No Data" on screen)
		return LV_FS_RES_UNKNOWN;
	} else {
                //if the code reaches here then it works okay
                //(image is shown)
		fseek(f, 0, SEEK_SET);
		/* 'file_p' is pointer to a file descriptor and
		 * we need to store our file descriptor here*/
		pc_file_t* fp = file_p;        /*Just avoid the confusing casings*/
		*fp = f;
	}
'''

Strange. Can you print the value of errno when it doesn’t work?

errno is ‘undefined’ - even when I break on it!

So if it works or not, it cannot resolve errno.

But I do get this in the command window when it fails:

Warn: Image draw cannot open the image resource (c:\pc_simulator_sdl_visual_studio-master\visual_studio_2017_sdl\lvgl\src\lv_draw\lv_img_cache.c #118)
Warn: Image draw error (c:\pc_simulator_sdl_visual_studio-master\pc_simulator_sdl_visual_studio-master\visual_studio_2017_sdl\lvgl\src\lv_draw\lv_draw_img.c #61)

Include errno.h, stdio.h, and string.h at the top of the file.

Then add printf("errno: %d %s\n", errno, strerror(errno)); before
return LV_FS_RES_UNKNOWN;.

errno: 0 No Error

Even when it fails it still says “No Error”? If so, that is very strange.

Hi, yes exactly!

When not fail the console says nothing, when fails its says 0: No Error!

Wait a second… can you try something? Change the if statement to be if(f == NULL) instead of if((long int)f <= 0). See if it works consistently.