Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Stefan Haun
firmware
Commits
08c02c48
Verified
Commit
08c02c48
authored
Aug 27, 2019
by
Rahix
Browse files
feat(simple_menu): Add timeout to button_events()
Signed-off-by:
Rahix
<
rahix@rahix.de
>
parent
3226a8d2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Documentation/pycardium/simple_menu.rst
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
pycardium/modules/py/simple_menu.py
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
:
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment