From 8e734b1e53418600ab1f05dec086e08854adadc1 Mon Sep 17 00:00:00 2001 From: Thomas Farstrike Date: Sun, 25 Jan 2026 21:52:25 +0100 Subject: [PATCH] InputManager: add has_indev_type to figure out if there are buttons --- .../assets/confetti.py | 2 + .../lib/mpos/board/fri3d_2024.py | 4 ++ internal_filesystem/lib/mpos/board/linux.py | 4 +- .../lib/mpos/ui/input_manager.py | 45 +++++++++++++++++-- 4 files changed, 51 insertions(+), 4 deletions(-) diff --git a/internal_filesystem/apps/com.micropythonos.confetti/assets/confetti.py b/internal_filesystem/apps/com.micropythonos.confetti/assets/confetti.py index f79e4d62..7d53276c 100644 --- a/internal_filesystem/apps/com.micropythonos.confetti/assets/confetti.py +++ b/internal_filesystem/apps/com.micropythonos.confetti/assets/confetti.py @@ -1,3 +1,5 @@ +# This is a copy of LightningPiggyApp's confetti.py + import time import random import lvgl as lv diff --git a/internal_filesystem/lib/mpos/board/fri3d_2024.py b/internal_filesystem/lib/mpos/board/fri3d_2024.py index 530e9f13..b0120b9c 100644 --- a/internal_filesystem/lib/mpos/board/fri3d_2024.py +++ b/internal_filesystem/lib/mpos/board/fri3d_2024.py @@ -15,6 +15,7 @@ import task_handler import mpos.ui import mpos.ui.focus_direction +from mpos import InputManager from ..task_manager import TaskManager @@ -258,6 +259,9 @@ disp = lv.display_get_default() # NOQA indev.set_display(disp) # different from display indev.enable(True) # NOQA +# Register the input device with InputManager +InputManager.register_indev(indev) + # Battery voltage ADC measuring # NOTE: GPIO13 is on ADC2, which requires WiFi to be disabled during reading on ESP32-S3. # battery_voltage.py handles this automatically: disables WiFi, reads ADC, reconnects WiFi. diff --git a/internal_filesystem/lib/mpos/board/linux.py b/internal_filesystem/lib/mpos/board/linux.py index 0fe4d30a..b4fbd1de 100644 --- a/internal_filesystem/lib/mpos/board/linux.py +++ b/internal_filesystem/lib/mpos/board/linux.py @@ -7,6 +7,7 @@ import mpos.clipboard import mpos.indev.mpos_sdl_keyboard import mpos.ui import mpos.ui.focus_direction +from mpos import InputManager # Same as Waveshare ESP32-S3-Touch-LCD-2 and Fri3d Camp 2026 Badge TFT_HOR_RES=320 @@ -71,14 +72,15 @@ def catch_escape_key(indev, indev_data): sdlkeyboard._read(indev, indev_data) -#import sdl_keyboard sdlkeyboard = mpos.indev.mpos_sdl_keyboard.MposSDLKeyboard() sdlkeyboard._indev_drv.set_read_cb(catch_escape_key) # check for escape +InputManager.register_indev(sdlkeyboard) try: sdlkeyboard.set_paste_text_callback(mpos.clipboard.paste_text) except Exception as e: print("Warning: could not set paste_text callback for sdlkeyboard, copy-paste won't work") + #def keyboard_cb(event): # global canvas # event_code=event.get_code() diff --git a/internal_filesystem/lib/mpos/ui/input_manager.py b/internal_filesystem/lib/mpos/ui/input_manager.py index 4c9574ff..b8c9251d 100644 --- a/internal_filesystem/lib/mpos/ui/input_manager.py +++ b/internal_filesystem/lib/mpos/ui/input_manager.py @@ -2,8 +2,8 @@ """ InputManager - Framework for managing input device interactions. -Provides a clean API for accessing input device data like pointer/touch coordinates -and focus management. +Provides a clean API for accessing input device data like pointer/touch coordinates, +focus management, and input device registration. All methods are class methods, so no instance creation is needed. """ @@ -15,6 +15,44 @@ class InputManager: Provides static/class methods for accessing input device properties and data. """ + _registered_indevs = [] # List of registered input devices + + @classmethod + def register_indev(cls, indev): + """ + Register an input device for later querying. + Called by board initialization code. + + Parameters: + - indev: LVGL input device object + """ + if indev and indev not in cls._registered_indevs: + cls._registered_indevs.append(indev) + + @classmethod + def list_indevs(cls): + """ + Get list of all registered input devices. + + Returns: list of LVGL input device objects + """ + return cls._registered_indevs + + @classmethod + def has_indev_type(cls, indev_type): + """ + Check if any registered input device has the specified type. + + Parameters: + - indev_type: LVGL input device type (e.g., lv.INDEV_TYPE.KEYPAD) + + Returns: bool - True if device type is available + """ + for indev in cls._registered_indevs: + if indev.get_type() == indev_type: + return True + return False + @classmethod def pointer_xy(cls): """Get current pointer/touch coordinates.""" @@ -30,7 +68,8 @@ class InputManager: def emulate_focus_obj(cls, focusgroup, target): """ Emulate setting focus to a specific object in the focus group. - This function is needed because LVGL doesn't have a direct set_focus method. + This function is needed because the current version of LVGL doesn't have a direct set_focus method. + It should exist, according to the API, so maybe it will be available in the next release and this function might no longer be needed someday. """ if not focusgroup: print("emulate_focus_obj needs a focusgroup, returning...")