Skip to content

Commit b1160e8

Browse files
authored
fix(keyboard): fix the vibration issue with the DEL button (#372)
1 parent 6d8c8cd commit b1160e8

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

core/src/trezor/lvglui/scrs/components/keyboard.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ def __init__(self, parent, is_slip39: bool = False):
234234
self.set_popovers(True)
235235
self.set_textarea(self.ta)
236236
self.add_event_cb(self.event_cb, lv.EVENT.PRESSED, None)
237+
self.add_event_cb(self.event_cb, lv.EVENT.LONG_PRESSED, None)
237238
self.add_event_cb(self.event_cb, lv.EVENT.DRAW_PART_BEGIN, None)
238239
self.add_event_cb(self.event_cb, lv.EVENT.VALUE_CHANGED, None)
239240
self.mnemonic_prompt = lv.obj(parent)
@@ -259,6 +260,7 @@ def __init__(self, parent, is_slip39: bool = False):
259260
self.mnemonic_prompt.add_event_cb(self.on_click, lv.EVENT.CLICKED, None)
260261
self.mnemonic_prompt.add_event_cb(self.on_click, lv.EVENT.PRESSED, None)
261262
self.move_foreground()
263+
self.vibrated = False
262264

263265
def tip_submitted(self):
264266
self.tip_panel = lv.obj(self.parent)
@@ -316,7 +318,10 @@ def event_cb(self, event):
316318
):
317319
return
318320
motor.vibrate()
321+
self.vibrated = True
319322
return
323+
elif code == lv.EVENT.LONG_PRESSED:
324+
self.vibrated = False
320325
if code == lv.EVENT.DRAW_PART_BEGIN:
321326
txt_input = self.ta.get_text()
322327
dsc = lv.obj_draw_part_dsc_t.__cast__(event.get_param())
@@ -328,7 +333,7 @@ def event_cb(self, event):
328333
# dsc.rect_dsc.bg_color = lv_colors.BLACK
329334
elif code == lv.EVENT.VALUE_CHANGED:
330335
utils.lcd_resume()
331-
if isinstance(target, lv.keyboard):
336+
if isinstance(target, lv.keyboard) and not self.vibrated:
332337
btn_id = target.get_selected_btn()
333338
if btn_id == 21:
334339
motor.vibrate()
@@ -524,11 +529,13 @@ def __init__(self, parent, max_len: int = 50, min_len: int = 4) -> None:
524529
self.input_count_tips.add_flag(lv.obj.FLAG.HIDDEN)
525530

526531
self.add_event_cb(self.event_cb, lv.EVENT.PRESSED, None)
532+
self.add_event_cb(self.event_cb, lv.EVENT.LONG_PRESSED, None)
527533
self.add_event_cb(self.event_cb, lv.EVENT.DRAW_PART_BEGIN, None)
528534
self.add_event_cb(self.event_cb, lv.EVENT.VALUE_CHANGED, None)
529535
self.add_event_cb(self.event_cb, lv.EVENT.READY, None)
530536
self.add_event_cb(self.event_cb, lv.EVENT.CANCEL, None)
531537
self.previous_input_len = 0
538+
self.vibrated = False
532539

533540
def update_count_tips(self):
534541
"""Update/show tips only when input length larger than 10"""
@@ -581,7 +588,10 @@ def event_cb(self, event):
581588
):
582589
return
583590
motor.vibrate()
591+
self.vibrated = True
584592
return
593+
elif code == lv.EVENT.LONG_PRESSED:
594+
self.vibrated = False
585595
input_len = len(self.ta.get_text())
586596
self.input_len = input_len
587597
self.ta.clear_flag(lv.obj.FLAG.HIDDEN)
@@ -598,7 +608,7 @@ def event_cb(self, event):
598608
# dsc.rect_dsc.bg_img_src = "A:/res/keyboard-close.png"
599609
elif code == lv.EVENT.VALUE_CHANGED:
600610
utils.lcd_resume()
601-
if isinstance(target, lv.keyboard):
611+
if isinstance(target, lv.keyboard) and not self.vibrated:
602612
btn_id = target.get_selected_btn()
603613
if btn_id == 9:
604614
motor.vibrate()
@@ -751,11 +761,13 @@ def __init__(
751761
# self.input_count_tips.add_flag(lv.obj.FLAG.HIDDEN)
752762

753763
self.add_event_cb(self.event_cb, lv.EVENT.PRESSED, None)
764+
self.add_event_cb(self.event_cb, lv.EVENT.LONG_PRESSED, None)
754765
self.add_event_cb(self.event_cb, lv.EVENT.DRAW_PART_BEGIN, None)
755766
self.add_event_cb(self.event_cb, lv.EVENT.VALUE_CHANGED, None)
756767
self.add_event_cb(self.event_cb, lv.EVENT.READY, None)
757768
self.add_event_cb(self.event_cb, lv.EVENT.CANCEL, None)
758769
self.previous_input_len = 0
770+
self.vibrated = False
759771

760772
# def update_count_tips(self):
761773
# """Update/show tips only when input length larger than 10"""
@@ -821,7 +833,10 @@ def event_cb(self, event):
821833
):
822834
return
823835
motor.vibrate()
836+
self.vibrated = True
824837
return
838+
elif code == lv.EVENT.LONG_PRESSED:
839+
self.vibrated = False
825840
if not self.is_pin and text.startswith("#"):
826841
input_len = len(text) - 1
827842
else:
@@ -850,7 +865,7 @@ def event_cb(self, event):
850865

851866
elif code == lv.EVENT.VALUE_CHANGED:
852867
utils.lcd_resume()
853-
if isinstance(target, lv.keyboard):
868+
if isinstance(target, lv.keyboard) and not self.vibrated:
854869
btn_id = target.get_selected_btn()
855870
if btn_id == 9:
856871
motor.vibrate()
@@ -1133,6 +1148,7 @@ def __init__(self, parent, max_len, min_len=0) -> None:
11331148

11341149
self.update_count_tips()
11351150
self.add_event_cb(self.event_cb, lv.EVENT.PRESSED, None)
1151+
self.add_event_cb(self.event_cb, lv.EVENT.LONG_PRESSED, None)
11361152
self.add_event_cb(self.event_cb, lv.EVENT.DRAW_PART_BEGIN, None)
11371153
self.add_event_cb(self.event_cb, lv.EVENT.VALUE_CHANGED, None)
11381154
self.ta.add_event_cb(self.event_cb, lv.EVENT.FOCUSED, None)
@@ -1167,7 +1183,10 @@ def event_cb(self, event):
11671183
if btn_id == 31 and len(self.ta.get_text()) == 0:
11681184
return
11691185
motor.vibrate()
1186+
self.vibrated = True
11701187
return
1188+
elif code == lv.EVENT.LONG_PRESSED:
1189+
self.vibrated = False
11711190
if code == lv.EVENT.DRAW_PART_BEGIN:
11721191
txt_input = self.ta.get_text()
11731192
dsc = lv.obj_draw_part_dsc_t.__cast__(event.get_param())
@@ -1222,7 +1241,8 @@ def event_cb(self, event):
12221241
self.ta.del_char()
12231242
self.update_count_tips()
12241243
self.update_ok_button_state()
1225-
motor.vibrate()
1244+
if not self.vibrated:
1245+
motor.vibrate()
12261246
return
12271247
elif text == lv.SYMBOL.OK:
12281248
if len(self.ta.get_text()) >= self.min_len:

0 commit comments

Comments
 (0)