heater: Enforce min/max_temp in heater.set_temp()
Raise an error if the user requests a temperate outside the configured min/max_temp range. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
566699f68a
commit
47f1d377f5
|
@ -191,7 +191,11 @@ class GCodeParser:
|
||||||
def set_temp(self, heater, params, wait=False):
|
def set_temp(self, heater, params, wait=False):
|
||||||
print_time = self.toolhead.get_last_move_time()
|
print_time = self.toolhead.get_last_move_time()
|
||||||
temp = float(params.get('S', '0'))
|
temp = float(params.get('S', '0'))
|
||||||
|
try:
|
||||||
heater.set_temp(print_time, temp)
|
heater.set_temp(print_time, temp)
|
||||||
|
except heater.error, e:
|
||||||
|
self.respond_error(str(e))
|
||||||
|
return
|
||||||
if wait:
|
if wait:
|
||||||
self.bg_temp(heater)
|
self.bg_temp(heater)
|
||||||
# Individual command handlers
|
# Individual command handlers
|
||||||
|
|
|
@ -21,7 +21,11 @@ MAX_HEAT_TIME = 5.0
|
||||||
AMBIENT_TEMP = 25.
|
AMBIENT_TEMP = 25.
|
||||||
PWM_MAX = 255
|
PWM_MAX = 255
|
||||||
|
|
||||||
|
class error(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
class PrinterHeater:
|
class PrinterHeater:
|
||||||
|
error = error
|
||||||
def __init__(self, printer, config):
|
def __init__(self, printer, config):
|
||||||
self.printer = printer
|
self.printer = printer
|
||||||
self.config = config
|
self.config = config
|
||||||
|
@ -29,6 +33,8 @@ class PrinterHeater:
|
||||||
self.thermistor_c = config.getchoice('thermistor_type', Thermistors)
|
self.thermistor_c = config.getchoice('thermistor_type', Thermistors)
|
||||||
self.pullup_r = config.getfloat('pullup_resistor', 4700.)
|
self.pullup_r = config.getfloat('pullup_resistor', 4700.)
|
||||||
self.min_extrude_temp = config.getfloat('min_extrude_temp', 170.)
|
self.min_extrude_temp = config.getfloat('min_extrude_temp', 170.)
|
||||||
|
self.min_temp = self.config.getfloat('min_temp')
|
||||||
|
self.max_temp = self.config.getfloat('max_temp')
|
||||||
self.can_extrude = (self.min_extrude_temp <= 0.)
|
self.can_extrude = (self.min_extrude_temp <= 0.)
|
||||||
self.lock = threading.Lock()
|
self.lock = threading.Lock()
|
||||||
self.last_temp = 0.
|
self.last_temp = 0.
|
||||||
|
@ -50,8 +56,8 @@ class PrinterHeater:
|
||||||
self.mcu_pwm = self.printer.mcu.create_pwm(
|
self.mcu_pwm = self.printer.mcu.create_pwm(
|
||||||
heater_pin, 0, MAX_HEAT_TIME)
|
heater_pin, 0, MAX_HEAT_TIME)
|
||||||
self.mcu_adc = self.printer.mcu.create_adc(thermistor_pin)
|
self.mcu_adc = self.printer.mcu.create_adc(thermistor_pin)
|
||||||
min_adc = self.calc_adc(self.config.getfloat('max_temp'))
|
min_adc = self.calc_adc(self.max_temp)
|
||||||
max_adc = self.calc_adc(self.config.getfloat('min_temp'))
|
max_adc = self.calc_adc(self.min_temp)
|
||||||
self.mcu_adc.set_minmax(
|
self.mcu_adc.set_minmax(
|
||||||
SAMPLE_TIME, SAMPLE_COUNT, minval=min_adc, maxval=max_adc)
|
SAMPLE_TIME, SAMPLE_COUNT, minval=min_adc, maxval=max_adc)
|
||||||
self.mcu_adc.set_adc_callback(REPORT_TIME, self.adc_callback)
|
self.mcu_adc.set_adc_callback(REPORT_TIME, self.adc_callback)
|
||||||
|
@ -102,6 +108,9 @@ class PrinterHeater:
|
||||||
#logging.debug("temp: %.3f %f = %f" % (read_time, read_value, temp))
|
#logging.debug("temp: %.3f %f = %f" % (read_time, read_value, temp))
|
||||||
# External commands
|
# External commands
|
||||||
def set_temp(self, print_time, degrees):
|
def set_temp(self, print_time, degrees):
|
||||||
|
if degrees and (degrees < self.min_temp or degrees > self.max_temp):
|
||||||
|
raise error("Requested temperature (%.1f) out of range (%.1f:%.1f)"
|
||||||
|
% (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):
|
||||||
|
|
Loading…
Reference in New Issue