diff --git a/klippy/fan.py b/klippy/fan.py index 112fb34c..3f9bd63d 100644 --- a/klippy/fan.py +++ b/klippy/fan.py @@ -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. diff --git a/klippy/gcode.py b/klippy/gcode.py index 45da131c..37e1c2af 100644 --- a/klippy/gcode.py +++ b/klippy/gcode.py @@ -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) diff --git a/klippy/heater.py b/klippy/heater.py index 7acd38b1..445f868b 100644 --- a/klippy/heater.py +++ b/klippy/heater.py @@ -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: diff --git a/src/adccmds.c b/src/adccmds.c index d95ad282..41247a54 100644 --- a/src/adccmds.c +++ b/src/adccmds.c @@ -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); diff --git a/src/linux/analog.c b/src/linux/analog.c index 88adc9dd..c909e286 100644 --- a/src/linux/analog.c +++ b/src/linux/analog.c @@ -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);