Skip to content

Commit 9ae3824

Browse files
fri3d-2024: support repeat for joystick/arrow keys
1 parent 169c482 commit 9ae3824

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

internal_filesystem/boot_fri3d-2024.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,16 @@ def keypad_read_cb(indev, data):
190190
# Check joystick
191191
angle = read_joystick_angle(0.30) # 0.25-0.27 is right on the edge so 0.30 should be good
192192
if angle:
193-
try:
194-
mpos.ui.focus_direction.move_focus_direction(angle)
195-
except Exception as e:
196-
print(f"Exception from move_focus_direction: {e}")
193+
if angle > 45 and angle < 135:
194+
current_key = lv.KEY.RIGHT
195+
elif angle > 135 and angle < 225:
196+
current_key = lv.KEY.DOWN
197+
elif angle > 225 and angle < 315:
198+
current_key = lv.KEY.LEFT
199+
elif angle < 45 or angle > 315:
200+
current_key = lv.KEY.UP
201+
else:
202+
print(f"WARNING: unhandled joystick angle {angle}") # maybe we could also handle diagonals?
197203

198204
# Key repeat logic
199205
if current_key:
@@ -229,8 +235,17 @@ def keypad_read_cb(indev, data):
229235
last_repeat_time = 0
230236

231237
# Handle ESC for back navigation (only on initial PRESSED)
232-
if current_key == lv.KEY.ESC and last_state == lv.INDEV_STATE.PRESSED and since_last_repeat == 0:
233-
mpos.ui.back_screen()
238+
if last_state == lv.INDEV_STATE.PRESSED:
239+
if current_key == lv.KEY.ESC and since_last_repeat == 0:
240+
mpos.ui.back_screen()
241+
elif current_key == lv.KEY.RIGHT:
242+
mpos.ui.focus_direction.move_focus_direction(90)
243+
elif current_key == lv.KEY.LEFT:
244+
mpos.ui.focus_direction.move_focus_direction(270)
245+
elif current_key == lv.KEY.UP:
246+
mpos.ui.focus_direction.move_focus_direction(0)
247+
elif current_key == lv.KEY.DOWN:
248+
mpos.ui.focus_direction.move_focus_direction(180)
234249

235250
group = lv.group_create()
236251
group.set_default()

0 commit comments

Comments
 (0)