mirror of https://github.com/Desuuuu/klipper.git
spi_temperature: Eliminate check_faults() callback
The faults can be checked from the calc_temp() method. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
f20dd0c9be
commit
f168032901
|
@ -70,13 +70,10 @@ class SensorBase:
|
||||||
self.oid, clock, self._report_clock,
|
self.oid, clock, self._report_clock,
|
||||||
self.min_sample_value, self.max_sample_value))
|
self.min_sample_value, self.max_sample_value))
|
||||||
def _handle_spi_response(self, params):
|
def _handle_spi_response(self, params):
|
||||||
last_value = params['value']
|
temp = self.calc_temp(params['value'], params['fault'])
|
||||||
next_clock = self.mcu.clock32_to_clock64(params['next_clock'])
|
next_clock = self.mcu.clock32_to_clock64(params['next_clock'])
|
||||||
last_read_clock = next_clock - self._report_clock
|
last_read_clock = next_clock - self._report_clock
|
||||||
last_read_time = self.mcu.clock_to_print_time(last_read_clock)
|
last_read_time = self.mcu.clock_to_print_time(last_read_clock)
|
||||||
temp = self.calc_temp(last_value)
|
|
||||||
self.check_faults(params['fault'])
|
|
||||||
if self._callback is not None:
|
|
||||||
self._callback(last_read_time, temp)
|
self._callback(last_read_time, temp)
|
||||||
|
|
||||||
|
|
||||||
|
@ -160,7 +157,7 @@ class MAX31856(SensorBase):
|
||||||
}
|
}
|
||||||
self.average_count = config.getchoice('tc_averaging_count', averages, "1")
|
self.average_count = config.getchoice('tc_averaging_count', averages, "1")
|
||||||
SensorBase.__init__(self, config)
|
SensorBase.__init__(self, config)
|
||||||
def check_faults(self, fault):
|
def calc_temp(self, adc, fault):
|
||||||
if fault & MAX31856_FAULT_CJRANGE:
|
if fault & MAX31856_FAULT_CJRANGE:
|
||||||
raise self.error("Max31856: Cold Junction Range Fault")
|
raise self.error("Max31856: Cold Junction Range Fault")
|
||||||
if fault & MAX31856_FAULT_TCRANGE:
|
if fault & MAX31856_FAULT_TCRANGE:
|
||||||
|
@ -177,7 +174,6 @@ class MAX31856(SensorBase):
|
||||||
raise self.error("Max31856: Over/Under Voltage Fault")
|
raise self.error("Max31856: Over/Under Voltage Fault")
|
||||||
if fault & MAX31856_FAULT_OPEN:
|
if fault & MAX31856_FAULT_OPEN:
|
||||||
raise self.error("Max31856: Thermocouple Open Fault")
|
raise self.error("Max31856: Thermocouple Open Fault")
|
||||||
def calc_temp(self, adc):
|
|
||||||
adc = adc >> MAX31856_SCALE
|
adc = adc >> MAX31856_SCALE
|
||||||
# Fix sign bit:
|
# Fix sign bit:
|
||||||
if adc & 0x40000:
|
if adc & 0x40000:
|
||||||
|
@ -219,9 +215,7 @@ class MAX31855(SensorBase):
|
||||||
def __init__(self, config):
|
def __init__(self, config):
|
||||||
self.chip_type = "MAX31855"
|
self.chip_type = "MAX31855"
|
||||||
SensorBase.__init__(self, config)
|
SensorBase.__init__(self, config)
|
||||||
def check_faults(self, fault):
|
def calc_temp(self, adc, fault):
|
||||||
pass
|
|
||||||
def calc_temp(self, adc):
|
|
||||||
if adc & 0x1:
|
if adc & 0x1:
|
||||||
raise self.error("MAX31855 : Open Circuit")
|
raise self.error("MAX31855 : Open Circuit")
|
||||||
if adc & 0x2:
|
if adc & 0x2:
|
||||||
|
@ -253,9 +247,7 @@ class MAX6675(SensorBase):
|
||||||
def __init__(self, config):
|
def __init__(self, config):
|
||||||
self.chip_type = "MAX6675"
|
self.chip_type = "MAX6675"
|
||||||
SensorBase.__init__(self, config)
|
SensorBase.__init__(self, config)
|
||||||
def check_faults(self, fault):
|
def calc_temp(self, adc, fault):
|
||||||
pass
|
|
||||||
def calc_temp(self, adc):
|
|
||||||
if adc & 0x02:
|
if adc & 0x02:
|
||||||
raise self.error("Max6675 : Device ID error")
|
raise self.error("Max6675 : Device ID error")
|
||||||
if adc & 0x04:
|
if adc & 0x04:
|
||||||
|
@ -314,7 +306,7 @@ class MAX31865(SensorBase):
|
||||||
self.num_wires = config.getint('rtd_num_of_wires', 2)
|
self.num_wires = config.getint('rtd_num_of_wires', 2)
|
||||||
self.use_50Hz_filter = config.getboolean('rtd_use_50Hz_filter', False)
|
self.use_50Hz_filter = config.getboolean('rtd_use_50Hz_filter', False)
|
||||||
SensorBase.__init__(self, config)
|
SensorBase.__init__(self, config)
|
||||||
def check_faults(self, fault):
|
def calc_temp(self, adc, fault):
|
||||||
if fault & 0x80:
|
if fault & 0x80:
|
||||||
raise self.error("Max31865 RTD input is disconnected")
|
raise self.error("Max31865 RTD input is disconnected")
|
||||||
if fault & 0x40:
|
if fault & 0x40:
|
||||||
|
@ -329,7 +321,6 @@ class MAX31865(SensorBase):
|
||||||
raise self.error("Max31865 Overvoltage or undervoltage fault")
|
raise self.error("Max31865 Overvoltage or undervoltage fault")
|
||||||
if fault & 0x03:
|
if fault & 0x03:
|
||||||
raise self.error("Max31865 Unspecified error")
|
raise self.error("Max31865 Unspecified error")
|
||||||
def calc_temp(self, adc):
|
|
||||||
adc = adc >> 1 # remove fault bit
|
adc = adc >> 1 # remove fault bit
|
||||||
R_rtd = (self.reference_r * adc) / VAL_ADC_MAX
|
R_rtd = (self.reference_r * adc) / VAL_ADC_MAX
|
||||||
temp = (
|
temp = (
|
||||||
|
|
Loading…
Reference in New Issue