Skip to content

Add directory support to fs_driver #399

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

ThomasFarstrike
Copy link
Contributor

Support directory operations (dir_open_cb, dir_read_cb, dir_close_cb) in fs_driver.py so that the file_explorer widget, when using fs_driver, is able to browse the filesystem.

I validated this on the unix and esp32 targets with:

import fs_driver
fs_drv = lv.fs_drv_t()
fs_driver.fs_register(fs_drv, 'M')
file_explorer = lv.file_explorer(lv.screen_active())
file_explorer.explorer_open_dir('M:/')
def file_explorer_event_cb(event):
    path = file_explorer.explorer_get_current_path()
    file = file_explorer.explorer_get_selected_file_name()
    print(f"Selected: {path}{file}")
file_explorer.add_event_cb(file_explorer_event_cb, lv.EVENT.VALUE_CHANGED, None)

If you get a UnicodeError, that's not due to this code but the binding code generator and how it handles char * vs void * arguments. See this discussion.

Support directory operations (dir_open_cb, dir_read_cb, dir_close_cb) in fs_driver.py
so that the file_explorer widget, when using fs_driver, is able to browse the filesystem.
This change addresses a UnicodeError in the MicroPython-LVGL binding generator
by explicitly handling `char *` arguments in `build_callback_func_arg`.

Previously, the function relied on the `lv_to_mp` dictionary for all type
conversions, which could lead to incorrect or missing converters for `char *`,
causing encoding issues. Now, `char *` arguments are assigned the `ptr_to_mp`
converter directly, ensuring proper conversion to MicroPython string objects.

Additionally, the initial type extraction preserves qualifiers
(`remove_quals=False`) to improve type handling accuracy, while maintaining
compatibility for non-`char *` types by stripping qualifiers in the fallback
path.
@ThomasFarstrike
Copy link
Contributor Author

With that additional commit, the UnicodeError is fixed now. Ty!

@kdschlosser
Copy link
Collaborator

And it was able to be done without having to make any changes needing to be made in LVGL...

Thanks for spending the time to make the PR. I always want people to get the credit for the work they do and PR's is the way that gets done.

If you are up to the challenge I would love to have some help with writing a new script to handle the binding code generation. The existing script is a mess and hard to understand what is happening. I also want to simplify things by flattening the API so it matches LVGL's C API. This will make it easier for people to use. A user will be able to select which API style they want to use at compile time. I will deprecate the current API and have a warning shown at compile time if it is used. That way it gives people some time to transition to the LVGL API.

The code generator script will be vastly easier if the API gets changed. I also want to write it in a manner that makes it easy to understand what is happening. create an actual module with separate source files and not 4K lines of code dumped into a single file.

If you are up for it lemme know. I will create a new repository where we can work on it and I will give you write permissions to that repository so we can both add to it. It will take a while to get it done.

@kdschlosser kdschlosser merged commit e8aa2bd into lvgl-micropython:main Jul 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants