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:
Kevin O'Connor 2017-10-11 22:16:02 -04:00
parent 744c6d114e
commit d03cf2b83f
5 changed files with 20 additions and 10 deletions

View File

@ -41,7 +41,7 @@ class PrinterHeaterFan:
self.heater_temp = config.getfloat("heater_temp", 50.0) self.heater_temp = config.getfloat("heater_temp", 50.0)
printer.reactor.register_timer(self.callback, printer.reactor.NOW) printer.reactor.register_timer(self.callback, printer.reactor.NOW)
def callback(self, eventtime): 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: if not current_temp and not target_temp and not self.fan.last_fan_time:
# Printer still starting # Printer still starting
return eventtime + 1. return eventtime + 1.

View File

@ -210,18 +210,18 @@ class GCodeParser:
except ValueError as e: except ValueError as e:
raise error("Malformed command '%s'" % (params['#original'],)) raise error("Malformed command '%s'" % (params['#original'],))
# Temperature wrappers # Temperature wrappers
def get_temp(self): def get_temp(self, eventtime):
if not self.is_printer_ready:
return "T:0"
# Tn:XXX /YYY B:XXX /YYY # Tn:XXX /YYY B:XXX /YYY
out = [] out = []
for i, heater in enumerate(self.heaters): for i, heater in enumerate(self.heaters):
if heater is not None: if heater is not None:
cur, target = heater.get_temp() cur, target = heater.get_temp(eventtime)
name = "B" name = "B"
if i < len(self.heaters) - 1: if i < len(self.heaters) - 1:
name = "T%d" % (i,) name = "T%d" % (i,)
out.append("%s:%.1f /%.1f" % (name, cur, target)) out.append("%s:%.1f /%.1f" % (name, cur, target))
if not out:
return "T:0"
return " ".join(out) return " ".join(out)
def bg_temp(self, heater): def bg_temp(self, heater):
if self.is_fileinput: if self.is_fileinput:
@ -229,7 +229,7 @@ class GCodeParser:
eventtime = self.reactor.monotonic() eventtime = self.reactor.monotonic()
while self.is_printer_ready and heater.check_busy(eventtime): while self.is_printer_ready and heater.check_busy(eventtime):
print_time = self.toolhead.get_last_move_time() 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.) eventtime = self.reactor.pause(eventtime + 1.)
def set_temp(self, params, is_bed=False, wait=False): def set_temp(self, params, is_bed=False, wait=False):
temp = self.get_float('S', params, 0.) temp = self.get_float('S', params, 0.)
@ -387,7 +387,7 @@ class GCodeParser:
cmd_M105_when_not_ready = True cmd_M105_when_not_ready = True
def cmd_M105(self, params): def cmd_M105(self, params):
# Get Extruder Temperature # Get Extruder Temperature
self.ack(self.get_temp()) self.ack(self.get_temp(self.reactor.monotonic()))
def cmd_M104(self, params): def cmd_M104(self, params):
# Set Extruder Temperature # Set Extruder Temperature
self.set_temp(params) self.set_temp(params)

View File

@ -167,8 +167,11 @@ class PrinterHeater:
% (degrees, self.min_temp, self.max_temp)) % (degrees, self.min_temp, self.max_temp))
with self.lock: with self.lock:
self.target_temp = degrees 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: with self.lock:
if self.last_temp_time < print_time:
return 0., self.target_temp
return self.last_temp, self.target_temp return self.last_temp, self.target_temp
def check_busy(self, eventtime): def check_busy(self, eventtime):
with self.lock: with self.lock:

View File

@ -43,7 +43,7 @@ analog_in_event(struct timer *timer)
return SF_RESCHEDULE; return SF_RESCHEDULE;
} }
if (a->value < a->min_value || a->value > a->max_value) 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); sched_wake_task(&analog_wake);
a->next_begin_time += a->rest_time; a->next_begin_time += a->rest_time;
a->timer.waketime = a->next_begin_time; a->timer.waketime = a->next_begin_time;
@ -115,6 +115,12 @@ analog_in_shutdown(void)
struct analog_in *a; struct analog_in *a;
foreach_oid(i, a, command_config_analog_in) { foreach_oid(i, a, command_config_analog_in) {
gpio_adc_cancel_sample(a->pin); 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); DECL_SHUTDOWN(analog_in_shutdown);

View File

@ -49,7 +49,8 @@ gpio_adc_read(struct gpio_adc g)
int ret = pread(g.fd, buf, sizeof(buf)-1, 0); int ret = pread(g.fd, buf, sizeof(buf)-1, 0);
if (ret <= 0) { if (ret <= 0) {
report_errno("analog read", ret); report_errno("analog read", ret);
shutdown("Error on analog read"); try_shutdown("Error on analog read");
return 0;
} }
buf[ret] = '\0'; buf[ret] = '\0';
return atoi(buf); return atoi(buf);