Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/Klipper3d/klipper.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClifford Roche <clifford.roche@gmail.com>2022-08-06 20:40:41 +0300
committerKevinOConnor <kevin@koconnor.net>2022-08-19 21:12:51 +0300
commitce27d359249e75fd546eaad2a393f55486a2fb59 (patch)
tree32253c5351649988a35f7ce20f077ad02530f842
parentb1dcd35b7a8919d99db5dc72fc0cf0fba4140352 (diff)
palette2: Fix UART encoding
Raised from issue #5645, UTF-8 encoded symbols or other unexpected symbols on the UART raise an exception which causes klipper to stop. This change support UTF-8 encoded characters (from file names) as well as ignoring unexpected bytes. Signed-off-by: Clifford Roche <clifford.roche@gmail.com>
-rw-r--r--klippy/extras/palette2.py13
1 files changed, 8 insertions, 5 deletions
diff --git a/klippy/extras/palette2.py b/klippy/extras/palette2.py
index c0289399d..c3c43ea69 100644
--- a/klippy/extras/palette2.py
+++ b/klippy/extras/palette2.py
@@ -544,13 +544,15 @@ class Palette2:
self.cmd_Disconnect()
return self.reactor.NEVER
if len(raw_bytes):
- text_buffer = self.read_buffer + str(raw_bytes.decode())
+ new_buffer = str(raw_bytes.decode(encoding='UTF-8',
+ errors='ignore'))
+ text_buffer = self.read_buffer + new_buffer
while True:
i = text_buffer.find("\n")
if i >= 0:
- line = text_buffer[0:i+1]
+ line = text_buffer[0:i + 1]
self.read_queue.put(line.strip())
- text_buffer = text_buffer[i+1:]
+ text_buffer = text_buffer[i + 1:]
else:
break
self.read_buffer = text_buffer
@@ -566,7 +568,7 @@ class Palette2:
heartbeat_strings = [COMMAND_HEARTBEAT, "Connection Okay"]
if not any(x in text_line for x in heartbeat_strings):
- logging.debug("%0.3f P2 -> : %s" %(eventtime, text_line))
+ logging.debug("%0.3f P2 -> : %s" % (eventtime, text_line))
# Received a heartbeat from the device
if text_line == COMMAND_HEARTBEAT:
@@ -621,7 +623,7 @@ class Palette2:
idle_time = est_print_time - print_time
if not lookahead_empty or idle_time < 0.5:
return eventtime + \
- max(0., min(1., print_time - est_print_time))
+ max(0., min(1., print_time - est_print_time))
extrude = abs(self.remaining_load_length)
extrude = min(50, extrude / 2)
@@ -646,5 +648,6 @@ class Palette2:
status["ping"] = self.omega_pings[-1]
return status
+
def load_config(config):
return Palette2(config)