Skip to content

Commit 8e734b1

Browse files
InputManager: add has_indev_type to figure out if there are buttons
1 parent 2a70e32 commit 8e734b1

File tree

4 files changed

+51
-4
lines changed

4 files changed

+51
-4
lines changed

internal_filesystem/apps/com.micropythonos.confetti/assets/confetti.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# This is a copy of LightningPiggyApp's confetti.py
2+
13
import time
24
import random
35
import lvgl as lv

internal_filesystem/lib/mpos/board/fri3d_2024.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import mpos.ui
1717
import mpos.ui.focus_direction
18+
from mpos import InputManager
1819

1920
from ..task_manager import TaskManager
2021

@@ -258,6 +259,9 @@ def keypad_read_cb(indev, data):
258259
indev.set_display(disp) # different from display
259260
indev.enable(True) # NOQA
260261

262+
# Register the input device with InputManager
263+
InputManager.register_indev(indev)
264+
261265
# Battery voltage ADC measuring
262266
# NOTE: GPIO13 is on ADC2, which requires WiFi to be disabled during reading on ESP32-S3.
263267
# battery_voltage.py handles this automatically: disables WiFi, reads ADC, reconnects WiFi.

internal_filesystem/lib/mpos/board/linux.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import mpos.indev.mpos_sdl_keyboard
88
import mpos.ui
99
import mpos.ui.focus_direction
10+
from mpos import InputManager
1011

1112
# Same as Waveshare ESP32-S3-Touch-LCD-2 and Fri3d Camp 2026 Badge
1213
TFT_HOR_RES=320
@@ -71,14 +72,15 @@ def catch_escape_key(indev, indev_data):
7172

7273
sdlkeyboard._read(indev, indev_data)
7374

74-
#import sdl_keyboard
7575
sdlkeyboard = mpos.indev.mpos_sdl_keyboard.MposSDLKeyboard()
7676
sdlkeyboard._indev_drv.set_read_cb(catch_escape_key) # check for escape
77+
InputManager.register_indev(sdlkeyboard)
7778
try:
7879
sdlkeyboard.set_paste_text_callback(mpos.clipboard.paste_text)
7980
except Exception as e:
8081
print("Warning: could not set paste_text callback for sdlkeyboard, copy-paste won't work")
8182

83+
8284
#def keyboard_cb(event):
8385
# global canvas
8486
# event_code=event.get_code()

internal_filesystem/lib/mpos/ui/input_manager.py

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"""
33
InputManager - Framework for managing input device interactions.
44
5-
Provides a clean API for accessing input device data like pointer/touch coordinates
6-
and focus management.
5+
Provides a clean API for accessing input device data like pointer/touch coordinates,
6+
focus management, and input device registration.
77
All methods are class methods, so no instance creation is needed.
88
"""
99

@@ -15,6 +15,44 @@ class InputManager:
1515
Provides static/class methods for accessing input device properties and data.
1616
"""
1717

18+
_registered_indevs = [] # List of registered input devices
19+
20+
@classmethod
21+
def register_indev(cls, indev):
22+
"""
23+
Register an input device for later querying.
24+
Called by board initialization code.
25+
26+
Parameters:
27+
- indev: LVGL input device object
28+
"""
29+
if indev and indev not in cls._registered_indevs:
30+
cls._registered_indevs.append(indev)
31+
32+
@classmethod
33+
def list_indevs(cls):
34+
"""
35+
Get list of all registered input devices.
36+
37+
Returns: list of LVGL input device objects
38+
"""
39+
return cls._registered_indevs
40+
41+
@classmethod
42+
def has_indev_type(cls, indev_type):
43+
"""
44+
Check if any registered input device has the specified type.
45+
46+
Parameters:
47+
- indev_type: LVGL input device type (e.g., lv.INDEV_TYPE.KEYPAD)
48+
49+
Returns: bool - True if device type is available
50+
"""
51+
for indev in cls._registered_indevs:
52+
if indev.get_type() == indev_type:
53+
return True
54+
return False
55+
1856
@classmethod
1957
def pointer_xy(cls):
2058
"""Get current pointer/touch coordinates."""
@@ -30,7 +68,8 @@ def pointer_xy(cls):
3068
def emulate_focus_obj(cls, focusgroup, target):
3169
"""
3270
Emulate setting focus to a specific object in the focus group.
33-
This function is needed because LVGL doesn't have a direct set_focus method.
71+
This function is needed because the current version of LVGL doesn't have a direct set_focus method.
72+
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.
3473
"""
3574
if not focusgroup:
3675
print("emulate_focus_obj needs a focusgroup, returning...")

0 commit comments

Comments
 (0)