Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1ff653e

Browse files
Debounce buttons to workaround PRESSING focus loss
In LVGL 9.2.2, the lv_keyboard widget seems to lose focus when a PRESSING (long press) is received.
1 parent5e23c22 commit1ff653e

File tree

1 file changed

+49
-28
lines changed

1 file changed

+49
-28
lines changed

‎internal_filesystem/boot_fri3d-2024.py‎

Lines changed: 49 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -116,53 +116,74 @@ def read_joystick():
116116
returnNone# No key triggered
117117

118118

119+
# Track button states for debouncing (only for buttons, not joystick)
120+
last_button_key=None
121+
last_button_state=lv.INDEV_STATE.RELEASED
122+
119123
# Read callback
120124
# Warning: This gets called several times per second, and if it outputs continuous debugging on the serial line,
121125
# that will break tools like mpremote from working properly to upload new files over the serial line, thus needing a reflash.
122126
defkeypad_read_cb(indev,data):
123-
data.continue_reading=False# No more data to read
124-
# Check GPIOs and set key/state (only one key at a time)
127+
globallast_button_key,last_button_state
128+
data.continue_reading=False
129+
130+
# Check buttons and joystick
131+
current_key=None
132+
is_joystick=False
133+
134+
# Check buttons first (debounced)
125135
ifbtn_x.value()==0:
126-
data.key=lv.KEY.ESC
127-
data.state=lv.INDEV_STATE.PRESSED
128-
mpos.ui.back_screen()
136+
current_key=lv.KEY.ESC
129137
elifbtn_y.value()==0:
130-
data.key=lv.KEY.ESC
131-
data.state=lv.INDEV_STATE.PRESSED
132-
mpos.ui.back_screen()
138+
current_key=lv.KEY.PREV
133139
elifbtn_a.value()==0:
134-
#print("A pressed")
135-
data.key=lv.KEY.ENTER
136-
data.state=lv.INDEV_STATE.PRESSED
140+
current_key=lv.KEY.NEXT
137141
elifbtn_b.value()==0:
138-
#print("B pressed")
139-
data.key=lv.KEY.ENTER
140-
data.state=lv.INDEV_STATE.PRESSED
142+
current_key=lv.KEY.ENTER
141143
elifbtn_menu.value()==0:
142-
data.key=lv.KEY.HOME
143-
data.state=lv.INDEV_STATE.PRESSED
144+
current_key=lv.KEY.HOME
144145
elifbtn_start.value()==0:
145-
data.key=lv.KEY.END
146-
data.state=lv.INDEV_STATE.PRESSED
146+
current_key=lv.KEY.END
147147
else:
148-
data.state=lv.INDEV_STATE.RELEASED
149-
ifdata.state==lv.INDEV_STATE.RELEASED:
148+
# Check joystick (not debounced)
150149
joystick=read_joystick()
151150
ifjoystick=="LEFT":
152-
data.key=lv.KEY.PREV
153-
data.state=lv.INDEV_STATE.PRESSED
151+
current_key=lv.KEY.LEFT
152+
is_joystick=True
154153
elifjoystick=="RIGHT":
155-
data.key=lv.KEY.NEXT
156-
data.state=lv.INDEV_STATE.PRESSED
154+
current_key=lv.KEY.RIGHT
155+
is_joystick=True
157156
elifjoystick=="UP":
158-
data.key=lv.KEY.UP
159-
data.state=lv.INDEV_STATE.PRESSED
157+
current_key=lv.KEY.UP
158+
is_joystick=True
160159
elifjoystick=="DOWN":
161-
data.key=lv.KEY.DOWN
160+
current_key=lv.KEY.DOWN
161+
is_joystick=True
162+
163+
# Handle joystick (continuous pressing allowed)
164+
ifis_joystickandcurrent_key:
165+
data.key=current_key
166+
data.state=lv.INDEV_STATE.PRESSED# Always send PRESSED for joystick
167+
# Handle buttons (debounced)
168+
elifcurrent_key:
169+
ifcurrent_key!=last_button_key:
170+
data.key=current_key
162171
data.state=lv.INDEV_STATE.PRESSED
172+
last_button_key=current_key
173+
last_button_state=lv.INDEV_STATE.PRESSED
163174
else:
164-
data.state=lv.INDEV_STATE.RELEASED
175+
data.state=lv.INDEV_STATE.RELEASED# Avoid continuous PRESSED
176+
else:
177+
# No input
178+
data.key=last_button_keyiflast_button_keyelselv.KEY.ENTER
179+
data.state=lv.INDEV_STATE.RELEASED
180+
last_button_key=None
181+
last_button_state=lv.INDEV_STATE.RELEASED
165182

183+
# Handle ESC for back navigation
184+
ifcurrent_key==lv.KEY.ESCandlast_button_state==lv.INDEV_STATE.PRESSED:
185+
importmpos
186+
mpos.ui.back_screen()
166187

167188
group=lv.group_create()
168189
group.set_default()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp