From f1ef9f9c4f1e847c97b7cdc17c6b800f58c80e62 Mon Sep 17 00:00:00 2001 From: Thomas Farstrike Date: Mon, 20 Oct 2025 13:20:37 +0200 Subject: [PATCH] fri3d-2024: fix joystick left/right direction --- internal_filesystem/boot_fri3d-2024.py | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/internal_filesystem/boot_fri3d-2024.py b/internal_filesystem/boot_fri3d-2024.py index c8de5829..f56c141f 100644 --- a/internal_filesystem/boot_fri3d-2024.py +++ b/internal_filesystem/boot_fri3d-2024.py @@ -7,6 +7,9 @@ import cst816s import i2c import math +import micropython +import gc + import lvgl as lv import task_handler @@ -143,7 +146,7 @@ def read_joystick_angle(threshold=0.1): return None # Neutral position # Calculate angle in degrees with UP = 0°, clockwise - angle_rad = math.atan2(-x, y) + angle_rad = math.atan2(x, y) angle_deg = math.degrees(angle_rad) angle_deg = (angle_deg + 360) % 360 # Normalize to [0, 360) return angle_deg @@ -185,10 +188,21 @@ def keypad_read_cb(indev, data): current_key = lv.KEY.END else: # Check joystick - angle = read_joystick_angle(0.25) + angle = read_joystick_angle(0.30) # 0.25-0.27 is right on the edge so 0.30 seems good if angle and time.time() < 60: - print(f"joystick angle: {angle}") - mpos.ui.focus_direction.move_focus_direction(angle) + print(f"got joystick angle: {angle}") + #gc.collect() + print("Memory after joystick:", end=" ") + micropython.mem_info() + try: + mpos.ui.focus_direction.move_focus_direction(angle) + except Exception as e: + print(f"Error in move_focus_direction: {e}") + print(f"after joystick angle: {angle}") + #gc.collect() + print("Memory after joystick:", end=" ") + micropython.mem_info() + else: # old behavior joystick = read_joystick() if joystick == "LEFT": current_key = lv.KEY.LEFT @@ -234,7 +248,6 @@ def keypad_read_cb(indev, data): # Handle ESC for back navigation (only on initial PRESSED) if current_key == lv.KEY.ESC and last_state == lv.INDEV_STATE.PRESSED and since_last_repeat == 0: - import mpos mpos.ui.back_screen() group = lv.group_create()