mirror of
https://github.com/esphome/esphome.git
synced 2024-12-21 21:14:52 +01:00
Implement all supported thermocouple types for MAX31856 (#7218)
Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com> Co-authored-by: Clyde Stubbs <2366188+clydebarrow@users.noreply.github.com>
This commit is contained in:
parent
ffc2b58714
commit
dbecade122
11 changed files with 50 additions and 5 deletions
|
@ -32,6 +32,12 @@ void MAX31856Sensor::dump_config() {
|
|||
LOG_PIN(" CS Pin: ", this->cs_);
|
||||
ESP_LOGCONFIG(TAG, " Mains Filter: %s",
|
||||
(filter_ == FILTER_60HZ ? "60 Hz" : (filter_ == FILTER_50HZ ? "50 Hz" : "Unknown!")));
|
||||
if (this->thermocouple_type_ < 0 || this->thermocouple_type_ > 7) {
|
||||
ESP_LOGCONFIG(TAG, " Thermocouple Type: Unknown");
|
||||
} else {
|
||||
ESP_LOGCONFIG(TAG, " Thermocouple Type: %c", "BEJKNRST"[this->thermocouple_type_]);
|
||||
}
|
||||
|
||||
LOG_UPDATE_INTERVAL(this);
|
||||
}
|
||||
|
||||
|
@ -129,7 +135,12 @@ void MAX31856Sensor::clear_fault_() {
|
|||
}
|
||||
|
||||
void MAX31856Sensor::set_thermocouple_type_() {
|
||||
MAX31856ThermocoupleType type = MAX31856_TCTYPE_K;
|
||||
MAX31856ThermocoupleType type;
|
||||
if (this->thermocouple_type_ < 0 || this->thermocouple_type_ > 7) {
|
||||
type = MAX31856_TCTYPE_K;
|
||||
} else {
|
||||
type = this->thermocouple_type_;
|
||||
}
|
||||
ESP_LOGCONFIG(TAG, "set_thermocouple_type_: 0x%02X", type);
|
||||
uint8_t t = this->read_register_(MAX31856_CR1_REG);
|
||||
t &= 0xF0; // mask off bottom 4 bits
|
||||
|
|
|
@ -50,7 +50,6 @@ enum MAX31856Registers {
|
|||
|
||||
/**
|
||||
* Multiple types of thermocouples supported by the chip.
|
||||
* Currently only K type implemented here.
|
||||
*/
|
||||
enum MAX31856ThermocoupleType {
|
||||
MAX31856_TCTYPE_B = 0b0000, // 0x00
|
||||
|
@ -78,11 +77,15 @@ class MAX31856Sensor : public sensor::Sensor,
|
|||
void setup() override;
|
||||
void dump_config() override;
|
||||
float get_setup_priority() const override;
|
||||
void set_filter(MAX31856ConfigFilter filter) { filter_ = filter; }
|
||||
void set_filter(MAX31856ConfigFilter filter) { this->filter_ = filter; }
|
||||
void set_thermocouple_type(MAX31856ThermocoupleType thermocouple_type) {
|
||||
this->thermocouple_type_ = thermocouple_type;
|
||||
}
|
||||
void update() override;
|
||||
|
||||
protected:
|
||||
MAX31856ConfigFilter filter_;
|
||||
MAX31856ThermocoupleType thermocouple_type_;
|
||||
|
||||
uint8_t read_register_(uint8_t reg);
|
||||
uint32_t read_register24_(uint8_t reg);
|
||||
|
|
|
@ -3,6 +3,7 @@ from esphome.components import sensor, spi
|
|||
import esphome.config_validation as cv
|
||||
from esphome.const import (
|
||||
CONF_MAINS_FILTER,
|
||||
CONF_THERMOCOUPLE_TYPE,
|
||||
DEVICE_CLASS_TEMPERATURE,
|
||||
STATE_CLASS_MEASUREMENT,
|
||||
UNIT_CELSIUS,
|
||||
|
@ -18,6 +19,17 @@ FILTER = {
|
|||
50: MAX31865ConfigFilter.FILTER_50HZ,
|
||||
60: MAX31865ConfigFilter.FILTER_60HZ,
|
||||
}
|
||||
MAX31856ThermocoupleType = max31856_ns.enum("MAX31856ThermocoupleType")
|
||||
THERMOCOUPLE_TYPE = {
|
||||
"B": MAX31856ThermocoupleType.MAX31856_TCTYPE_B,
|
||||
"E": MAX31856ThermocoupleType.MAX31856_TCTYPE_E,
|
||||
"J": MAX31856ThermocoupleType.MAX31856_TCTYPE_J,
|
||||
"K": MAX31856ThermocoupleType.MAX31856_TCTYPE_K,
|
||||
"N": MAX31856ThermocoupleType.MAX31856_TCTYPE_N,
|
||||
"R": MAX31856ThermocoupleType.MAX31856_TCTYPE_R,
|
||||
"S": MAX31856ThermocoupleType.MAX31856_TCTYPE_S,
|
||||
"T": MAX31856ThermocoupleType.MAX31856_TCTYPE_T,
|
||||
}
|
||||
|
||||
CONFIG_SCHEMA = (
|
||||
sensor.sensor_schema(
|
||||
|
@ -34,6 +46,13 @@ CONFIG_SCHEMA = (
|
|||
),
|
||||
}
|
||||
)
|
||||
.extend(
|
||||
{
|
||||
cv.Optional(CONF_THERMOCOUPLE_TYPE, default="K"): cv.enum(
|
||||
THERMOCOUPLE_TYPE, upper=True, space=""
|
||||
),
|
||||
}
|
||||
)
|
||||
.extend(cv.polling_component_schema("60s"))
|
||||
.extend(spi.spi_device_schema())
|
||||
)
|
||||
|
@ -44,3 +63,4 @@ async def to_code(config):
|
|||
await cg.register_component(var, config)
|
||||
await spi.register_spi_device(var, config)
|
||||
cg.add(var.set_filter(config[CONF_MAINS_FILTER]))
|
||||
cg.add(var.set_thermocouple_type(config[CONF_THERMOCOUPLE_TYPE]))
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
from esphome.components import i2c, sensor
|
||||
import esphome.config_validation as cv
|
||||
from esphome.const import (
|
||||
CONF_ID,
|
||||
CONF_THERMOCOUPLE_TYPE,
|
||||
DEVICE_CLASS_TEMPERATURE,
|
||||
STATE_CLASS_MEASUREMENT,
|
||||
UNIT_CELSIUS,
|
||||
)
|
||||
|
||||
CONF_THERMOCOUPLE_TYPE = "thermocouple_type"
|
||||
CONF_HOT_JUNCTION = "hot_junction"
|
||||
CONF_COLD_JUNCTION = "cold_junction"
|
||||
|
||||
|
|
|
@ -852,6 +852,7 @@ CONF_TEMPERATURE_STEP = "temperature_step"
|
|||
CONF_TEXT = "text"
|
||||
CONF_TEXT_SENSORS = "text_sensors"
|
||||
CONF_THEN = "then"
|
||||
CONF_THERMOCOUPLE_TYPE = "thermocouple_type"
|
||||
CONF_THRESHOLD = "threshold"
|
||||
CONF_THROTTLE = "throttle"
|
||||
CONF_TILT = "tilt"
|
||||
|
|
|
@ -10,3 +10,4 @@ sensor:
|
|||
cs_pin: 12
|
||||
update_interval: 15s
|
||||
mains_filter: 50Hz
|
||||
thermocouple_type: N
|
||||
|
|
|
@ -10,3 +10,5 @@ sensor:
|
|||
cs_pin: 8
|
||||
update_interval: 15s
|
||||
mains_filter: 50Hz
|
||||
thermocouple_type: N
|
||||
|
||||
|
|
|
@ -10,3 +10,5 @@ sensor:
|
|||
cs_pin: 8
|
||||
update_interval: 15s
|
||||
mains_filter: 50Hz
|
||||
thermocouple_type: N
|
||||
|
||||
|
|
|
@ -10,3 +10,4 @@ sensor:
|
|||
cs_pin: 12
|
||||
update_interval: 15s
|
||||
mains_filter: 50Hz
|
||||
thermocouple_type: N
|
||||
|
|
|
@ -10,3 +10,5 @@ sensor:
|
|||
cs_pin: 15
|
||||
update_interval: 15s
|
||||
mains_filter: 50Hz
|
||||
thermocouple_type: N
|
||||
|
||||
|
|
|
@ -10,3 +10,5 @@ sensor:
|
|||
cs_pin: 6
|
||||
update_interval: 15s
|
||||
mains_filter: 50Hz
|
||||
thermocouple_type: N
|
||||
|
||||
|
|
Loading…
Reference in a new issue