mirror of
https://github.com/Klipper3d/klipper.git
synced 2025-07-16 11:17:52 -06:00
mcu: Add support for changing cycle_time in set_pwm()
Signed-off-by: Guy Shapira <gayuha@gmail.com> Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
27cefb2b38
commit
55e20f2c19
6 changed files with 26 additions and 15 deletions
|
@ -17,11 +17,12 @@ class PrinterOutputPin:
|
|||
hardware_pwm = config.getboolean('hardware_pwm', False)
|
||||
self.mcu_pin.setup_cycle_time(cycle_time, hardware_pwm)
|
||||
self.scale = config.getfloat('scale', 1., above=0.)
|
||||
self.last_cycle_time = self.default_cycle_time = cycle_time
|
||||
else:
|
||||
self.mcu_pin = ppins.setup_pin('digital_out', config.get('pin'))
|
||||
self.scale = 1.
|
||||
self.mcu_pin.setup_max_duration(0.)
|
||||
self.last_value_time = 0.
|
||||
self.last_print_time = 0.
|
||||
static_value = config.getfloat('static_value', None,
|
||||
minval=0., maxval=self.scale)
|
||||
if static_value is not None:
|
||||
|
@ -45,18 +46,23 @@ class PrinterOutputPin:
|
|||
def cmd_SET_PIN(self, gcmd):
|
||||
value = gcmd.get_float('VALUE', minval=0., maxval=self.scale)
|
||||
value /= self.scale
|
||||
if value == self.last_value:
|
||||
return
|
||||
print_time = self.printer.lookup_object('toolhead').get_last_move_time()
|
||||
print_time = max(print_time, self.last_value_time + PIN_MIN_TIME)
|
||||
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 = 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_value_time = print_time
|
||||
self.last_print_time = print_time
|
||||
|
||||
def load_config_prefix(config):
|
||||
return PrinterOutputPin(config)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue