From 49425907ad5f25a6d8719ca4c804da25b80ed5b7 Mon Sep 17 00:00:00 2001 From: Carlos Felicio Date: Fri, 10 Oct 2025 16:27:18 -0700 Subject: [PATCH] Fix heartbeat waiting logic in palette2.py In some situations, the existing _wait_for_heartbeat causes a shutdown and the following error when using PALETTE_CONNECT: TypeError: '<' not supported between instances of 'NoneType' and 'float' PALETTE_CONNECT now works (tested with a Palette 2 and a Palette 2 PRO). I'm not quite sure why this happens with one of my printers but not the other one, what I figured out so far is that the serial communication happens almost instantly on printer 1, while printer 2 struggles in the beginning due to a slower motherboard. It should properly allow for a timeout, or fail more gracefully instead of a shutdown. --- klippy/extras/palette2.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/klippy/extras/palette2.py b/klippy/extras/palette2.py index 4fe720808c69..9c4daf6d1b06 100644 --- a/klippy/extras/palette2.py +++ b/klippy/extras/palette2.py @@ -218,18 +218,21 @@ def cmd_OmegaDefault(self, gcmd): if self._check_P2(gcmd): self.write_queue.put(gcmd.get_commandline()) - def _wait_for_heartbeat(self): - startTs = self.reactor.monotonic() - currTs = startTs - while self.heartbeat is None or (self.heartbeat < ( - currTs - SETUP_TIMEOUT) and startTs > ( - currTs - SETUP_TIMEOUT)): - currTs = self.reactor.pause(currTs + 1.) - - if self.heartbeat < (currTs - SETUP_TIMEOUT): +def _wait_for_heartbeat(self): + startTs = self.reactor.monotonic() + currTs = startTs + while True: + currTs = self.reactor.pause(currTs + 1.0) + if ( + self.heartbeat is not None + and self.heartbeat >= (currTs - SETUP_TIMEOUT) + ): + break + if currTs - startTs > SETUP_TIMEOUT: self.signal_disconnect = True raise self.printer.command_error( - "No response from Palette 2") + "No response from Palette 2" + ) cmd_O1_help = ( "Initialize the print, and check connection with the Palette 2")