spikedev.stopwatch

Example

from spikedev.button import ButtonCenter
from spikedev.stopwatch import StopWatch

button = ButtonCenter()

sw = StopWatch()
print("Press the center as soon as possible)
sw.start()
button.wait_for_bump()
sw.stop()
print("center button pressed in {} ms".format(sw.value_ms))

Classes

A StopWatch class for tracking the amount of time between events

class spikedev.stopwatch.StopWatch(desc=None)

Bases: object

A timer class which lets you start a virtual stopwatch and later check the amount of time elapsed

start()

Start the timer. If the timer is already running, raise StopWatchAlreadyStartedException

stop()

Stop the timer. The time value of this Stopwatch is paused and will not continue increasing.

reset()

Reset the timer and leave it stopped

restart()

Reset and start the timer

property is_started

Return True if the StopWatch has been started but not stopped (i.e., it’s currently running), else return False

property value_ms

Return the value of the StopWatch in milliseconds

property value_secs

Return the value of the StopWatch in seconds

property value_hms

Return the StopWatch elapsed time as a tuple (hours, minutes, seconds, milliseconds).

property hms_str

Return the stringified value of the StopWatch in HH-MM-SS.msec format

is_elapsed_ms(duration_ms)

Return True if this timer has measured at least duration_ms milliseconds, else returns False. If duration_ms is None, return False.

is_elapsed_secs(duration_secs)

Return True if this timer has measured at least duration_secs seconds, else returns False. If duration_secs is None, returns False.

exception spikedev.stopwatch.StopWatchAlreadyStartedException

Bases: Exception

Exception raised when start() is called on a StopWatch which was already start()ed and not yet stopped.