mirror of https://github.com/Desuuuu/klipper.git
adccmds: Continue to query analog inputs after a shutdown
Continue to sample the ADC input pins even if the MCU goes into a shutdown state. This enables the printer to continue reporting temperatures even on an mcu error. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
744c6d114e
commit
d03cf2b83f
|
@ -41,7 +41,7 @@ class PrinterHeaterFan:
|
|||
self.heater_temp = config.getfloat("heater_temp", 50.0)
|
||||
printer.reactor.register_timer(self.callback, printer.reactor.NOW)
|
||||
def callback(self, eventtime):
|
||||
current_temp, target_temp = self.heater.get_temp()
|
||||
current_temp, target_temp = self.heater.get_temp(eventtime)
|
||||
if not current_temp and not target_temp and not self.fan.last_fan_time:
|
||||
# Printer still starting
|
||||
return eventtime + 1.
|
||||
|
|
|
@ -210,18 +210,18 @@ class GCodeParser:
|
|||
except ValueError as e:
|
||||
raise error("Malformed command '%s'" % (params['#original'],))
|
||||
# Temperature wrappers
|
||||
def get_temp(self):
|
||||
if not self.is_printer_ready:
|
||||
return "T:0"
|
||||
def get_temp(self, eventtime):
|
||||
# Tn:XXX /YYY B:XXX /YYY
|
||||
out = []
|
||||
for i, heater in enumerate(self.heaters):
|
||||
if heater is not None:
|
||||
cur, target = heater.get_temp()
|
||||
cur, target = heater.get_temp(eventtime)
|
||||
name = "B"
|
||||
if i < len(self.heaters) - 1:
|
||||
name = "T%d" % (i,)
|
||||
out.append("%s:%.1f /%.1f" % (name, cur, target))
|
||||
if not out:
|
||||
return "T:0"
|
||||
return " ".join(out)
|
||||
def bg_temp(self, heater):
|
||||
if self.is_fileinput:
|
||||
|
@ -229,7 +229,7 @@ class GCodeParser:
|
|||
eventtime = self.reactor.monotonic()
|
||||
while self.is_printer_ready and heater.check_busy(eventtime):
|
||||
print_time = self.toolhead.get_last_move_time()
|
||||
self.respond(self.get_temp())
|
||||
self.respond(self.get_temp(eventtime))
|
||||
eventtime = self.reactor.pause(eventtime + 1.)
|
||||
def set_temp(self, params, is_bed=False, wait=False):
|
||||
temp = self.get_float('S', params, 0.)
|
||||
|
@ -387,7 +387,7 @@ class GCodeParser:
|
|||
cmd_M105_when_not_ready = True
|
||||
def cmd_M105(self, params):
|
||||
# Get Extruder Temperature
|
||||
self.ack(self.get_temp())
|
||||
self.ack(self.get_temp(self.reactor.monotonic()))
|
||||
def cmd_M104(self, params):
|
||||
# Set Extruder Temperature
|
||||
self.set_temp(params)
|
||||
|
|
|
@ -167,8 +167,11 @@ class PrinterHeater:
|
|||
% (degrees, self.min_temp, self.max_temp))
|
||||
with self.lock:
|
||||
self.target_temp = degrees
|
||||
def get_temp(self):
|
||||
def get_temp(self, eventtime):
|
||||
print_time = self.mcu_adc.get_mcu().estimated_print_time(eventtime) - 5.
|
||||
with self.lock:
|
||||
if self.last_temp_time < print_time:
|
||||
return 0., self.target_temp
|
||||
return self.last_temp, self.target_temp
|
||||
def check_busy(self, eventtime):
|
||||
with self.lock:
|
||||
|
|
|
@ -43,7 +43,7 @@ analog_in_event(struct timer *timer)
|
|||
return SF_RESCHEDULE;
|
||||
}
|
||||
if (a->value < a->min_value || a->value > a->max_value)
|
||||
shutdown("ADC out of range");
|
||||
try_shutdown("ADC out of range");
|
||||
sched_wake_task(&analog_wake);
|
||||
a->next_begin_time += a->rest_time;
|
||||
a->timer.waketime = a->next_begin_time;
|
||||
|
@ -115,6 +115,12 @@ analog_in_shutdown(void)
|
|||
struct analog_in *a;
|
||||
foreach_oid(i, a, command_config_analog_in) {
|
||||
gpio_adc_cancel_sample(a->pin);
|
||||
if (a->sample_count) {
|
||||
a->state = a->sample_count + 1;
|
||||
a->next_begin_time += a->rest_time;
|
||||
a->timer.waketime = a->next_begin_time;
|
||||
sched_add_timer(&a->timer);
|
||||
}
|
||||
}
|
||||
}
|
||||
DECL_SHUTDOWN(analog_in_shutdown);
|
||||
|
|
|
@ -49,7 +49,8 @@ gpio_adc_read(struct gpio_adc g)
|
|||
int ret = pread(g.fd, buf, sizeof(buf)-1, 0);
|
||||
if (ret <= 0) {
|
||||
report_errno("analog read", ret);
|
||||
shutdown("Error on analog read");
|
||||
try_shutdown("Error on analog read");
|
||||
return 0;
|
||||
}
|
||||
buf[ret] = '\0';
|
||||
return atoi(buf);
|
||||
|
|
Loading…
Reference in New Issue