|
7 | 7 | import i2c |
8 | 8 | import math |
9 | 9 |
|
| 10 | +import micropython |
| 11 | +import gc |
| 12 | + |
10 | 13 | import lvgl as lv |
11 | 14 | import task_handler |
12 | 15 |
|
@@ -143,7 +146,7 @@ def read_joystick_angle(threshold=0.1): |
143 | 146 | return None # 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 | return angle_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 | if angle and time.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 | + except Exception as e: |
| 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 | if joystick == "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 | if current_key == lv.KEY.ESC and last_state == lv.INDEV_STATE.PRESSED and since_last_repeat == 0: |
237 | | - import mpos |
238 | 251 | mpos.ui.back_screen() |
239 | 252 |
|
240 | 253 | group = lv.group_create() |
|
0 commit comments