diff options
Diffstat (limited to 'klippy/extras/delayed_gcode.py')
-rw-r--r-- | klippy/extras/delayed_gcode.py | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/klippy/extras/delayed_gcode.py b/klippy/extras/delayed_gcode.py index c15f231e..ddc8f697 100644 --- a/klippy/extras/delayed_gcode.py +++ b/klippy/extras/delayed_gcode.py @@ -6,28 +6,35 @@ import logging + class DelayedGcode: def __init__(self, config): self.printer = config.get_printer() self.reactor = self.printer.get_reactor() self.name = config.get_name().split()[1] - self.gcode = self.printer.lookup_object('gcode') - gcode_macro = self.printer.load_object(config, 'gcode_macro') - self.timer_gcode = gcode_macro.load_template(config, 'gcode') - self.duration = config.getfloat('initial_duration', 0., minval=0.) + self.gcode = self.printer.lookup_object("gcode") + gcode_macro = self.printer.load_object(config, "gcode_macro") + self.timer_gcode = gcode_macro.load_template(config, "gcode") + self.duration = config.getfloat("initial_duration", 0.0, minval=0.0) self.timer_handler = None self.inside_timer = self.repeat = False self.printer.register_event_handler("klippy:ready", self._handle_ready) self.gcode.register_mux_command( - "UPDATE_DELAYED_GCODE", "ID", self.name, + "UPDATE_DELAYED_GCODE", + "ID", + self.name, self.cmd_UPDATE_DELAYED_GCODE, - desc=self.cmd_UPDATE_DELAYED_GCODE_help) + desc=self.cmd_UPDATE_DELAYED_GCODE_help, + ) + def _handle_ready(self): waketime = self.reactor.NEVER if self.duration: waketime = self.reactor.monotonic() + self.duration self.timer_handler = self.reactor.register_timer( - self._gcode_timer_event, waketime) + self._gcode_timer_event, waketime + ) + def _gcode_timer_event(self, eventtime): self.inside_timer = True try: @@ -39,16 +46,19 @@ class DelayedGcode: nextwake = eventtime + self.duration self.inside_timer = self.repeat = False return nextwake + cmd_UPDATE_DELAYED_GCODE_help = "Update the duration of a delayed_gcode" + def cmd_UPDATE_DELAYED_GCODE(self, gcmd): - self.duration = gcmd.get_float('DURATION', minval=0.) + self.duration = gcmd.get_float("DURATION", minval=0.0) if self.inside_timer: - self.repeat = (self.duration != 0.) + self.repeat = self.duration != 0.0 else: waketime = self.reactor.NEVER if self.duration: waketime = self.reactor.monotonic() + self.duration self.reactor.update_timer(self.timer_handler, waketime) + def load_config_prefix(config): return DelayedGcode(config) |