📄 periodic.py
字号:
# This script is in the public domain and has no copyright## Periodic is a utility class to implement a repeated call to a # given callback function at a specified interval.#import simcoreimport net.tinyos.sim.eventclass Periodic: def __init__(self, interval, callback, args = None, call_immediate = 1): self.callback = callback; self.interval = int(interval) self.interruptID = simcore.interp.getInterruptID(); self.stopped = 0; def mycallback(interruptEvent): if (interruptEvent.get_id() != self.interruptID): return self.callback(interruptEvent); if (self.stopped == 0): nextInterrupt = interruptEvent.getTime() + self.interval simcore.interp.interruptInFuture(nextInterrupt, self.interruptID) evclass = net.tinyos.sim.event.InterruptEvent; self.eventID = simcore.interp.addEventHandler(mycallback, evclass); if call_immediate: simcore.interp.interruptInFuture(0, self.interruptID); else: simcore.interp.interruptInFuture(simcore.sim.getTossimTime()+ self.interval, self.interruptID) def is_stopped(self): return self.stopped; def stop(self): self.stopped = 1; simcore.interp.removeEventHandler(self.eventID);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -