10static constexpr uint32_t TEMPERATURE_TIMEOUT_ID = 0;
11static constexpr uint32_t PRESSURE_TIMEOUT_ID = 1;
13static const uint8_t MS5611_ADDRESS = 0x77;
14static const uint8_t MS5611_CMD_ADC_READ = 0x00;
15static const uint8_t MS5611_CMD_RESET = 0x1E;
16static const uint8_t MS5611_CMD_CONV_D1 = 0x40;
17static const uint8_t MS5611_CMD_CONV_D2 = 0x50;
18static const uint8_t MS5611_CMD_READ_PROM = 0xA2;
21 if (!this->
write_bytes(MS5611_CMD_RESET,
nullptr, 0)) {
26 for (uint8_t offset = 0; offset < 6; offset++) {
27 if (!this->
read_byte_16(MS5611_CMD_READ_PROM + (offset * 2), &this->
prom_[offset])) {
35 ESP_LOGCONFIG(TAG,
"MS5611:");
37 LOG_UPDATE_INTERVAL(
this);
43 if (!this->
write_bytes(MS5611_CMD_CONV_D2 + 0x08,
nullptr, 0)) {
52 if (!this->
read_bytes(MS5611_CMD_ADC_READ, bytes, 3)) {
59 if (!this->
write_bytes(MS5611_CMD_CONV_D1 + 0x08,
nullptr, 0)) {
68 if (!this->
read_bytes(MS5611_CMD_ADC_READ, bytes, 3)) {
83 const uint16_t c3 = uint16_t(this->
prom_[2]);
84 const uint16_t c4 = uint16_t(this->
prom_[3]);
85 const int32_t c5 = int32_t(this->
prom_[4]);
86 const uint16_t c6 = uint16_t(this->
prom_[5]);
88 const int32_t d2 = raw_temperature;
91 const int64_t dt = d2 - (c5 << 8);
92 int32_t temp = (2000 + ((dt * c6) >> 23));
94 int64_t off = (c2 << 16) + ((dt * c4) >> 7);
95 int64_t sens = (c1 << 15) + ((dt * c3) >> 8);
98 const int32_t t2 = (dt * dt) >> 31;
99 int32_t off2 = ((5 * (temp - 2000) * (temp - 2000)) >> 1);
100 int32_t sens2 = ((5 * (temp - 2000) * (temp - 2000)) >> 2);
102 off2 = (off2 + 7 * (temp + 1500) * (temp + 1500));
103 sens2 = sens2 + ((11 * (temp + 1500) * (temp + 1500)) >> 1);
113 const int32_t p = ((((d1 * sens) >> 21) - off) >> 15);
void mark_failed()
Mark this component as failed.
void status_set_warning()
void set_timeout(const char *name, uint32_t timeout, std::function< void()> &&f)
Set a timeout function with a const char* name.
void status_clear_warning()
bool read_byte_16(uint8_t a_register, uint16_t *data)
bool write_bytes(uint8_t a_register, const uint8_t *data, uint8_t len) const
bool read_bytes(uint8_t a_register, uint8_t *data, uint8_t len)
Compat APIs All methods below have been added for compatibility reasons.
void read_pressure_(uint32_t raw_temperature)
void dump_config() override
sensor::Sensor * temperature_sensor_
sensor::Sensor * pressure_sensor_
void calculate_values_(uint32_t raw_temperature, uint32_t raw_pressure)
void publish_state(float state)
Publish a new state to the front-end.
ESPHOME_LOG_TAG(TAG, "ms5611")
constexpr uint32_t encode_uint24(uint8_t byte1, uint8_t byte2, uint8_t byte3)
Encode a 24-bit value given three bytes in most to least significant byte order.