Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
firmware
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
François Revol
firmware
Commits
7be1aded
Commit
7be1aded
authored
4 years ago
by
Pixtxa
Browse files
Options
Downloads
Patches
Plain Diff
retrigger buttons when long pressed
parent
2022ebc4
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
pycardium/modules/py/simple_menu.py
+27
-16
27 additions, 16 deletions
pycardium/modules/py/simple_menu.py
with
27 additions
and
16 deletions
pycardium/modules/py/simple_menu.py
+
27
−
16
View file @
7be1aded
...
...
@@ -8,8 +8,7 @@ import config
TIMEOUT
=
0x100
"""
:py:func:`~simple_menu.button_events` timeout marker.
"""
def
button_events
(
timeout
=
None
):
def
button_events
(
timeout
=
None
,
long_press_ms
=
1000
,
retrigger_ms
=
250
):
"""
Iterate over button presses (event-loop).
...
...
@@ -44,6 +43,8 @@ def button_events(timeout=None):
v
=
buttons
.
read
(
buttons
.
BOTTOM_LEFT
|
buttons
.
BOTTOM_RIGHT
|
buttons
.
TOP_RIGHT
)
button_pressed
=
True
if
v
!=
0
else
False
t0
=
time
.
time_ms
()
still_pressed
=
False
if
timeout
is
not
None
:
timeout
=
int
(
timeout
*
1000
)
...
...
@@ -60,18 +61,28 @@ def button_events(timeout=None):
if
v
==
0
:
button_pressed
=
False
if
not
button_pressed
and
v
&
buttons
.
BOTTOM_LEFT
!=
0
:
button_pressed
=
True
yield
buttons
.
BOTTOM_LEFT
if
not
button_pressed
and
v
&
buttons
.
BOTTOM_RIGHT
!=
0
:
button_pressed
=
True
yield
buttons
.
BOTTOM_RIGHT
if
not
button_pressed
and
v
&
buttons
.
TOP_RIGHT
!=
0
:
button_pressed
=
True
yield
buttons
.
TOP_RIGHT
still_pressed
=
False
else
:
if
not
button_pressed
:
button_pressed
=
True
t0
=
time
.
time_ms
()
if
v
&
buttons
.
BOTTOM_LEFT
:
yield
buttons
.
BOTTOM_LEFT
if
v
&
buttons
.
BOTTOM_RIGHT
:
yield
buttons
.
BOTTOM_RIGHT
if
v
&
buttons
.
TOP_RIGHT
:
yield
buttons
.
TOP_RIGHT
if
not
still_pressed
and
long_press_ms
and
time
.
time_ms
()
-
t0
<=
long_press_ms
:
pass
else
:
if
retrigger_ms
and
time
.
time_ms
()
-
t0
>
retrigger_ms
:
button_pressed
=
False
still_pressed
=
True
class
_ExitMenuException
(
Exception
):
...
...
@@ -305,14 +316,14 @@ class Menu:
self
.
disp
.
update
()
def
run
(
self
,
long_press_ms
=
1000
):
def
run
(
self
,
long_press_ms
=
1000
,
retrigger_ms
=
250
):
"""
Start the event-loop.
"""
try
:
timeout
=
self
.
scroll_speed
if
self
.
timeout
is
not
None
and
self
.
timeout
<
self
.
scroll_speed
:
timeout
=
self
.
timeout
for
ev
in
button_events
(
timeout
):
for
ev
in
button_events
(
timeout
,
long_press_ms
,
retrigger_ms
):
if
ev
==
buttons
.
BOTTOM_RIGHT
:
self
.
select_time
=
time
.
time_ms
()
self
.
draw_menu
(
-
8
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment