heaters: Make sure set_temp() command wakes up the idle_timeout

Introduce a heaters.set_temperature() command and call that from
commands that set a heater temperature.  This new function calls
toolhead.register_lookahead_callback() so that the idle_timeout gets
notification that activity has occurred.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2021-03-05 18:41:21 -05:00
parent 1950380d6c
commit 64b3e5642e
4 changed files with 14 additions and 12 deletions

View File

@ -18,10 +18,8 @@ class PrinterHeaterBed:
def cmd_M140(self, gcmd, wait=False): def cmd_M140(self, gcmd, wait=False):
# Set Bed Temperature # Set Bed Temperature
temp = gcmd.get_float('S', 0.) temp = gcmd.get_float('S', 0.)
self.heater.set_temp(temp)
if wait and temp:
pheaters = self.printer.lookup_object('heaters') pheaters = self.printer.lookup_object('heaters')
pheaters.wait_for_temperature(self.heater) pheaters.set_temperature(self.heater, temp, wait)
def cmd_M190(self, gcmd): def cmd_M190(self, gcmd):
# Set Bed Temperature and Wait # Set Bed Temperature and Wait
self.cmd_M140(gcmd, wait=True) self.cmd_M140(gcmd, wait=True)

View File

@ -138,7 +138,8 @@ class Heater:
cmd_SET_HEATER_TEMPERATURE_help = "Sets a heater temperature" cmd_SET_HEATER_TEMPERATURE_help = "Sets a heater temperature"
def cmd_SET_HEATER_TEMPERATURE(self, gcmd): def cmd_SET_HEATER_TEMPERATURE(self, gcmd):
temp = gcmd.get_float('TARGET', 0.) temp = gcmd.get_float('TARGET', 0.)
self.set_temp(temp) pheaters = self.printer.lookup_object('heaters')
pheaters.set_temperature(self, temp)
###################################################################### ######################################################################
@ -313,7 +314,7 @@ class PrinterHeaters:
did_ack = gcmd.ack(msg) did_ack = gcmd.ack(msg)
if not did_ack: if not did_ack:
gcmd.respond_raw(msg) gcmd.respond_raw(msg)
def wait_for_temperature(self, heater): def _wait_for_temperature(self, heater):
# Helper to wait on heater.check_busy() and report M105 temperatures # Helper to wait on heater.check_busy() and report M105 temperatures
if self.printer.get_start_args().get('debugoutput') is not None: if self.printer.get_start_args().get('debugoutput') is not None:
return return
@ -325,6 +326,12 @@ class PrinterHeaters:
print_time = toolhead.get_last_move_time() print_time = toolhead.get_last_move_time()
gcode.respond_raw(self._get_temp(eventtime)) gcode.respond_raw(self._get_temp(eventtime))
eventtime = reactor.pause(eventtime + 1.) eventtime = reactor.pause(eventtime + 1.)
def set_temperature(self, heater, temp, wait=False):
toolhead = self.printer.lookup_object('toolhead')
toolhead.register_lookahead_callback((lambda pt: None))
heater.set_temp(temp)
if wait and temp:
self._wait_for_temperature(heater)
cmd_TEMPERATURE_WAIT_help = "Wait for a temperature on a sensor" cmd_TEMPERATURE_WAIT_help = "Wait for a temperature on a sensor"
def cmd_TEMPERATURE_WAIT(self, gcmd): def cmd_TEMPERATURE_WAIT(self, gcmd):
sensor_name = gcmd.get('SENSOR') sensor_name = gcmd.get('SENSOR')

View File

@ -26,11 +26,10 @@ class PIDCalibrate:
calibrate = ControlAutoTune(heater, target) calibrate = ControlAutoTune(heater, target)
old_control = heater.set_control(calibrate) old_control = heater.set_control(calibrate)
try: try:
heater.set_temp(target) pheaters.set_temperature(heater, target, True)
except self.printer.command_error as e: except self.printer.command_error as e:
heater.set_control(old_control) heater.set_control(old_control)
raise raise
pheaters.wait_for_temperature(heater)
heater.set_control(old_control) heater.set_control(old_control)
if write_file: if write_file:
calibrate.write_file('/tmp/heattest.txt') calibrate.write_file('/tmp/heattest.txt')

View File

@ -167,10 +167,8 @@ class PrinterExtruder:
raise gcmd.error("Extruder not configured") raise gcmd.error("Extruder not configured")
else: else:
extruder = self.printer.lookup_object('toolhead').get_extruder() extruder = self.printer.lookup_object('toolhead').get_extruder()
heater = extruder.get_heater() pheaters = self.printer.lookup_object('heaters')
heater.set_temp(temp) pheaters.set_temperature(extruder.get_heater(), temp, wait)
if wait and temp:
self.printer.lookup_object('heaters').wait_for_temperature(heater)
def cmd_M109(self, gcmd): def cmd_M109(self, gcmd):
# Set Extruder Temperature and Wait # Set Extruder Temperature and Wait
self.cmd_M104(gcmd, wait=True) self.cmd_M104(gcmd, wait=True)