|
32 | 32 |
|
33 | 33 | #keyboard.add_event_cb(keyboard_cb, lv.EVENT.ALL, None) |
34 | 34 |
|
35 | | - |
36 | | -# Swipe detection state |
37 | | -start_y = None # Store the starting Y-coordinate of the mouse press |
38 | | -start_x = None # Store the starting X-coordinate for left-edge swipe |
39 | | - |
40 | | -# the problem is, this whole thing is called after the click/release has been processed by the screen... |
41 | | -def swipe_read_cb(indev_drv, data): |
42 | | - global start_y, start_x |
43 | | - global indev |
44 | | - global mouse |
45 | | - |
46 | | - mouseindev = mouse._indevs[0] |
47 | | - #print(indev) # none... |
48 | | - #print(mouse.get_event_count()) |
49 | | - #print(mouseindev.get_event_count()) # 0 |
50 | | - #mouseindev.stop_processing() |
51 | | - #mouseindev.enable(False) # well this works... |
52 | | - #mouseindev.__x = -1 # works |
53 | | - #mouseindev.__y = -1 # works |
54 | | - #print(mouse._indevs[0]) |
55 | | - |
56 | | - pressed = mouse.get_state() # Get mouse/touch pressed state |
57 | | - point = lv.point_t() |
58 | | - mouse.get_point(point) # Get current coordinates |
59 | | - #indev.get_point(point) # Always returns 0,0 |
60 | | - x, y = point.x, point.y |
61 | | - |
62 | | - #indev.stop_processing() |
63 | | - #data.state = lv.INDEV_STATE.RELEASED # Ensure release state |
64 | | - #data.point.x = -1 # Move point off-screen to prevent widget interaction |
65 | | - #data.point.y = -1 |
66 | | - #indev.stop_processing() # doesn't work on unix |
67 | | - #return |
68 | | - #mouse.stop_processing() |
69 | | - |
70 | | - if pressed and start_y is None and start_x is None: |
71 | | - # Mouse/touch pressed (start of potential swipe) |
72 | | - start_y = y # Store Y for vertical swipe detection |
73 | | - start_x = x # Store X for horizontal swipe detection |
74 | | - #print(f"Mouse press at X={start_x}, Y={start_y}") |
75 | | - |
76 | | - # Check if press is in notification bar (for swipe down) |
77 | | - if y <= mpos.ui.NOTIFICATION_BAR_HEIGHT: |
78 | | - print(f"Press in notification bar at Y={start_y}") |
79 | | - # Check if press is near left edge (for swipe right) |
80 | | - if x <= 20: # Adjust threshold for left edge (e.g., 20 pixels) |
81 | | - print(f"Press near left edge at X={start_x}") |
82 | | - elif pressed and (start_y is not None or start_x is not None): |
83 | | - # Mouse/touch dragged while pressed (potential swipe in progress) |
84 | | - |
85 | | - # Check for downward swipe (y increased significantly) |
86 | | - if start_y is not None and y > start_y + 50: # Threshold for swipe down |
87 | | - print("Long swipe down") |
88 | | - if start_y <= mpos.ui.NOTIFICATION_BAR_HEIGHT: |
89 | | - print("Swipe Down Detected from Notification Bar") |
90 | | - mpos.ui.open_drawer() |
91 | | - start_y = None # Reset Y after swipe |
92 | | - start_x = None # Reset X to avoid conflicts |
93 | | - else: |
94 | | - # Mouse/touch released |
95 | | - if start_y is not None and y < start_y - 50: # Threshold for swipe-up |
96 | | - print("Swipe Up Detected") |
97 | | - mpos.ui.close_drawer() |
98 | | - |
99 | | - # Check for rightward swipe from left edge (x increased significantly) |
100 | | - if start_x is not None and x > start_x + 50: # Threshold for swipe right |
101 | | - print("Long swipe right") |
102 | | - if start_x <= 20: # Confirm swipe started near left edge |
103 | | - print("Swipe Right Detected from Left Edge") |
104 | | - #mouseindev.enable(False) # well this works... |
105 | | - mouseindev.wait_release() |
106 | | - mpos.ui.back_screen() # Call custom method for left menu |
107 | | - start_y = None # Reset Y after swipe |
108 | | - start_x = None # Reset X after swipe |
109 | | - |
110 | | - # Reset both coordinates on release |
111 | | - start_y = None |
112 | | - start_x = None |
113 | | - |
114 | | -def get_xy(): |
115 | | - indev = lv.indev_active() |
116 | | - if indev: |
117 | | - point = lv.point_t() |
118 | | - indev.get_point(point) |
119 | | - return point.x, point.y |
120 | | - else: |
121 | | - return indev_error_x,indev_error_y # make it visible that this occurred |
122 | | - |
123 | | -def test_indev_cb(event): |
124 | | - print("test_indev_cb") |
125 | | - |
126 | | -def test_cb(event): |
127 | | - print("test_cb") |
128 | | - event_code=event.get_code() |
129 | | - name = mpos.ui.get_event_name(event_code) |
130 | | - print(f"lv_event_t: code={event_code}, name={name}") # target={event.get_target()}, user_data={event.get_user_data()}, param={event.get_param()} |
131 | | - x, y = get_xy() |
132 | | - print(f"x,y = {x},{y}") |
133 | | - # try to disable the event |
134 | | - event.stop_processing() |
135 | | - event.stop_bubbling() |
136 | | - #global mouse |
137 | | - #mouseindev = mouse._indevs[0] |
138 | | - #mouseindev.__x = -1 # works |
139 | | - #mouseindev.__y = -1 # works |
140 | | - #mouseindev.wait_release() # results in only PRESSED and then it stops... |
141 | | - #if event_code == lv.EVENT.RELEASED or event_code == lv.EVENT.CLICKED: |
142 | | - # mouseindev.wait_release() # results in only PRESSED and then it stops... |
143 | | - #mouseindev.enable(False) # well this works... |
144 | | - |
145 | | -gesture_start_x = None |
146 | | -gesture_start_y = None |
147 | | -def detect_gesture(event, pressed, x, y): |
148 | | - global mouse |
149 | | - global gesture_start_x, gesture_start_y |
150 | | - |
151 | | - mouseindev = mouse._indevs[0] |
152 | | - event.stop_processing() |
153 | | - event.stop_bubbling() |
154 | | - #event.remove_all() |
155 | | - |
156 | | - if pressed and gesture_start_x is None : |
157 | | - # Mouse/touch pressed (start of potential swipe) |
158 | | - gesture_start_y = y # Store Y for vertical swipe detection |
159 | | - gesture_start_x = x # Store X for horizontal swipe detection |
160 | | - #print(f"Mouse press at X={start_x}, Y={start_y}") |
161 | | - |
162 | | - # Check if press is in notification bar (for swipe down) |
163 | | - if y <= mpos.ui.NOTIFICATION_BAR_HEIGHT: |
164 | | - print(f"Press in notification bar at Y={start_y}") |
165 | | - # Check if press is near left edge (for swipe right) |
166 | | - if x <= 20: # Adjust threshold for left edge (e.g., 20 pixels) |
167 | | - print(f"Press near left edge at X={start_x}") |
168 | | - elif pressed and gesture_start_x is not None: |
169 | | - # Mouse/touch dragged while pressed (potential swipe in progress) |
170 | | - print("tracking pressed") |
171 | | - if gesture_start_x <= 20: # Confirm swipe started near left edge |
172 | | - print("tracking pressed with swipe started left") |
173 | | - #mpos.ui.back_screen() # Call custom method for left menu |
174 | | - mouse.wait_release() # causes only presses to be detected anymore |
175 | | - #mouseindev.wait_release() # causes only presses to be detected anymore |
176 | | - #event.stop_processing() |
177 | | - #event.stop_bubbling() |
178 | | - #mouseindev.__x = -1 |
179 | | - #mouseindev.__y = -1 |
180 | | - #mouseindev.enable(False) # causes no pressed to be detected anymore because no events |
181 | | - # Idea: show a full-screen widget that captures the presses? |
182 | | - else: |
183 | | - # Check for rightward swipe from left edge (x increased significantly) |
184 | | - if gesture_start_x is not None and x > gesture_start_x + 50: # Threshold for swipe right |
185 | | - print("Long swipe right") |
186 | | - if gesture_start_x <= 20: # Confirm swipe started near left edge |
187 | | - print("!!! Swipe Right Detected from Left Edge") |
188 | | - mpos.ui.back_screen() # Call custom method for left menu |
189 | | - #mouse.wait_release() |
190 | | - #mouseindev.wait_release() |
191 | | - #event.stop_processing() |
192 | | - #event.stop_bubbling() |
193 | | - #mouseindev.__x = -1 |
194 | | - #mouseindev.__y = -1 |
195 | | - #mouseindev.enable(False) |
196 | | - |
197 | | - # Reset both coordinates on release |
198 | | - gesture_start_y = None |
199 | | - gesture_start_x = None |
200 | | - #mouseindev.enable(True) # well this works... |
201 | | - |
202 | | - |
203 | | -def detect_swipe(event): |
204 | | - global mouse |
205 | | - pressed = mouse.get_state() # Get mouse/touch pressed state |
206 | | - point = lv.point_t() |
207 | | - mouse.get_point(point) # Get current coordinates |
208 | | - x, y = point.x, point.y |
209 | | - code = event.get_code() |
210 | | - name = mpos.ui.get_event_name(code) |
211 | | - print(f"detect_swipe got {pressed},{x},{y} with {code},{name}") |
212 | | - event.stop_processing() |
213 | | - # crashes: target_obj = event.get_target_obj() # Get the widget that triggered the event |
214 | | - target = event.get_target() # Get the widget that triggered the event |
215 | | - print("Event triggered by target:", target) |
216 | | - ctarget = event.get_current_target() # Get the widget that triggered the event |
217 | | - print("Event triggered by ctarget:", ctarget) |
218 | | - #target_obj = lv.obj.cast(target) |
219 | | - target_obj = lv.obj(target) # Wrap the Blob as an lv.obj |
220 | | - print("Event triggered by object:", target_obj) |
221 | | - # Example: Check if the object is a button |
222 | | - if isinstance(target_obj, lv.button): |
223 | | - print("This is a button!") |
224 | | - elif isinstance(target_obj, lv.obj): |
225 | | - print("This is a generic LVGL object") |
226 | | - #event.remove() |
227 | | - #event.removeall() |
228 | | - # this also works: |
229 | | - #mouseindev = mouse._indevs[0] |
230 | | - #mouseindev.get_point(point) # Always returns 0,0 |
231 | | - #x, y = point.x, point.y |
232 | | - #print(f"detect_swipe got {x},{y} from mouseindev") |
233 | | - |
234 | | - detect_gesture(event, pressed, x, y) |
235 | | - |
236 | | - |
237 | | -# this seems to work for capturing mouse events: |
238 | | -#mouse.add_event_cb(detect_swipe, lv.EVENT.ALL, None) |
239 | | - |
240 | | -def re_enable_upon_release(indev_drv, data): |
241 | | - #print("re_enable_upon_release") |
242 | | - global mouse |
243 | | - #pressed = mouse.get_state() # doesn't change if mouseindev has been disabled |
244 | | - #print(f"re_enable_upon_release {pressed}") |
245 | | - #if not pressed: |
246 | | - mouseindev = mouse._indevs[0] |
247 | | - mouseindev.enable(True) # causes no pressed to be detected anymore because no events |
248 | | - |
249 | | -# Register the custom read callback with the input device |
250 | | -#indev = lv.indev_create() |
251 | | -#indev.set_type(lv.INDEV_TYPE.POINTER) |
252 | | -#indev.set_read_cb(re_enable_upon_release) |
253 | | - |
254 | | -#indev = lv.indev_active() |
255 | | -#if not indev: |
256 | | -# print("ERROR: could not get active indev?!") |
257 | | -#else: |
258 | | -# indev.set_read_cb(test_indev_cb) |
259 | | - |
260 | | - |
261 | | - |
262 | 35 | print("boot_unix.py finished") |
263 | 36 |
|
0 commit comments