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/chelper/__init__.py b/klippy/chelper/__init__.py index 2aed107a..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); @@ -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 diff --git a/klippy/chelper/serialqueue.c b/klippy/chelper/serialqueue.c index c207495c..ed1215df 100644 --- a/klippy/chelper/serialqueue.c +++ b/klippy/chelper/serialqueue.c @@ -43,6 +43,7 @@ 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; @@ -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,16 @@ 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)); + sq->name[sizeof(sq->name)-1] = '\0'; 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/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) 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 = {} 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()}} 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..2a401f89 100644 --- a/klippy/serialhdl.py +++ b/klippy/serialhdl.py @@ -12,12 +12,17 @@ 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) + 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=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 +39,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) @@ -80,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() @@ -200,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(