|
| 1 | +import lcd_bus |
| 2 | +import lvgl as lv |
| 3 | +import sdl_display |
| 4 | +import sdl_pointer |
| 5 | + |
| 6 | +TFT_HOR_RES=320 |
| 7 | +TFT_VER_RES=240 |
| 8 | + |
| 9 | +bus = lcd_bus.SDLBus(flags=0) |
| 10 | + |
| 11 | +buf1 = bus.allocate_framebuffer(TFT_HOR_RES * TFT_VER_RES * 3, 0) |
| 12 | + |
| 13 | +display = sdl_display.SDLDisplay(data_bus=bus,display_width=TFT_HOR_RES,display_height=TFT_VER_RES,frame_buffer1=buf1,color_space=lv.COLOR_FORMAT.RGB888) |
| 14 | +display.init() |
| 15 | + |
| 16 | +mouse = sdl_pointer.SDLPointer() |
| 17 | + |
| 18 | +# Swipe detection state |
| 19 | +start_y = None # Store the starting Y-coordinate of the mouse press |
| 20 | +def swipe_read_cb(indev_drv, data): |
| 21 | + global start_y |
| 22 | + |
| 23 | + pressed = mouse.get_state() |
| 24 | + #print(f"mouse_state: {pressed}") |
| 25 | + point = lv.point_t() |
| 26 | + mouse.get_point(point) |
| 27 | + #print(f"X={point.x}, Y={point.y}") |
| 28 | + x, y = point.x, point.y |
| 29 | + |
| 30 | + if pressed and start_y is None: |
| 31 | + start_y = y |
| 32 | + # Mouse button pressed (start of potential swipe) |
| 33 | + if y <= NOTIFICATION_BAR_HEIGHT: |
| 34 | + # Store starting Y if press is in the notification bar area |
| 35 | + print(f"Mouse press at Y={start_y}") |
| 36 | + elif pressed and start_y is not None: |
| 37 | + # Mouse dragged while pressed (potential swipe in progress) |
| 38 | + # Check for downward swipe (y increased significantly) |
| 39 | + if y > start_y + 50: # Threshold for swipe detection (adjust as needed) |
| 40 | + print("long swipe down") |
| 41 | + if start_y <= NOTIFICATION_BAR_HEIGHT: |
| 42 | + print("Swipe Down Detected from Notification Bar") |
| 43 | + open_drawer() |
| 44 | + start_y = None # Reset after swipe |
| 45 | + else: |
| 46 | + # Mouse button released |
| 47 | + if start_y is not None and y < start_y - 50: # Threshold for swipe-up |
| 48 | + print("Swipe Up Detected") |
| 49 | + close_drawer() |
| 50 | + start_y = None # Reset on release |
| 51 | + |
| 52 | +# Register the custom read callback with the input device |
| 53 | +indev = lv.indev_create() |
| 54 | +indev.set_type(lv.INDEV_TYPE.POINTER) |
| 55 | +indev.set_read_cb(swipe_read_cb) |
| 56 | + |
| 57 | +print("boot_unix.py finished") |
| 58 | + |
0 commit comments