From 7a44726492fd7ec8eb7a7a74ff4c2adc1129a7c2 Mon Sep 17 00:00:00 2001 From: Timofey Titovets Date: Sun, 1 Mar 2026 16:23:55 +0100 Subject: [PATCH] pwm_tool: fix missing updates Generate intermediate updates if a set_pwm() call schedules an update far in the future. Signed-off-by: Timofey Titovets Signed-off-by: Kevin O'Connor --- klippy/extras/pwm_tool.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/klippy/extras/pwm_tool.py b/klippy/extras/pwm_tool.py index a069dd2d8..954bd2093 100644 --- a/klippy/extras/pwm_tool.py +++ b/klippy/extras/pwm_tool.py @@ -117,18 +117,23 @@ class MCU_queued_pwm: wake_print_time = self._mcu.clock_to_print_time(wakeclock) self._motion_queuing.note_mcu_movequeue_activity(wake_print_time, is_step_gen=False) + def _gen_intermediate_updates(self, clock): + if self._last_value == self._default_value: + return + while clock >= self._last_clock + self._duration_ticks: + self._send_update(self._last_clock + self._duration_ticks, + self._last_value) def set_pwm(self, print_time, value): clock = self._mcu.print_time_to_clock(print_time) if self._invert: value = 1. - value v = int(max(0., min(1., value)) * self._pwm_max + 0.5) + if self._duration_ticks: + self._gen_intermediate_updates(clock - 1) self._send_update(clock, v) def _flush_notification(self, must_flush_time, max_step_gen_time): clock = self._mcu.print_time_to_clock(must_flush_time) - if self._last_value != self._default_value: - while clock >= self._last_clock + self._duration_ticks: - self._send_update(self._last_clock + self._duration_ticks, - self._last_value) + self._gen_intermediate_updates(clock) class PrinterOutputPin: def __init__(self, config):