diff --git a/klippy/chipmisc.py b/klippy/chipmisc.py index 2bdf3b58..0c41f9d4 100644 --- a/klippy/chipmisc.py +++ b/klippy/chipmisc.py @@ -137,7 +137,7 @@ class pca9685_pwm: self._max_duration = 2. self._oid = None self._invert = pin_params['invert'] - self._shutdown_value = float(self._invert) + self._start_value = self._shutdown_value = float(self._invert) self._last_clock = 0 self._pwm_max = 0. self._cmd_queue = self._mcu.alloc_command_queue() @@ -156,10 +156,12 @@ class pca9685_pwm: if self._invert: value = 1. - value self._static_value = max(0., min(1., value)) - def setup_shutdown_value(self, value): + def setup_start_value(self, start_value, shutdown_value): if self._invert: - value = 1. - value - self._shutdown_value = max(0., min(1., value)) + start_value = 1. - start_value + shutdown_value = 1. - shutdown_value + self._start_value = max(0., min(1., start_value)) + self._shutdown_value = max(0., min(1., shutdown_value)) if self._shutdown_value: self._replicape.note_enable_on_shutdown() def build_config(self): @@ -178,7 +180,7 @@ class pca9685_pwm: "config_pca9685 oid=%d bus=%d addr=%d channel=%d cycle_ticks=%d" " value=%d default_value=%d max_duration=%d" % ( self._oid, self._bus, self._address, self._channel, cycle_ticks, - self._invert * self._pwm_max, + self._start_value * self._pwm_max, self._shutdown_value * self._pwm_max, self._mcu.seconds_to_clock(self._max_duration))) self._set_cmd = self._mcu.lookup_command( @@ -269,7 +271,7 @@ class Replicape: REPLICAPE_SHIFT_REGISTER_BUS, REPLICAPE_SHIFT_REGISTER_DEVICE, "".join(["%02x" % (x,) for x in shift_registers]))) def note_enable_on_shutdown(self): - self.mcu_enable.setup_shutdown_value(1) + self.mcu_enable.setup_start_value(0, 1) def note_enable(self, print_time, channel, is_enable): if is_enable: is_off = not self.enabled_channels diff --git a/klippy/fan.py b/klippy/fan.py index 5401c5ec..5cf05861 100644 --- a/klippy/fan.py +++ b/klippy/fan.py @@ -42,7 +42,7 @@ class PrinterHeaterFan: max_power = self.fan.max_power self.fan_speed = config.getfloat( "fan_speed", max_power, minval=0., maxval=max_power) - self.fan.mcu_fan.setup_shutdown_value(max_power) + self.fan.mcu_fan.setup_start_value(0., max_power) printer.reactor.register_timer(self.callback, printer.reactor.NOW) def callback(self, eventtime): current_temp, target_temp = self.heater.get_temp(eventtime) diff --git a/klippy/mcu.py b/klippy/mcu.py index 64ecb79c..78dfe9e7 100644 --- a/klippy/mcu.py +++ b/klippy/mcu.py @@ -227,9 +227,10 @@ class MCU_digital_out: def __init__(self, mcu, pin_params): self._mcu = mcu self._oid = None - self._static_value = None self._pin = pin_params['pin'] - self._invert = self._shutdown_value = pin_params['invert'] + self._invert = pin_params['invert'] + self._start_value = self._shutdown_value = self._invert + self._static_value = None self._max_duration = 2. self._last_clock = 0 self._cmd_queue = mcu.alloc_command_queue() @@ -240,8 +241,9 @@ class MCU_digital_out: self._max_duration = max_duration def setup_static(self): self._static_value = not self._invert - def setup_shutdown_value(self, value): - self._shutdown_value = (not not value) ^ self._invert + def setup_start_value(self, start_value, shutdown_value): + self._start_value = (not not start_value) ^ self._invert + self._shutdown_value = (not not shutdown_value) ^ self._invert def build_config(self): if self._static_value is not None: self._mcu.add_config_cmd("set_digital_out pin=%s value=%d" % ( @@ -272,10 +274,10 @@ class MCU_pwm: self._cycle_time = 0.100 self._max_duration = 2. self._oid = None - self._static_value = None self._pin = pin_params['pin'] self._invert = pin_params['invert'] - self._shutdown_value = float(self._invert) + self._start_value = self._shutdown_value = float(self._invert) + self._static_value = None self._last_clock = 0 self._pwm_max = 0. self._cmd_queue = mcu.alloc_command_queue() @@ -296,10 +298,12 @@ class MCU_pwm: if self._invert: value = 1. - value self._static_value = max(0., min(1., value)) - def setup_shutdown_value(self, value): + def setup_start_value(self, start_value, shutdown_value): if self._invert: - value = 1. - value - self._shutdown_value = max(0., min(1., value)) + start_value = 1. - start_value + shutdown_value = 1. - shutdown_value + self._start_value = max(0., min(1., start_value)) + self._shutdown_value = max(0., min(1., shutdown_value)) def build_config(self): if self._hard_pwm: self._pwm_max = self._mcu.get_constant_float("PWM_MAX") @@ -314,7 +318,7 @@ class MCU_pwm: "config_pwm_out oid=%d pin=%s cycle_ticks=%d value=%d" " default_value=%d max_duration=%d" % ( self._oid, self._pin, self._cycle_time, - self._invert * self._pwm_max, + self._start_value * self._pwm_max, self._shutdown_value * self._pwm_max, self._mcu.seconds_to_clock(self._max_duration))) self._set_cmd = self._mcu.lookup_command( @@ -328,16 +332,17 @@ class MCU_pwm: self._mcu.add_config_cmd("set_digital_out pin=%s value=%d" % ( self._pin, self._static_value >= 0.5)) return - if self._shutdown_value not in [0., 1.]: + if (self._start_value not in [0., 1.] + or self._shutdown_value not in [0., 1.]): raise pins.error( - "shutdown value must be 0.0 or 1.0 on soft pwm") + "start and shutdown values must be 0.0 or 1.0 on soft pwm") self._oid = self._mcu.create_oid() self._mcu.add_config_cmd( "config_soft_pwm_out oid=%d pin=%s cycle_ticks=%d value=%d" " default_value=%d max_duration=%d" % ( self._oid, self._pin, self._mcu.seconds_to_clock(self._cycle_time), - self._invert, self._shutdown_value >= 0.5, + self._start_value >= 0.5, self._shutdown_value >= 0.5, self._mcu.seconds_to_clock(self._max_duration))) self._set_cmd = self._mcu.lookup_command( "schedule_soft_pwm_out oid=%c clock=%u value=%hu")