|
33 | 33 | #keyboard.add_event_cb(keyboard_cb, lv.EVENT.ALL, None) |
34 | 34 |
|
35 | 35 |
|
| 36 | +# Swipe detection state |
36 | 37 | # Swipe detection state |
37 | 38 | start_y = None # Store the starting Y-coordinate of the mouse press |
| 39 | +start_x = None # Store the starting X-coordinate for left-edge swipe |
| 40 | + |
38 | 41 | def swipe_read_cb(indev_drv, data): |
39 | | - global start_y |
| 42 | + global start_y, start_x |
40 | 43 |
|
41 | | - pressed = mouse.get_state() |
42 | | - #print(f"mouse_state: {pressed}") |
| 44 | + pressed = mouse.get_state() # Get mouse/touch pressed state |
43 | 45 | point = lv.point_t() |
44 | | - mouse.get_point(point) |
45 | | - #print(f"X={point.x}, Y={point.y}") |
| 46 | + mouse.get_point(point) # Get current coordinates |
46 | 47 | x, y = point.x, point.y |
47 | 48 |
|
48 | | - if pressed and start_y is None: |
49 | | - start_y = y |
50 | | - # Mouse button pressed (start of potential swipe) |
| 49 | + if pressed and start_y is None and start_x is None: |
| 50 | + # Mouse/touch pressed (start of potential swipe) |
| 51 | + start_y = y # Store Y for vertical swipe detection |
| 52 | + start_x = x # Store X for horizontal swipe detection |
| 53 | + print(f"Mouse press at X={start_x}, Y={start_y}") |
| 54 | + |
| 55 | + # Check if press is in notification bar (for swipe down) |
51 | 56 | if y <= mpos.ui.NOTIFICATION_BAR_HEIGHT: |
52 | | - # Store starting Y if press is in the notification bar area |
53 | | - print(f"Mouse press at Y={start_y}") |
54 | | - elif pressed and start_y is not None: |
55 | | - # Mouse dragged while pressed (potential swipe in progress) |
| 57 | + print(f"Press in notification bar at Y={start_y}") |
| 58 | + # Check if press is near left edge (for swipe right) |
| 59 | + if x <= 20: # Adjust threshold for left edge (e.g., 20 pixels) |
| 60 | + print(f"Press near left edge at X={start_x}") |
| 61 | + elif pressed and (start_y is not None or start_x is not None): |
| 62 | + # Mouse/touch dragged while pressed (potential swipe in progress) |
| 63 | + |
56 | 64 | # Check for downward swipe (y increased significantly) |
57 | | - if y > start_y + 50: # Threshold for swipe detection (adjust as needed) |
58 | | - print("long swipe down") |
| 65 | + if start_y is not None and y > start_y + 50: # Threshold for swipe down |
| 66 | + print("Long swipe down") |
59 | 67 | if start_y <= mpos.ui.NOTIFICATION_BAR_HEIGHT: |
60 | 68 | print("Swipe Down Detected from Notification Bar") |
61 | 69 | mpos.ui.open_drawer() |
62 | | - start_y = None # Reset after swipe |
| 70 | + start_y = None # Reset Y after swipe |
| 71 | + start_x = None # Reset X to avoid conflicts |
| 72 | + # Check for rightward swipe from left edge (x increased significantly) |
| 73 | + if start_x is not None and x > start_x + 50: # Threshold for swipe right |
| 74 | + print("Long swipe right") |
| 75 | + if start_x <= 20: # Confirm swipe started near left edge |
| 76 | + print("Swipe Right Detected from Left Edge") |
| 77 | + mpos.ui.back_screen() # Call custom method for left menu |
| 78 | + start_y = None # Reset Y after swipe |
| 79 | + start_x = None # Reset X after swipe |
63 | 80 | else: |
64 | | - # Mouse button released |
| 81 | + # Mouse/touch released |
65 | 82 | if start_y is not None and y < start_y - 50: # Threshold for swipe-up |
66 | 83 | print("Swipe Up Detected") |
67 | 84 | mpos.ui.close_drawer() |
68 | | - start_y = None # Reset on release |
| 85 | + |
| 86 | + # Reset both coordinates on release |
| 87 | + start_y = None |
| 88 | + start_x = None |
69 | 89 |
|
70 | 90 | # Register the custom read callback with the input device |
71 | 91 | indev = lv.indev_create() |
|
0 commit comments