14 namespace bmp3xx_base {
16 static const char *
const TAG =
"bmp3xx.sensor";
18 static const LogString *chip_type_to_str(uint8_t chip_type) {
21 return LOG_STR(
"BMP 388");
23 return LOG_STR(
"BMP 390");
25 return LOG_STR(
"Unknown Chip Type");
29 static const LogString *oversampling_to_str(
Oversampling oversampling) {
30 switch (oversampling) {
32 return LOG_STR(
"None");
40 return LOG_STR(
"16x");
42 return LOG_STR(
"32x");
48 static const LogString *iir_filter_to_str(
IIRFilter filter) {
51 return LOG_STR(
"OFF");
59 return LOG_STR(
"16x");
61 return LOG_STR(
"32x");
63 return LOG_STR(
"64x");
65 return LOG_STR(
"128x");
72 this->error_code_ =
NONE;
73 ESP_LOGCONFIG(TAG,
"Setting up BMP3XX...");
76 ESP_LOGE(TAG,
"Failed to reset BMP3XX...");
82 ESP_LOGE(TAG,
"Can't read chip id");
87 ESP_LOGCONFIG(TAG,
"Chip %s Id 0x%X", LOG_STR_ARG(chip_type_to_str(this->
chip_id_.reg)), this->chip_id_.reg);
90 ESP_LOGE(TAG,
"Unknown chip id - is this really a BMP388 or BMP390?");
99 ESP_LOGE(TAG,
"Can't read calibration data");
105 (float) compensation_params_.param_T1 / powf(2.0f, -8.0f);
122 ESP_LOGE(TAG,
"Failed to set IIR filter");
143 ESP_LOGE(TAG,
"Failed to set oversampling register");
151 ESP_LOGCONFIG(TAG,
"BMP3XX:");
152 ESP_LOGCONFIG(TAG,
" Type: %s (0x%X)", LOG_STR_ARG(chip_type_to_str(this->
chip_id_.reg)), this->chip_id_.reg);
153 switch (this->error_code_) {
157 ESP_LOGE(TAG,
"Communication with BMP3XX failed!");
162 "BMP3XX has wrong chip ID (reported id: 0x%X) - please check if you are really using a BMP 388 or BMP 390",
166 ESP_LOGE(TAG,
"BMP3XX failed to reset");
169 ESP_LOGE(TAG,
"BMP3XX error code %d", (
int) this->error_code_);
172 ESP_LOGCONFIG(TAG,
" IIR Filter: %s", LOG_STR_ARG(iir_filter_to_str(this->
iir_filter_)));
173 LOG_UPDATE_INTERVAL(
this);
189 ESP_LOGV(TAG,
"Sending conversion request...");
190 float meas_time = 1.0f;
196 ESP_LOGE(TAG,
"Failed start forced mode");
201 const uint32_t meas_timeout = uint32_t(ceilf(meas_time));
202 ESP_LOGVV(TAG,
"measurement time %" PRIu32, meas_timeout);
208 ESP_LOGW(TAG,
"Failed to read pressure and temperature - skipping update");
212 ESP_LOGD(TAG,
"Got temperature=%.1f°C pressure=%.1fhPa", temperature, pressure);
215 ESP_LOGW(TAG,
"Failed to read temperature - skipping update");
219 ESP_LOGD(TAG,
"Got temperature=%.1f°C", temperature);
237 return event_.bit.por_detected;
254 osr_.bit.osr_p = oversampling;
260 osr_.bit.osr_t = oversampling;
279 ESP_LOGE(TAG,
"Failed to read temperature");
283 int32_t adc_temp = (int32_t) data[2] << 16 | (int32_t) data[1] << 8 | (int32_t) data[0];
299 ESP_LOGD(TAG,
"BMP3XX Get measurement - data not ready skipping update");
306 ESP_LOGE(TAG,
"Failed to read measurements");
310 int32_t adc_pres = (int32_t) data[2] << 16 | (int32_t) data[1] << 8 | (int32_t) data[0];
311 int32_t adc_temp = (int32_t) data[5] << 16 | (int32_t) data[4] << 8 | (int32_t) data[3];
331 osr_.reg = temperature_oversampling << 3 | pressure_oversampling;
339 ESP_LOGD(TAG,
"Not ready - sensor is in sleep mode");
345 ESP_LOGE(TAG,
"Failed to read status register");
349 ESP_LOGVV(TAG,
"data ready status %d", status);
380 partial_data1 = uncomp_press * uncomp_press;
382 partial_data3 = partial_data1 * partial_data2;
383 float partial_data4 =
385 return partial_out1 + partial_out2 + partial_data4;
Oversampling temperature_oversampling_
void dump_config() override
const float DATA
For components that import data from directly connected sensors like DHT.
float get_setup_priority() const override
union esphome::bmp3xx_base::BMP3XXComponent::@31 config_
void status_set_warning(const char *message="unspecified")
Oversampling
Oversampling bit fields in the control and measurement register.
bool set_mode(OperationMode mode)
Set the barometer mode.
void set_timeout(const std::string &name, uint32_t timeout, std::function< void()> &&f)
Set a timeout function with a unique name.
union esphome::bmp3xx_base::BMP3XXComponent::@27 int_status_
virtual bool read_bytes(uint8_t a_register, uint8_t *data, size_t len)=0
union esphome::bmp3xx_base::BMP3XXComponent::@25 chip_id_
bool data_ready()
Checks if a measurement is ready.
bool start_forced_conversion()
Start a one shot measurement in FORCED_MODE.
float bmp388_compensate_temperature_(float uncomp_temp)
bool set_iir_filter(IIRFilter iir_filter)
Set the IIR filter setting: OFF, 2, 3, 8, 16, 32.
bool get_measurements(float &temperature, float &pressure)
Get a temperature and pressure measurement.
sensor::Sensor * pressure_sensor_
bool get_pressure(float &pressure)
Get a pressure measurement.
Oversampling pressure_oversampling_
bool stop_conversion()
Stop the conversion and return to SLEEP_MODE.
void status_clear_warning()
void publish_state(float state)
Publish a new state to the front-end.
bool set_temperature_oversampling(Oversampling temperature_oversampling)
Set the temperature oversampling: OFF, X1, X2, X4, X8, X16, X32.
bool get_temperature(float &temperature)
Get a temperature measurement.
enum esphome::bmp3xx_base::BMP3XXComponent::ErrorCode NONE
uint8_t reset()
Soft reset the sensor.
union esphome::bmp3xx_base::BMP3XXComponent::@28 pwr_ctrl_
union esphome::bmp3xx_base::BMP3XXComponent::@29 osr_
IIRFilter
Infinite Impulse Response (IIR) filter bit field in the configuration register.
bool set_pressure_oversampling(Oversampling pressure_oversampling)
Set the pressure oversampling: OFF, X1, X2, X4, X8, X16, X32.
virtual bool write_byte(uint8_t a_register, uint8_t data)=0
sensor::Sensor * temperature_sensor_
virtual void mark_failed()
Mark this component as failed.
uint8_t oversampling_to_time(Oversampling over_sampling)
Implementation of SPI Controller mode.
OperationMode
Device mode bitfield in the control and measurement register.
float bmp388_compensate_pressure_(float uncomp_press, float t_lin)
bool set_oversampling_register(Oversampling pressure_oversampling, Oversampling temperature_oversampling)
Set the BMP388 oversampling register.
struct esphome::bmp3xx_base::BMP3XXComponent::FloatParams compensation_float_params_
union esphome::bmp3xx_base::BMP3XXComponent::@26 event_
virtual bool read_byte(uint8_t a_register, uint8_t *data)=0
void IRAM_ATTR HOT delay(uint32_t ms)