From 13ee6032ae28a4a8dfc1e194c2b5c73e66674df3 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Wed, 9 Sep 2020 13:16:02 -0400 Subject: [PATCH] mcu: Use schedule_pwm_out instead of set_pwm_out on a restart Some mcu implementations don't like it when the pwm pin is configured twice, so use the normal schedule_pwm_out implementation to update on a restart. Signed-off-by: Kevin O'Connor --- klippy/mcu.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/klippy/mcu.py b/klippy/mcu.py index 2d26743d..869688f9 100644 --- a/klippy/mcu.py +++ b/klippy/mcu.py @@ -213,10 +213,13 @@ class MCU_pwm: self._start_value * self._pwm_max, self._shutdown_value * self._pwm_max, self._mcu.seconds_to_clock(self._max_duration))) - self._mcu.add_config_cmd( - "set_pwm_out pin=%s cycle_ticks=%d value=%d" - % (self._pin, cycle_ticks, self._start_value * self._pwm_max), - on_restart=True) + curtime = self._mcu.get_printer().get_reactor().monotonic() + printtime = self._mcu.estimated_print_time(curtime) + self._last_clock = self._mcu.print_time_to_clock(printtime + 0.100) + svalue = int(self._start_value * self._pwm_max + 0.5) + self._mcu.add_config_cmd("schedule_pwm_out oid=%d clock=%d value=%d" + % (self._oid, self._last_clock, svalue), + on_restart=True) self._set_cmd = self._mcu.lookup_command( "schedule_pwm_out oid=%c clock=%u value=%hu", cq=cmd_queue) return