You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/frameworks/input-manager.md
+141-1Lines changed: 141 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# InputManager
2
2
3
-
InputManager is a singleton framework that provides a unified API for managing input device interactions, including pointer/touch coordinates and focus management.
3
+
InputManager is a singleton framework that provides a unified API for managing input device interactions, including pointer/touch coordinates, focus management, and input device registration.
4
4
5
5
## Overview
6
6
@@ -11,13 +11,16 @@ InputManager centralizes all input-related operations in a single class with cla
11
11
-**Testable** - InputManager can be tested independently
12
12
-**Focus Control** - Emulate focus on specific UI objects
13
13
-**Pointer Access** - Get current touch/pointer coordinates
14
+
-**Device Registration** - Register and query available input devices by type
14
15
15
16
## Architecture
16
17
17
18
InputManager is implemented as a singleton using class variables and class methods:
18
19
19
20
```python
20
21
classInputManager:
22
+
_registered_indevs = [] # List of registered input devices
23
+
21
24
@classmethod
22
25
defpointer_xy(cls):
23
26
"""Get current pointer/touch coordinates."""
@@ -33,6 +36,25 @@ class InputManager:
33
36
defemulate_focus_obj(cls, focusgroup, target):
34
37
"""Emulate setting focus to a specific object."""
35
38
# ... implementation
39
+
40
+
@classmethod
41
+
defregister_indev(cls, indev):
42
+
"""Register an input device for later querying."""
43
+
if indev and indev notincls._registered_indevs:
44
+
cls._registered_indevs.append(indev)
45
+
46
+
@classmethod
47
+
deflist_indevs(cls):
48
+
"""Get list of all registered input devices."""
49
+
returncls._registered_indevs
50
+
51
+
@classmethod
52
+
defhas_indev_type(cls, indev_type):
53
+
"""Check if any registered input device has the specified type."""
54
+
for indev incls._registered_indevs:
55
+
if indev.get_type() == indev_type:
56
+
returnTrue
57
+
returnFalse
36
58
```
37
59
38
60
No instance creation is needed - all methods are class methods that operate on class variables.
Register an input device for later querying by type.
127
+
128
+
This method is called by board initialization code to register available input devices. Apps can then query these devices without hardcoding hardware IDs.
129
+
130
+
**Parameters:**
131
+
-`indev` (lv.indev): The LVGL input device to register
132
+
133
+
**Returns:** None
134
+
135
+
**Example:**
136
+
```python
137
+
# In board initialization (e.g., fri3d_2024.py)
138
+
indev = lv.indev_create()
139
+
indev.set_type(lv.INDEV_TYPE.KEYPAD)
140
+
indev.set_read_cb(keypad_read_cb)
141
+
InputManager.register_indev(indev)
142
+
```
143
+
144
+
#### `list_indevs()`
145
+
Get list of all registered input devices.
146
+
147
+
**Returns:** list - List of registered LVGL input devices
148
+
149
+
**Example:**
150
+
```python
151
+
devices = InputManager.list_indevs()
152
+
for indev in devices:
153
+
print(f"Device type: {indev.get_type()}")
154
+
```
155
+
156
+
#### `has_indev_type(indev_type)`
157
+
Check if any registered input device has the specified type.
158
+
159
+
This is a convenience method for checking device capabilities without iterating through the device list.
160
+
161
+
**Parameters:**
162
+
-`indev_type` (int): LVGL input device type (e.g., `lv.INDEV_TYPE.KEYPAD`, `lv.INDEV_TYPE.POINTER`)
163
+
164
+
**Returns:** bool - True if a device with the specified type is registered, False otherwise
165
+
166
+
**Example:**
167
+
```python
168
+
if InputManager.has_indev_type(lv.INDEV_TYPE.KEYPAD):
0 commit comments