24 lines
482 B
Python
Raw Normal View History

2023-08-10 19:36:32 +08:00
from PikaStdDevice import Timer
2023-08-10 21:31:14 +08:00
import time
2023-08-10 19:36:32 +08:00
tim = Timer()
cb_times = 0
def cb_test(signal):
global cb_times
2023-10-26 20:13:10 +08:00
if cb_times > 0:
return
2023-08-10 19:36:32 +08:00
cb_times += 1
print("cb_test: signal = %d, cb_times = %d" % (signal, cb_times))
tim.setCallback(cb_test, Timer.SIGNAL_ANY)
tim.setId(-1) # -1 means soft timer
2023-08-10 21:31:14 +08:00
tim.setPeriod(100) # 100ms
2023-08-10 19:36:32 +08:00
tim.enable()
while True:
2023-10-26 20:13:10 +08:00
time.sleep(1)
print("cb_times = %d" % cb_times)
if cb_times >= 1:
2023-08-10 19:36:32 +08:00
tim.close()
break