42 lines
1.1 KiB
Python
42 lines
1.1 KiB
Python
from . import CustomInstruction
|
|
|
|
class TimerCustomInstruction(CustomInstruction):
|
|
"""
|
|
Timer custom instruction
|
|
"""
|
|
@property
|
|
def timer_name(self):
|
|
return self.get_arg(0)
|
|
|
|
|
|
class TimerStart(TimerCustomInstruction):
|
|
"""
|
|
TimerStart() starts a given timer
|
|
"""
|
|
def run(self, update_program_counter=True):
|
|
self._vmstate.timers_manager.start_timer(self.timer_name)
|
|
super().run(update_program_counter)
|
|
|
|
|
|
class TimerStop(TimerCustomInstruction):
|
|
"""
|
|
TimerStop() stops a given timer
|
|
"""
|
|
def run(self, update_program_counter=True):
|
|
self._vmstate.timers_manager.stop_timer(self.timer_name)
|
|
super().run(update_program_counter)
|
|
|
|
|
|
class TimerSetPeriod(TimerCustomInstruction):
|
|
"""
|
|
TimerSetPeriod() stops a given timer
|
|
"""
|
|
def __init__(self, call_operation):
|
|
super().__init__(call_operation)
|
|
self.period = float(self.get_arg(1))
|
|
|
|
def run(self, update_program_counter=True):
|
|
period = float(self.get_arg(1))
|
|
self._vmstate.timers_manager.set_timer_period(self.timer_name, self.period)
|
|
super().run(update_program_counter)
|