Skip to content

Commit f1ef9f9

Browse files
fri3d-2024: fix joystick left/right direction
1 parent 176b59e commit f1ef9f9

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

internal_filesystem/boot_fri3d-2024.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
import i2c
88
import math
99

10+
import micropython
11+
import gc
12+
1013
import lvgl as lv
1114
import task_handler
1215

@@ -143,7 +146,7 @@ def read_joystick_angle(threshold=0.1):
143146
return None # Neutral position
144147

145148
# Calculate angle in degrees with UP = 0°, clockwise
146-
angle_rad = math.atan2(-x, y)
149+
angle_rad = math.atan2(x, y)
147150
angle_deg = math.degrees(angle_rad)
148151
angle_deg = (angle_deg + 360) % 360 # Normalize to [0, 360)
149152
return angle_deg
@@ -185,10 +188,21 @@ def keypad_read_cb(indev, data):
185188
current_key = lv.KEY.END
186189
else:
187190
# 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
189192
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
192206
joystick = read_joystick()
193207
if joystick == "LEFT":
194208
current_key = lv.KEY.LEFT
@@ -234,7 +248,6 @@ def keypad_read_cb(indev, data):
234248

235249
# Handle ESC for back navigation (only on initial PRESSED)
236250
if current_key == lv.KEY.ESC and last_state == lv.INDEV_STATE.PRESSED and since_last_repeat == 0:
237-
import mpos
238251
mpos.ui.back_screen()
239252

240253
group = lv.group_create()

0 commit comments

Comments
 (0)