mirror of https://github.com/Desuuuu/klipper.git
output_pin: Don't flush lookahead queue on a SET_PIN command
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
afbed5d4c7
commit
90d755dc0a
|
@ -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}
|
||||
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:
|
||||
self.mcu_pin.set_pwm(print_time, value, cycle_time)
|
||||
else:
|
||||
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
|
||||
print_time = self.printer.lookup_object('toolhead').get_last_move_time()
|
||||
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.]:
|
||||
if not self.is_pwm and 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_print_time = print_time
|
||||
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)
|
||||
|
|
Loading…
Reference in New Issue