spi_temperature: Use setup_minmax() to set the temperature range

Use setup_minmax() instead of directly reading the min/max temperature
from the config.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2018-07-24 14:12:00 -04:00
parent 270080cd4c
commit 7510efe827
1 changed files with 5 additions and 8 deletions

View File

@ -25,16 +25,11 @@ class error(Exception):
class SensorBase: class SensorBase:
error = error error = error
def __init__(self, config): def __init__(self, config):
self.min_temp = config.getfloat('min_temp', minval=0., default=0.)
self.max_temp = config.getfloat('max_temp', above=self.min_temp)
self._callback = None self._callback = None
sensor_pin = config.get('sensor_pin') self.min_sample_value = self.max_sample_value = 0
adc_range = [self.calc_adc(self.min_temp),
self.calc_adc(self.max_temp)]
self.min_sample_value = min(adc_range)
self.max_sample_value = max(adc_range)
self._report_clock = 0 self._report_clock = 0
ppins = config.get_printer().lookup_object('pins') ppins = config.get_printer().lookup_object('pins')
sensor_pin = config.get('sensor_pin')
pin_params = ppins.lookup_pin('digital_out', sensor_pin) pin_params = ppins.lookup_pin('digital_out', sensor_pin)
self.mcu = mcu = pin_params['chip'] self.mcu = mcu = pin_params['chip']
pin = pin_params['pin'] pin = pin_params['pin']
@ -58,7 +53,9 @@ class SensorBase:
"thermocouple_result", oid) "thermocouple_result", oid)
mcu.add_config_object(self) mcu.add_config_object(self)
def setup_minmax(self, min_temp, max_temp): def setup_minmax(self, min_temp, max_temp):
pass adc_range = [self.calc_adc(min_temp), self.calc_adc(max_temp)]
self.min_sample_value = min(adc_range)
self.max_sample_value = max(adc_range)
def setup_callback(self, cb): def setup_callback(self, cb):
self._callback = cb self._callback = cb
def get_report_time_delta(self): def get_report_time_delta(self):