Fix image viewer by adding filesystem driver

This commit is contained in:
Thomas Farstrike
2025-06-10 11:13:54 +02:00
parent 863d5bee90
commit 4680a7a89c
6 changed files with 36 additions and 17 deletions
+24 -11
View File
@@ -89,26 +89,28 @@ def show_block_height():
# Create file explorer widget
file_explorer = lv.file_explorer(subwindow)
file_explorer.set_root_path("/")
file_explorer.explorer_open_dir('/')
file_explorer = lv.file_explorer(lv.screen_active())
#file_explorer.set_root_path("/")
#file_explorer.explorer_open_dir('/')
file_explorer.explorer_open_dir('P:.') # POSIX works, fs_driver doesn't because it doesn't have dir_open, dir_read, dir_close
#file_explorer.explorer_open_dir('S:/')
file_explorer.set_size(210, 210)
file_explorer.set_mode(lv.FILE_EXPLORER.MODE.DEFAULT) # Default browsing mode
file_explorer.set_sort(lv.FILE_EXPLORER.SORT.NAME_ASC) # Sort by name, ascending
#file_explorer.set_mode(lv.FILE_EXPLORER.MODE.DEFAULT) # Default browsing mode
#file_explorer.set_sort(lv.FILE_EXPLORER.SORT.NAME_ASC) # Sort by name, ascending
file_explorer.align(lv.ALIGN.CENTER, 0, 0)
def file_explorer_event_cb(e):
code = e.get_code()
print(f"file_explorer_event_cb {code}")
obj = e.get_target_obj()
if code == lv.EVENT.VALUE_CHANGED:
#selected_path = obj.get_selected_file_name()
selected_path = file_explorer.explorer_get_selected_file_name
selected_path = file_explorer.explorer_get_selected_file_name()
print("Selected:", selected_path)
if obj.is_selected_dir():
print("This is a directory")
else:
print("This is a file")
#if obj.is_selected_dir():
# print("This is a directory")
#else:
# print("This is a file")
# Attach event callback
@@ -664,3 +666,14 @@ mem32[0] = 0xDEADBEEF
import _thread
_thread.stack_size(0)
import fs_driver
fs_drv = lv.fs_drv_t()
fs_driver.fs_register(fs_drv, 'M')
img = lv.image(lv.screen_active())
#img.set_src("P:/data/images/icon_64x64.jpg")
img.set_src("P:../artwork/icon_64x64.jpg")
@@ -6,7 +6,8 @@ from mpos.apps import Activity
class ImageView(Activity):
#imagedir = "../icons/"
imagedir = "../artwork/"
#imagedir = "../artwork/"
imagedir = "data/images"
#imagedir = "/home/user/Downloads/"
#imagedir = "/home/user/images/"
images = []
@@ -82,13 +83,13 @@ class ImageView(Activity):
def show_image(self, name):
try:
self.label.set_text(name)
self.image.set_src(f"P:{name}")
self.image.set_src(f"M:{name}")
print(f"the LVGL image has size: {self.image.get_width()}x{self.image.get_height()}")
header = lv.image_header_t()
self.image.decoder_get_info(self.image.get_src(), header)
print(f"the real image has size: {header.w}x{header.h}")
#image.set_size(128, 128)
self.image.set_scale(512)
#self.image.set_scale(512)
print(f"after set_scale, the LVGL image has size: {self.image.get_width()}x{self.image.get_height()}")
except Exception as e:
print(f"show_image got exception: {e}")
Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.3 KiB

After

Width:  |  Height:  |  Size: 3.2 KiB

