mirror of
https://github.com/Threnklyn/esphome-dev.git
synced 2026-06-13 16:13:32 +02:00
Fix MAX31865 edge case. (#882)
In a heavy EMI environment, reading the current config from the MAX31865 can fail, such as switching from a 4-wire sensor to a 3-wire sensor. This causes the temperature value to be off wildly, but still technically valid, so it doesn't get reported as a sensor failure. Since we know what configuration we want, rather than send it to the MAX31865 on setup and ask for it over and over (propagating any error as we write it back), instead store the base configuration and work from that to change modes. This not only avoids propagating any error, it also saves a lot of unnecessary reads from the MAX31865.
This commit is contained in:
@@ -43,10 +43,12 @@ class MAX31865Sensor : public sensor::Sensor,
|
||||
float rtd_nominal_resistance_;
|
||||
MAX31865ConfigFilter filter_;
|
||||
uint8_t rtd_wires_;
|
||||
uint8_t base_config_;
|
||||
bool has_fault_ = false;
|
||||
bool has_warn_ = false;
|
||||
void read_data_();
|
||||
void write_register_(uint8_t reg, uint8_t mask, uint8_t bits, uint8_t start_position = 0);
|
||||
void write_config_(uint8_t mask, uint8_t bits, uint8_t start_position = 0);
|
||||
void write_register_(uint8_t reg, uint8_t value);
|
||||
const uint8_t read_register_(uint8_t reg);
|
||||
const uint16_t read_register_16_(uint8_t reg);
|
||||
float calc_temperature_(const float& rtd_ratio);
|
||||
|
||||
Reference in New Issue
Block a user