diff --git a/klippy/extras/spi_temperature.py b/klippy/extras/spi_temperature.py index 89d3772b..07321a6d 100644 --- a/klippy/extras/spi_temperature.py +++ b/klippy/extras/spi_temperature.py @@ -7,12 +7,6 @@ import math import bus -# Sensor types defined in the micro-controller code (thermocouple.c) -TS_CHIP_MAX31855 = 1 << 0 -TS_CHIP_MAX31856 = 1 << 1 -TS_CHIP_MAX31865 = 1 << 2 -TS_CHIP_MAX6675 = 1 << 3 - ###################################################################### # SensorBase @@ -46,7 +40,7 @@ class SensorBase: return REPORT_TIME def _build_config(self): self.mcu.add_config_cmd( - "config_thermocouple oid=%u spi_oid=%u chip_type=%u" % ( + "config_thermocouple oid=%u spi_oid=%u thermocouple_type=%s" % ( self.oid, self.spi.get_oid(), self.chip_type)) clock = self.mcu.get_query_slot(self.oid) self._report_clock = self.mcu.seconds_to_clock(REPORT_TIME) @@ -123,7 +117,7 @@ MAX31856_MULT = 0.0078125 class MAX31856(SensorBase): def __init__(self, config): - SensorBase.__init__(self, config, TS_CHIP_MAX31856, + SensorBase.__init__(self, config, "MAX31856", self.build_spi_init(config)) def calc_temp(self, adc, fault): if fault & MAX31856_FAULT_CJRANGE: @@ -198,7 +192,7 @@ MAX31855_MULT = 0.25 class MAX31855(SensorBase): def __init__(self, config): - SensorBase.__init__(self, config, TS_CHIP_MAX31855) + SensorBase.__init__(self, config, "MAX31855") def calc_temp(self, adc, fault): if adc & 0x1: self.fault("MAX31855 : Open Circuit") @@ -227,7 +221,7 @@ MAX6675_MULT = 0.25 class MAX6675(SensorBase): def __init__(self, config): - SensorBase.__init__(self, config, TS_CHIP_MAX6675) + SensorBase.__init__(self, config, "MAX6675") def calc_temp(self, adc, fault): if adc & 0x02: self.fault("Max6675 : Device ID error") @@ -281,7 +275,7 @@ class MAX31865(SensorBase): def __init__(self, config): self.rtd_nominal_r = config.getint('rtd_nominal_r', 100) self.reference_r = config.getfloat('rtd_reference_r', 430., above=0.) - SensorBase.__init__(self, config, TS_CHIP_MAX31865, + SensorBase.__init__(self, config, "MAX31865", self.build_spi_init(config)) def calc_temp(self, adc, fault): if fault & 0x80: diff --git a/src/thermocouple.c b/src/thermocouple.c index 2389e7b6..412317fb 100644 --- a/src/thermocouple.c +++ b/src/thermocouple.c @@ -14,12 +14,14 @@ #include "spicmds.h" // spidev_transfer enum { - TS_CHIP_MAX31855 = 1 << 0, - TS_CHIP_MAX31856 = 1 << 1, - TS_CHIP_MAX31865 = 1 << 2, - TS_CHIP_MAX6675 = 1 << 3 + TS_CHIP_MAX31855, TS_CHIP_MAX31856, TS_CHIP_MAX31865, TS_CHIP_MAX6675 }; +DECL_ENUMERATION("thermocouple_type", "MAX31855", TS_CHIP_MAX31855); +DECL_ENUMERATION("thermocouple_type", "MAX31856", TS_CHIP_MAX31856); +DECL_ENUMERATION("thermocouple_type", "MAX31865", TS_CHIP_MAX31865); +DECL_ENUMERATION("thermocouple_type", "MAX6675", TS_CHIP_MAX6675); + struct thermocouple_spi { struct timer timer; uint32_t rest_time; @@ -49,7 +51,7 @@ void command_config_thermocouple(uint32_t *args) { uint8_t chip_type = args[2]; - if (chip_type > TS_CHIP_MAX6675 || !chip_type) + if (chip_type > TS_CHIP_MAX6675) shutdown("Invalid thermocouple chip type"); struct thermocouple_spi *spi = oid_alloc( args[0], command_config_thermocouple, sizeof(*spi)); @@ -58,7 +60,7 @@ command_config_thermocouple(uint32_t *args) spi->chip_type = chip_type; } DECL_COMMAND(command_config_thermocouple, - "config_thermocouple oid=%c spi_oid=%c chip_type=%c"); + "config_thermocouple oid=%c spi_oid=%c thermocouple_type=%c"); void command_query_thermocouple(uint32_t *args)