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
External 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
fleur
firmware
Commits
08c02c48
Verified
Commit
08c02c48
authored
5 years ago
by
rahix
Browse files
Options
Downloads
Patches
Plain Diff
feat(simple_menu): Add timeout to button_events()
Signed-off-by:
Rahix
<
rahix@rahix.de
>
parent
3226a8d2
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Documentation/pycardium/simple_menu.rst
+2
-0
2 additions, 0 deletions
Documentation/pycardium/simple_menu.rst
pycardium/modules/py/simple_menu.py
+23
-1
23 additions, 1 deletion
pycardium/modules/py/simple_menu.py
with
25 additions
and
1 deletion
Documentation/pycardium/simple_menu.rst
+
2
−
0
View file @
08c02c48
...
...
@@ -25,4 +25,6 @@ displaying menus. You can use it like this:
.. autoclass:: simple_menu.Menu
:members:
.. autodata:: simple_menu.TIMEOUT
.. autofunction:: simple_menu.button_events
This diff is collapsed.
Click to expand it.
pycardium/modules/py/simple_menu.py
+
23
−
1
View file @
08c02c48
...
...
@@ -4,8 +4,11 @@ import display
import
sys
import
utime
TIMEOUT
=
0x100
"""
:py:func:`~simple_menu.button_events` timeout marker.
"""
def
button_events
():
def
button_events
(
timeout
=
None
):
"""
Iterate over button presses (event-loop).
...
...
@@ -28,11 +31,30 @@ def button_events():
pass
.. versionadded:: 1.4
:param float,optional timeout:
Timeout after which the generator should yield in any case. If a
timeout is defined, the generator will periodically yield
:py:data:`simple_menu.TIMEOUT`.
.. versionadded:: 1.9
"""
yield
0
v
=
buttons
.
read
(
buttons
.
BOTTOM_LEFT
|
buttons
.
BOTTOM_RIGHT
|
buttons
.
TOP_RIGHT
)
button_pressed
=
True
if
v
!=
0
else
False
if
timeout
is
not
None
:
timeout
=
int
(
timeout
*
1000
)
next_tick
=
utime
.
time_ms
()
+
timeout
while
True
:
if
timeout
is
not
None
:
current_time
=
utime
.
time_ms
()
if
current_time
>=
next_tick
:
next_tick
+=
timeout
yield
TIMEOUT
v
=
buttons
.
read
(
buttons
.
BOTTOM_LEFT
|
buttons
.
BOTTOM_RIGHT
|
buttons
.
TOP_RIGHT
)
if
v
==
0
:
...
...
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