InputManager: add has_indev_type to figure out if there are buttons

This commit is contained in:
Thomas Farstrike
2026-01-25 21:52:25 +01:00
parent 2a70e32375
commit 8e734b1e53
4 changed files with 51 additions and 4 deletions
@@ -1,3 +1,5 @@
# This is a copy of LightningPiggyApp's confetti.py
import time
import random
import lvgl as lv
@@ -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.
+3 -1
View File
@@ -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()
@@ -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...")