From 2cbb8959780f545a0dc410ae91c49452abd0d5e5 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Fri, 1 Aug 2025 12:33:50 -0400 Subject: [PATCH 1/9] tmc2240: Add OTW_OV_VTH to list of ReadRegisters Reported by @poernahi. Signed-off-by: Kevin O'Connor --- klippy/extras/tmc2240.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/klippy/extras/tmc2240.py b/klippy/extras/tmc2240.py index 214896e7..35d2ce83 100644 --- a/klippy/extras/tmc2240.py +++ b/klippy/extras/tmc2240.py @@ -58,8 +58,9 @@ Registers = { ReadRegisters = [ "GCONF", "GSTAT", "IOIN", "DRV_CONF", "GLOBALSCALER", "IHOLD_IRUN", "TPOWERDOWN", "TSTEP", "TPWMTHRS", "TCOOLTHRS", "THIGH", "ADC_VSUPPLY_AIN", - "ADC_TEMP", "MSCNT", "MSCURACT", "CHOPCONF", "COOLCONF", "DRV_STATUS", - "PWMCONF", "PWM_SCALE", "PWM_AUTO", "SG4_THRS", "SG4_RESULT", "SG4_IND" + "ADC_TEMP", "OTW_OV_VTH", "MSCNT", "MSCURACT", "CHOPCONF", "COOLCONF", + "DRV_STATUS", "PWMCONF", "PWM_SCALE", "PWM_AUTO", "SG4_THRS", "SG4_RESULT", + "SG4_IND" ] Fields = {} From d5c031bc1326f38f7528ac83a6ed046b6d48bca5 Mon Sep 17 00:00:00 2001 From: Contomo <139701597+Contomo@users.noreply.github.com> Date: Fri, 1 Aug 2025 18:37:47 +0200 Subject: [PATCH 2/9] idle_timeout: Add status field for current idle timeout (#6982) Signed-off-by: Eric Billmeyer --- docs/Status_Reference.md | 3 +++ klippy/extras/idle_timeout.py | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/docs/Status_Reference.md b/docs/Status_Reference.md index f6f649b0..77313682 100644 --- a/docs/Status_Reference.md +++ b/docs/Status_Reference.md @@ -291,6 +291,9 @@ is always available): - `printing_time`: The amount of time (in seconds) the printer has been in the "Printing" state (as tracked by the idle_timeout module). +- `idle_timeout`: The current 'timeout' (in seconds) + to wait for the gcode to be triggered. + (as set by [SET_IDLE_TIMEOUT](G-Codes.md#set_idle_timeout)) ## led diff --git a/klippy/extras/idle_timeout.py b/klippy/extras/idle_timeout.py index 6ab2a34a..cc31a97c 100644 --- a/klippy/extras/idle_timeout.py +++ b/klippy/extras/idle_timeout.py @@ -35,7 +35,9 @@ class IdleTimeout: printing_time = 0. if self.state == "Printing": printing_time = eventtime - self.last_print_start_systime - return { "state": self.state, "printing_time": printing_time } + return {"state": self.state, + "printing_time": printing_time, + "idle_timeout": self.idle_timeout} def handle_ready(self): self.toolhead = self.printer.lookup_object('toolhead') self.timeout_timer = self.reactor.register_timer(self.timeout_handler) From c78dd6a00a7434e0a235d4b722f4cac3b41884da Mon Sep 17 00:00:00 2001 From: Timofey Titovets Date: Mon, 28 Jul 2025 01:12:19 +0200 Subject: [PATCH 3/9] pyhelper: define set_thread_name() helper Signed-off-by: Timofey Titovets --- klippy/chelper/__init__.py | 1 + klippy/chelper/pyhelper.c | 9 +++++++++ klippy/chelper/pyhelper.h | 1 + 3 files changed, 11 insertions(+) diff --git a/klippy/chelper/__init__.py b/klippy/chelper/__init__.py index 2aed107a..de8a496a 100644 --- a/klippy/chelper/__init__.py +++ b/klippy/chelper/__init__.py @@ -219,6 +219,7 @@ defs_trdispatch = """ defs_pyhelper = """ void set_python_logging_callback(void (*func)(const char *)); double get_monotonic(void); + int set_thread_name(char name[16]); """ defs_std = """ diff --git a/klippy/chelper/pyhelper.c b/klippy/chelper/pyhelper.c index a0a42923..60c6de9b 100644 --- a/klippy/chelper/pyhelper.c +++ b/klippy/chelper/pyhelper.c @@ -10,6 +10,8 @@ #include // fprintf #include // strerror #include // struct timespec +#include // PR_SET_NAME +#include // prctl #include "compiler.h" // __visible #include "pyhelper.h" // get_monotonic @@ -92,3 +94,10 @@ dump_string(char *outbuf, int outbuf_size, char *inbuf, int inbuf_size) *o = '\0'; return outbuf; } + +// Set custom thread names +int __visible +set_thread_name(char name[16]) +{ + return prctl(PR_SET_NAME, name); +} diff --git a/klippy/chelper/pyhelper.h b/klippy/chelper/pyhelper.h index 1042214b..a29992a2 100644 --- a/klippy/chelper/pyhelper.h +++ b/klippy/chelper/pyhelper.h @@ -7,5 +7,6 @@ void set_python_logging_callback(void (*func)(const char *)); void errorf(const char *fmt, ...) __attribute__ ((format (printf, 1, 2))); void report_errno(char *where, int rc); char *dump_string(char *outbuf, int outbuf_size, char *inbuf, int inbuf_size); +int set_thread_name(char name[16]); #endif // pyhelper.h From 73c6674306599000281064b599545aaaa24a5448 Mon Sep 17 00:00:00 2001 From: Timofey Titovets Date: Fri, 25 Jul 2025 19:13:20 +0200 Subject: [PATCH 4/9] queuelogger: set thread name Python 2.7 does not allow loading the cffi lib inside the thread, but function calls are allowed Signed-off-by: Timofey Titovets --- klippy/queuelogger.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/klippy/queuelogger.py b/klippy/queuelogger.py index c6447f8e..7fa93ace 100644 --- a/klippy/queuelogger.py +++ b/klippy/queuelogger.py @@ -4,6 +4,7 @@ # # This file may be distributed under the terms of the GNU GPLv3 license. import logging, logging.handlers, threading, queue, time +import chelper # Class to forward all messages through a queue to a background thread class QueueHandler(logging.Handler): @@ -25,11 +26,15 @@ class QueueListener(logging.handlers.TimedRotatingFileHandler): def __init__(self, filename): logging.handlers.TimedRotatingFileHandler.__init__( self, filename, when='midnight', backupCount=5) + _, ffi_lib = chelper.get_ffi() + self._set_thread_name = ffi_lib.set_thread_name self.bg_queue = queue.Queue() self.bg_thread = threading.Thread(target=self._bg_thread) self.bg_thread.start() self.rollover_info = {} def _bg_thread(self): + name_short = "queuelogger"[:15] + self._set_thread_name(name_short.encode('utf-8')) while 1: record = self.bg_queue.get(True) if record is None: From 39d01158ba41137f46b80eb9018561d834a2e860 Mon Sep 17 00:00:00 2001 From: Timofey Titovets Date: Fri, 25 Jul 2025 19:11:50 +0200 Subject: [PATCH 5/9] serialhdl: name the threads per mcu Signed-off-by: Timofey Titovets --- klippy/mcu.py | 4 ++-- klippy/serialhdl.py | 11 ++++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/klippy/mcu.py b/klippy/mcu.py index 8b41e4e0..d3b8ffd7 100644 --- a/klippy/mcu.py +++ b/klippy/mcu.py @@ -564,8 +564,8 @@ class MCU: if self._name.startswith('mcu '): self._name = self._name[4:] # Serial port - wp = "mcu '%s': " % (self._name) - self._serial = serialhdl.SerialReader(self._reactor, warn_prefix=wp) + name = self._name + self._serial = serialhdl.SerialReader(self._reactor, mcu_name = name) self._baud = 0 self._canbus_iface = None canbus_uuid = config.get('canbus_uuid', None) diff --git a/klippy/serialhdl.py b/klippy/serialhdl.py index fc884638..ab26514c 100644 --- a/klippy/serialhdl.py +++ b/klippy/serialhdl.py @@ -12,12 +12,15 @@ class error(Exception): pass class SerialReader: - def __init__(self, reactor, warn_prefix=""): + def __init__(self, reactor, mcu_name=""): self.reactor = reactor - self.warn_prefix = warn_prefix + self.warn_prefix = "" + self.mcu_name = mcu_name + if self.mcu_name: + self.warn_prefix = "mcu '%s': " % (self.mcu_name) # Serial port self.serial_dev = None - self.msgparser = msgproto.MessageParser(warn_prefix=warn_prefix) + self.msgparser = msgproto.MessageParser(warn_prefix=self.warn_prefix) # C interface self.ffi_main, self.ffi_lib = chelper.get_ffi() self.serialqueue = None @@ -34,6 +37,8 @@ class SerialReader: self.last_notify_id = 0 self.pending_notifications = {} def _bg_thread(self): + name_short = ("serialhdl %s" % (self.mcu_name))[:15] + self.ffi_lib.set_thread_name(name_short.encode('utf-8')) response = self.ffi_main.new('struct pull_queue_message *') while 1: self.ffi_lib.serialqueue_pull(self.serialqueue, response) From 17ce45d212821efed96a24801b10b157bde6ad35 Mon Sep 17 00:00:00 2001 From: Timofey Titovets Date: Fri, 25 Jul 2025 20:14:18 +0200 Subject: [PATCH 6/9] serialqueue: name the threads per mcu Signed-off-by: Timofey Titovets --- klippy/chelper/__init__.py | 2 +- klippy/chelper/serialqueue.c | 6 +++++- klippy/chelper/serialqueue.h | 2 +- klippy/serialhdl.py | 8 ++++++-- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/klippy/chelper/__init__.py b/klippy/chelper/__init__.py index de8a496a..622cc9a7 100644 --- a/klippy/chelper/__init__.py +++ b/klippy/chelper/__init__.py @@ -182,7 +182,7 @@ defs_serialqueue = """ }; struct serialqueue *serialqueue_alloc(int serial_fd, char serial_fd_type - , int client_id); + , int client_id, char name[16]); void serialqueue_exit(struct serialqueue *sq); void serialqueue_free(struct serialqueue *sq); struct command_queue *serialqueue_alloc_commandqueue(void); diff --git a/klippy/chelper/serialqueue.c b/klippy/chelper/serialqueue.c index c207495c..1af00b06 100644 --- a/klippy/chelper/serialqueue.c +++ b/klippy/chelper/serialqueue.c @@ -47,6 +47,7 @@ struct serialqueue { pthread_mutex_t lock; // protects variables below pthread_cond_t cond; int receive_waiting; + char name[16]; // Baud / clock tracking int receive_window; double bittime_adjust, idle_time; @@ -612,6 +613,7 @@ static void * background_thread(void *data) { struct serialqueue *sq = data; + set_thread_name(sq->name); pollreactor_run(sq->pr); pthread_mutex_lock(&sq->lock); @@ -623,13 +625,15 @@ background_thread(void *data) // Create a new 'struct serialqueue' object struct serialqueue * __visible -serialqueue_alloc(int serial_fd, char serial_fd_type, int client_id) +serialqueue_alloc(int serial_fd, char serial_fd_type, int client_id + , char name[16]) { struct serialqueue *sq = malloc(sizeof(*sq)); memset(sq, 0, sizeof(*sq)); sq->serial_fd = serial_fd; sq->serial_fd_type = serial_fd_type; sq->client_id = client_id; + strncpy(sq->name, name, sizeof(sq->name)); int ret = pipe(sq->pipe_fds); if (ret) diff --git a/klippy/chelper/serialqueue.h b/klippy/chelper/serialqueue.h index 4d447f2f..9da0ad08 100644 --- a/klippy/chelper/serialqueue.h +++ b/klippy/chelper/serialqueue.h @@ -27,7 +27,7 @@ struct pull_queue_message { struct serialqueue; struct serialqueue *serialqueue_alloc(int serial_fd, char serial_fd_type - , int client_id); + , int client_id, char name[16]); void serialqueue_exit(struct serialqueue *sq); void serialqueue_free(struct serialqueue *sq); struct command_queue *serialqueue_alloc_commandqueue(void); diff --git a/klippy/serialhdl.py b/klippy/serialhdl.py index ab26514c..2a401f89 100644 --- a/klippy/serialhdl.py +++ b/klippy/serialhdl.py @@ -18,6 +18,8 @@ class SerialReader: self.mcu_name = mcu_name if self.mcu_name: self.warn_prefix = "mcu '%s': " % (self.mcu_name) + sq_name = ("serialq %s" % (self.mcu_name))[:15] + self.sq_name = sq_name.encode("utf-8") # Serial port self.serial_dev = None self.msgparser = msgproto.MessageParser(warn_prefix=self.warn_prefix) @@ -85,7 +87,8 @@ class SerialReader: self.serial_dev = serial_dev self.serialqueue = self.ffi_main.gc( self.ffi_lib.serialqueue_alloc(serial_dev.fileno(), - serial_fd_type, client_id), + serial_fd_type, client_id, + self.sq_name), self.ffi_lib.serialqueue_free) self.background_thread = threading.Thread(target=self._bg_thread) self.background_thread.start() @@ -205,7 +208,8 @@ class SerialReader: self.serial_dev = debugoutput self.msgparser.process_identify(dictionary, decompress=False) self.serialqueue = self.ffi_main.gc( - self.ffi_lib.serialqueue_alloc(self.serial_dev.fileno(), b'f', 0), + self.ffi_lib.serialqueue_alloc(self.serial_dev.fileno(), b'f', 0, + self.sq_name), self.ffi_lib.serialqueue_free) def set_clock_est(self, freq, conv_time, conv_clock, last_clock): self.ffi_lib.serialqueue_set_clock_est( From 0df40b43e8c3b3fb4db2d6af38de5a0944ff64e9 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Fri, 1 Aug 2025 12:44:59 -0400 Subject: [PATCH 7/9] serialqueue: Be sure sq->name is null terminated Signed-off-by: Kevin O'Connor --- klippy/chelper/serialqueue.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/klippy/chelper/serialqueue.c b/klippy/chelper/serialqueue.c index 1af00b06..ed1215df 100644 --- a/klippy/chelper/serialqueue.c +++ b/klippy/chelper/serialqueue.c @@ -43,11 +43,11 @@ struct serialqueue { uint8_t need_sync; int input_pos; // Threading + char name[16]; pthread_t tid; pthread_mutex_t lock; // protects variables below pthread_cond_t cond; int receive_waiting; - char name[16]; // Baud / clock tracking int receive_window; double bittime_adjust, idle_time; @@ -634,6 +634,7 @@ serialqueue_alloc(int serial_fd, char serial_fd_type, int client_id sq->serial_fd_type = serial_fd_type; sq->client_id = client_id; strncpy(sq->name, name, sizeof(sq->name)); + sq->name[sizeof(sq->name)-1] = '\0'; int ret = pipe(sq->pipe_fds); if (ret) From e1ba7c17cec8f22ce2bec67699a7902577aadd8d Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Fri, 1 Aug 2025 13:07:44 -0400 Subject: [PATCH 8/9] Revert "queuelogger: set thread name" This reverts commit 73c6674306599000281064b599545aaaa24a5448. Signed-off-by: Kevin O'Connor --- klippy/queuelogger.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/klippy/queuelogger.py b/klippy/queuelogger.py index 7fa93ace..c6447f8e 100644 --- a/klippy/queuelogger.py +++ b/klippy/queuelogger.py @@ -4,7 +4,6 @@ # # This file may be distributed under the terms of the GNU GPLv3 license. import logging, logging.handlers, threading, queue, time -import chelper # Class to forward all messages through a queue to a background thread class QueueHandler(logging.Handler): @@ -26,15 +25,11 @@ class QueueListener(logging.handlers.TimedRotatingFileHandler): def __init__(self, filename): logging.handlers.TimedRotatingFileHandler.__init__( self, filename, when='midnight', backupCount=5) - _, ffi_lib = chelper.get_ffi() - self._set_thread_name = ffi_lib.set_thread_name self.bg_queue = queue.Queue() self.bg_thread = threading.Thread(target=self._bg_thread) self.bg_thread.start() self.rollover_info = {} def _bg_thread(self): - name_short = "queuelogger"[:15] - self._set_thread_name(name_short.encode('utf-8')) while 1: record = self.bg_queue.get(True) if record is None: From 5eb07966b5d7e1534aa40df3b0ea305f5c6d9ae2 Mon Sep 17 00:00:00 2001 From: Dmitry Butyugin Date: Fri, 1 Aug 2025 15:46:24 +0200 Subject: [PATCH 9/9] idex_modes: Fixed dual_carriage axis range calculation after homing Signed-off-by: Dmitry Butyugin --- klippy/kinematics/idex_modes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/klippy/kinematics/idex_modes.py b/klippy/kinematics/idex_modes.py index 19d5a655..46b0be08 100644 --- a/klippy/kinematics/idex_modes.py +++ b/klippy/kinematics/idex_modes.py @@ -124,7 +124,7 @@ class DualCarriages: self.toggle_active_dc_rail(dc) kin.home_axis(homing_state, axis, dc.rail) # Restore the original rails ordering - self.toggle_active_dc_rail(dcs[0]) + self.activate_dc_mode(dcs[0], PRIMARY) def get_status(self, eventtime=None): status = {'carriages' : {dc.get_name() : dc.mode for dc in self.dc_rails.values()}}