mirror of
https://github.com/andreili/klipper.git
synced 2025-08-23 19:34:06 +02:00
Merge branch 'Klipper3d:master' into master
This commit is contained in:
commit
765842ca8a
@ -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
|
||||
|
||||
|
@ -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 = """
|
||||
|
@ -10,6 +10,8 @@
|
||||
#include <stdio.h> // fprintf
|
||||
#include <string.h> // strerror
|
||||
#include <time.h> // struct timespec
|
||||
#include <linux/prctl.h> // PR_SET_NAME
|
||||
#include <sys/prctl.h> // 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);
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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);
|
||||
|
@ -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)
|
||||
|
@ -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 = {}
|
||||
|
@ -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()}}
|
||||
|
@ -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)
|
||||
|
@ -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(
|
||||
|
Loading…
x
Reference in New Issue
Block a user