thermocouple: Define thermocouple types using enumerations
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
618b374ae5
commit
0af89e4766
|
@ -7,12 +7,6 @@
|
||||||
import math
|
import math
|
||||||
import bus
|
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
|
# SensorBase
|
||||||
|
@ -46,7 +40,7 @@ class SensorBase:
|
||||||
return REPORT_TIME
|
return REPORT_TIME
|
||||||
def _build_config(self):
|
def _build_config(self):
|
||||||
self.mcu.add_config_cmd(
|
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))
|
self.oid, self.spi.get_oid(), self.chip_type))
|
||||||
clock = self.mcu.get_query_slot(self.oid)
|
clock = self.mcu.get_query_slot(self.oid)
|
||||||
self._report_clock = self.mcu.seconds_to_clock(REPORT_TIME)
|
self._report_clock = self.mcu.seconds_to_clock(REPORT_TIME)
|
||||||
|
@ -123,7 +117,7 @@ MAX31856_MULT = 0.0078125
|
||||||
|
|
||||||
class MAX31856(SensorBase):
|
class MAX31856(SensorBase):
|
||||||
def __init__(self, config):
|
def __init__(self, config):
|
||||||
SensorBase.__init__(self, config, TS_CHIP_MAX31856,
|
SensorBase.__init__(self, config, "MAX31856",
|
||||||
self.build_spi_init(config))
|
self.build_spi_init(config))
|
||||||
def calc_temp(self, adc, fault):
|
def calc_temp(self, adc, fault):
|
||||||
if fault & MAX31856_FAULT_CJRANGE:
|
if fault & MAX31856_FAULT_CJRANGE:
|
||||||
|
@ -198,7 +192,7 @@ MAX31855_MULT = 0.25
|
||||||
|
|
||||||
class MAX31855(SensorBase):
|
class MAX31855(SensorBase):
|
||||||
def __init__(self, config):
|
def __init__(self, config):
|
||||||
SensorBase.__init__(self, config, TS_CHIP_MAX31855)
|
SensorBase.__init__(self, config, "MAX31855")
|
||||||
def calc_temp(self, adc, fault):
|
def calc_temp(self, adc, fault):
|
||||||
if adc & 0x1:
|
if adc & 0x1:
|
||||||
self.fault("MAX31855 : Open Circuit")
|
self.fault("MAX31855 : Open Circuit")
|
||||||
|
@ -227,7 +221,7 @@ MAX6675_MULT = 0.25
|
||||||
|
|
||||||
class MAX6675(SensorBase):
|
class MAX6675(SensorBase):
|
||||||
def __init__(self, config):
|
def __init__(self, config):
|
||||||
SensorBase.__init__(self, config, TS_CHIP_MAX6675)
|
SensorBase.__init__(self, config, "MAX6675")
|
||||||
def calc_temp(self, adc, fault):
|
def calc_temp(self, adc, fault):
|
||||||
if adc & 0x02:
|
if adc & 0x02:
|
||||||
self.fault("Max6675 : Device ID error")
|
self.fault("Max6675 : Device ID error")
|
||||||
|
@ -281,7 +275,7 @@ class MAX31865(SensorBase):
|
||||||
def __init__(self, config):
|
def __init__(self, config):
|
||||||
self.rtd_nominal_r = config.getint('rtd_nominal_r', 100)
|
self.rtd_nominal_r = config.getint('rtd_nominal_r', 100)
|
||||||
self.reference_r = config.getfloat('rtd_reference_r', 430., above=0.)
|
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))
|
self.build_spi_init(config))
|
||||||
def calc_temp(self, adc, fault):
|
def calc_temp(self, adc, fault):
|
||||||
if fault & 0x80:
|
if fault & 0x80:
|
||||||
|
|
|
@ -14,12 +14,14 @@
|
||||||
#include "spicmds.h" // spidev_transfer
|
#include "spicmds.h" // spidev_transfer
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
TS_CHIP_MAX31855 = 1 << 0,
|
TS_CHIP_MAX31855, TS_CHIP_MAX31856, TS_CHIP_MAX31865, TS_CHIP_MAX6675
|
||||||
TS_CHIP_MAX31856 = 1 << 1,
|
|
||||||
TS_CHIP_MAX31865 = 1 << 2,
|
|
||||||
TS_CHIP_MAX6675 = 1 << 3
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
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 thermocouple_spi {
|
||||||
struct timer timer;
|
struct timer timer;
|
||||||
uint32_t rest_time;
|
uint32_t rest_time;
|
||||||
|
@ -49,7 +51,7 @@ void
|
||||||
command_config_thermocouple(uint32_t *args)
|
command_config_thermocouple(uint32_t *args)
|
||||||
{
|
{
|
||||||
uint8_t chip_type = args[2];
|
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");
|
shutdown("Invalid thermocouple chip type");
|
||||||
struct thermocouple_spi *spi = oid_alloc(
|
struct thermocouple_spi *spi = oid_alloc(
|
||||||
args[0], command_config_thermocouple, sizeof(*spi));
|
args[0], command_config_thermocouple, sizeof(*spi));
|
||||||
|
@ -58,7 +60,7 @@ command_config_thermocouple(uint32_t *args)
|
||||||
spi->chip_type = chip_type;
|
spi->chip_type = chip_type;
|
||||||
}
|
}
|
||||||
DECL_COMMAND(command_config_thermocouple,
|
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
|
void
|
||||||
command_query_thermocouple(uint32_t *args)
|
command_query_thermocouple(uint32_t *args)
|
||||||
|
|
Loading…
Reference in New Issue