diff options
author | Kevin O'Connor <kevin@koconnor.net> | 2020-11-13 12:41:31 -0500 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2020-11-13 18:29:41 -0500 |
commit | 90d755dc0a67f1a5e910728b61b31e3b7ae3025b (patch) | |
tree | d3d8f91f1ab1121884ad25e4bf1f2ccca3aff11b | |
parent | afbed5d4c71fbd7465b970169be0b54649f7c20e (diff) | |
download | kutter-90d755dc0a67f1a5e910728b61b31e3b7ae3025b.tar.gz kutter-90d755dc0a67f1a5e910728b61b31e3b7ae3025b.tar.xz kutter-90d755dc0a67f1a5e910728b61b31e3b7ae3025b.zip |
output_pin: Don't flush lookahead queue on a SET_PIN command
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
-rw-r--r-- | klippy/extras/output_pin.py | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/klippy/extras/output_pin.py b/klippy/extras/output_pin.py index 549c788b..f9a886f6 100644 --- a/klippy/extras/output_pin.py +++ b/klippy/extras/output_pin.py @@ -1,6 +1,6 @@ # Code to configure miscellaneous chips # -# Copyright (C) 2017,2018 Kevin O'Connor <kevin@koconnor.net> +# Copyright (C) 2017-2020 Kevin O'Connor <kevin@koconnor.net> # # This file may be distributed under the terms of the GNU GPLv3 license. @@ -21,6 +21,7 @@ class PrinterOutputPin: else: self.mcu_pin = ppins.setup_pin('digital_out', config.get('pin')) self.scale = 1. + self.last_cycle_time = self.default_cycle_time = 0. self.mcu_pin.setup_max_duration(0.) self.last_print_time = 0. static_value = config.getfloat('static_value', None, @@ -42,27 +43,28 @@ class PrinterOutputPin: desc=self.cmd_SET_PIN_help) def get_status(self, eventtime): return {'value': self.last_value} - cmd_SET_PIN_help = "Set the value of an output pin" - def cmd_SET_PIN(self, gcmd): - value = gcmd.get_float('VALUE', minval=0., maxval=self.scale) - value /= self.scale - print_time = self.printer.lookup_object('toolhead').get_last_move_time() + def _set_pin(self, print_time, value, cycle_time): + if value == self.last_value and cycle_time == self.last_cycle_time: + return print_time = max(print_time, self.last_print_time + PIN_MIN_TIME) if self.is_pwm: - cycle_time = gcmd.get_float('CYCLE_TIME', self.default_cycle_time, - above=0.) - if value == self.last_value and cycle_time == self.last_cycle_time: - return self.mcu_pin.set_pwm(print_time, value, cycle_time) - self.last_cycle_time = cycle_time else: - if value == self.last_value: - return - if value not in [0., 1.]: - raise gcmd.error("Invalid pin value") self.mcu_pin.set_digital(print_time, value) self.last_value = value + self.last_cycle_time = cycle_time self.last_print_time = print_time + cmd_SET_PIN_help = "Set the value of an output pin" + def cmd_SET_PIN(self, gcmd): + value = gcmd.get_float('VALUE', minval=0., maxval=self.scale) + value /= self.scale + cycle_time = gcmd.get_float('CYCLE_TIME', self.default_cycle_time, + above=0.) + if not self.is_pwm and value not in [0., 1.]: + raise gcmd.error("Invalid pin value") + toolhead = self.printer.lookup_object('toolhead') + toolhead.register_lookahead_callback( + lambda print_time: self._set_pin(print_time, value, cycle_time)) def load_config_prefix(config): return PrinterOutputPin(config) |