|
81 | 81 | lv.init() |
82 | 82 | display.set_rotation(lv.DISPLAY_ROTATION._90) # must be done after initializing display and creating the touch drivers, to ensure proper handling |
83 | 83 |
|
84 | | -# Gesture IDs: |
85 | | -# 0: press |
86 | | -# 1: swipe from left to USB port |
87 | | -# 2: swipe from USB port to left |
88 | | -# 3: top to bottom |
89 | | -# 4: bottom to top |
90 | | -# 5: release |
91 | | -# 12: long press |
92 | | - |
93 | | -start_y = None # Variable to store the starting Y-coordinate of a touch |
94 | | -def handle_gesture(pin): |
95 | | - global start_y # Access the global start_y variable |
96 | | - indev._read_reg(0x01) |
97 | | - gesture_id = indev._rx_buf[0] |
98 | | - indev._read_reg(0x02) |
99 | | - finger_num = indev._rx_buf[0] |
100 | | - indev._read_reg(0x03) |
101 | | - x_h = indev._rx_buf[0] |
102 | | - indev._read_reg(0x04) |
103 | | - x_l = indev._rx_buf[0] |
104 | | - x = ((x_h & 0x0F) << 8) | x_l |
105 | | - indev._read_reg(0x05) |
106 | | - y_h = indev._rx_buf[0] |
107 | | - indev._read_reg(0x06) |
108 | | - y_l = indev._rx_buf[0] |
109 | | - y = ((y_h & 0x0F) << 8) | y_l |
110 | | - #print(f"GestureID={gesture_id},FingerNum={finger_num},X={x},Y={y}") |
111 | | - temp = y |
112 | | - y = TFT_VER_RES - x |
113 | | - #x = TFT_HOR_RES - temp |
114 | | - x = temp |
115 | | - #print(f"Corrected GestureID={gesture_id},FingerNum={finger_num},X={x},Y={y}") |
116 | | - if gesture_id == 0x00 and start_y is None: # Press (touch start) |
117 | | - # Store the starting Y-coordinate |
118 | | - start_y = y |
119 | | - #print(f"Touch started at Y={start_y}") |
120 | | - elif gesture_id == 0x04: # Swipe up |
121 | | - # print("Swipe Up Detected") |
122 | | - mpos.ui.close_drawer() |
123 | | - start_y = None # Clear start_y after gesture |
124 | | - elif gesture_id == 0x03: # Swipe down |
125 | | - if start_y is not None and start_y <= mpos.ui.NOTIFICATION_BAR_HEIGHT: |
126 | | - # print("Swipe Down Detected from Notification Bar") |
127 | | - mpos.ui.open_drawer() |
128 | | - start_y = None # Clear start_y after gesture |
129 | | - elif gesture_id == 0x05: # Release |
130 | | - start_y = None # Clear start_y on release |
131 | | - |
132 | | -indev._write_reg(0xEC,0x06) |
133 | | -indev._write_reg(0xFA,0x50) |
134 | | -irq_pin=machine.Pin(46,machine.Pin.IN,machine.Pin.PULL_UP) |
135 | | -irq_pin.irq(trigger=machine.Pin.IRQ_FALLING, handler=handle_gesture) |
136 | | - |
137 | 84 | print("boot.py finished") |
0 commit comments