|
7 | 7 | importi2c |
8 | 8 | importmath |
9 | 9 |
|
| 10 | +importmicropython |
| 11 | +importgc |
| 12 | + |
10 | 13 | importlvglaslv |
11 | 14 | importtask_handler |
12 | 15 |
|
@@ -143,7 +146,7 @@ def read_joystick_angle(threshold=0.1): |
143 | 146 | returnNone# Neutral position |
144 | 147 |
|
145 | 148 | # Calculate angle in degrees with UP = 0°, clockwise |
146 | | -angle_rad=math.atan2(-x,y) |
| 149 | +angle_rad=math.atan2(x,y) |
147 | 150 | angle_deg=math.degrees(angle_rad) |
148 | 151 | angle_deg= (angle_deg+360)%360# Normalize to [0, 360) |
149 | 152 | returnangle_deg |
@@ -185,10 +188,21 @@ def keypad_read_cb(indev, data): |
185 | 188 | current_key=lv.KEY.END |
186 | 189 | else: |
187 | 190 | # Check joystick |
188 | | -angle=read_joystick_angle(0.25) |
| 191 | +angle=read_joystick_angle(0.30)# 0.25-0.27 is right on the edge so 0.30 seems good |
189 | 192 | ifangleandtime.time()<60: |
190 | | -print(f"joystick angle:{angle}") |
191 | | -mpos.ui.focus_direction.move_focus_direction(angle) |
| 193 | +print(f"got joystick angle:{angle}") |
| 194 | +#gc.collect() |
| 195 | +print("Memory after joystick:",end=" ") |
| 196 | +micropython.mem_info() |
| 197 | +try: |
| 198 | +mpos.ui.focus_direction.move_focus_direction(angle) |
| 199 | +exceptExceptionase: |
| 200 | +print(f"Error in move_focus_direction:{e}") |
| 201 | +print(f"after joystick angle:{angle}") |
| 202 | +#gc.collect() |
| 203 | +print("Memory after joystick:",end=" ") |
| 204 | +micropython.mem_info() |
| 205 | +else:# old behavior |
192 | 206 | joystick=read_joystick() |
193 | 207 | ifjoystick=="LEFT": |
194 | 208 | current_key=lv.KEY.LEFT |
@@ -234,7 +248,6 @@ def keypad_read_cb(indev, data): |
234 | 248 |
|
235 | 249 | # Handle ESC for back navigation (only on initial PRESSED) |
236 | 250 | ifcurrent_key==lv.KEY.ESCandlast_state==lv.INDEV_STATE.PRESSEDandsince_last_repeat==0: |
237 | | -importmpos |
238 | 251 | mpos.ui.back_screen() |
239 | 252 |
|
240 | 253 | group=lv.group_create() |
|