Skip to content

Commit 579111c

Browse files
dwalton76ddemidov
authored andcommitted
Added Motor.wait_until_not_moving() (#327)
1 parent 05c89fc commit 579111c

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

ev3dev/core.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -909,6 +909,21 @@ def wait(self, cond, timeout=None):
909909
if cond(self.state):
910910
return True
911911

912+
def wait_until_not_moving(self, timeout=None):
913+
"""
914+
Blocks until ``running`` is not in ``self.state`` or ``stalled`` is in
915+
``self.state``. The condition is checked when there is an I/O event
916+
related to the ``state`` attribute. Exits early when ``timeout``
917+
(in milliseconds) is reached.
918+
919+
Returns ``True`` if the condition is met, and ``False`` if the timeout
920+
is reached.
921+
922+
Example::
923+
924+
m.wait_until_not_moving()
925+
"""
926+
return self.wait(lambda state: self.STATE_RUNNING not in state or self.STATE_STALLED in state, timeout)
912927

913928
def wait_until(self, s, timeout=None):
914929
"""

0 commit comments

Comments
 (0)