-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathtimer_simpletest.py
34 lines (24 loc) · 979 Bytes
/
timer_simpletest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
"""
This is a simple test script that tests the basic functionality of the timer class.
It creates a periodic timer in a class instance and a one-shot timer that stops the periodic timer.
"""
from multimer import Timer
from sys import platform
class TimerTest:
def __init__(self):
self._tim = Timer(-1 if platform == "rp2" else 1)
def start(self, period):
self._counter = 0
self._tim.init(mode=Timer.PERIODIC, period=period, callback=self.do_something)
print("TimerTest: timer started...")
def do_something(self, t):
self._counter += 1
def stop(self, t=None):
self._tim.deinit()
print(f"TimerTest: timer stopped after {self._counter:,} calls.")
# Create a timer that calls tt.do_something every 1ms
tt = TimerTest()
tt.start(1)
# Create a timer that stops the first timer after 5 seconds
tim2 = Timer(-1 if platform == "rp2" else 2)
tim2.init(mode=Timer.ONE_SHOT, period=5000, callback=tt.stop)