+5 -3
View File
@@ -1,16 +1,18 @@
import task_handler
# Allow LVGL M:/path/to/file or M:relative/path/to/file to work for image set_src etc
import fs_driver
fs_drv = lv.fs_drv_t()
fs_driver.fs_register(fs_drv, 'M')
import mpos.ui
RED = lv.palette_main(lv.PALETTE.RED)
DARKPINK = lv.color_hex(0xEC048C)
MEDIUMPINK = lv.color_hex(0xF480C5)
LIGHTPINK = lv.color_hex(0xF9E9F2)
DARKYELLOW = lv.color_hex(0xFBDC05)
LIGHTYELLOW = lv.color_hex(0xFBE499)
theme = lv.theme_default_init(display._disp_drv, DARKPINK, DARKYELLOW, False, lv.font_montserrat_12)
#theme = lv.theme_default_init(display._disp_drv, DARKPINK, DARKYELLOW, True, lv.font_montserrat_12)
+1
View File
@@ -34,6 +34,7 @@ if [ "$target" == "esp32" ]; then
# CONFIG_FREERTOS_USE_TRACE_FACILITY=y
# CONFIG_FREERTOS_VTASKLIST_INCLUDE_COREID=y
# CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS=y
#python3 make.py --ota --partition-size=4194304 --flash-size=16 esp32 BOARD=ESP32_GENERIC_S3 BOARD_VARIANT=SPIRAM_OCT DISPLAY=st7789 INDEV=cst816s USER_C_MODULE=/home/user/sources/micropython-camera-API/src/micropython.cmake USER_C_MODULE=/home/user/projects/MicroPythonOS/secp256k1-embedded-ecdh/micropython.cmake USER_C_MODULE=/home/user/sources/MicroPythonOS/c_mpos/micropython.cmake CONFIG_FREERTOS_USE_TRACE_FACILITY=y CONFIG_FREERTOS_VTASKLIST_INCLUDE_COREID=y CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS=y "$manifest"
python3 make.py --ota --partition-size=4194304 --flash-size=16 esp32 BOARD=ESP32_GENERIC_S3 BOARD_VARIANT=SPIRAM_OCT DISPLAY=st7789 INDEV=cst816s USER_C_MODULE=/home/user/sources/micropython-camera-API/src/micropython.cmake USER_C_MODULE=/home/user/projects/MicroPythonOS/secp256k1-embedded-ecdh/micropython.cmake USER_C_MODULE=/home/user/sources/MicroPythonOS/c_mpos/micropython.cmake CONFIG_FREERTOS_USE_TRACE_FACILITY=y CONFIG_FREERTOS_VTASKLIST_INCLUDE_COREID=y CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS=y "$manifest"
# ffmpeg failed because time_t conflict time.h /home/user/sources/lvgl_micropython/lib/esp-idf/components/mbedtls/mbedtls/include/mbedtls/platform_time.h
#python3 make.py --ota --partition-size=4194304 --flash-size=16 esp32 BOARD=ESP32_GENERIC_S3 BOARD_VARIANT=SPIRAM_OCT DISPLAY=st7789 INDEV=cst816s USER_C_MODULE=/home/user/sources/micropython-camera-API/src/micropython.cmake USER_C_MODULE=/home/user/projects/MicroPythonOS/secp256k1-embedded-ecdh/micropython.cmake USER_C_MODULE=/home/user/sources/MicroPythonOS/c_mpos/micropython.cmake USER_C_MODULE=/home/user/sources/MicroPythonOS/c_mpos/ffmpeg.cmake CONFIG_FREERTOS_USE_TRACE_FACILITY=y CONFIG_FREERTOS_VTASKLIST_INCLUDE_COREID=y CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS=y "$manifest"
+2
View File
@@ -48,7 +48,9 @@ fi
~/sources/lvgl_micropython/lib/micropython/tools/mpremote/mpremote.py fs cp -r builtin :/
~/sources/lvgl_micropython/lib/micropython/tools/mpremote/mpremote.py fs cp -r lib :/
~/sources/lvgl_micropython/lib/micropython/tools/mpremote/mpremote.py fs cp -r resources :/
#~/sources/lvgl_micropython/lib/micropython/tools/mpremote/mpremote.py fs cp -r data :/
#~/sources/lvgl_micropython/lib/micropython/tools/mpremote/mpremote.py fs cp -r data/images :/data/
popd