14namespace bmp3xx_base {
16static const char *
const TAG =
"bmp3xx.sensor";
18static 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");
29static 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");
48static 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;
75 ESP_LOGE(TAG,
"Failed to reset");
81 ESP_LOGE(TAG,
"Can't read chip id");
86 ESP_LOGCONFIG(TAG,
"Chip %s Id 0x%X", LOG_STR_ARG(chip_type_to_str(this->
chip_id_.reg)), this->chip_id_.reg);
89 ESP_LOGE(TAG,
"Unknown chip id - is this really a BMP388 or BMP390?");
98 ESP_LOGE(TAG,
"Can't read calibration data");
104 (float) compensation_params_.param_T1 / powf(2.0f, -8.0f);
121 ESP_LOGE(TAG,
"Failed to set IIR filter");
142 ESP_LOGE(TAG,
"Failed to set oversampling register");
153 LOG_STR_ARG(chip_type_to_str(this->
chip_id_.reg)), this->chip_id_.reg);
154 switch (this->error_code_) {
158 ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
161 ESP_LOGE(TAG,
"Wrong chip ID (reported id: 0x%X) - please check if you are really using a BMP 388 or BMP 390",
165 ESP_LOGE(TAG,
"Failed to reset");
168 ESP_LOGE(TAG,
"Error code %d", (
int) this->error_code_);
171 ESP_LOGCONFIG(TAG,
" IIR Filter: %s", LOG_STR_ARG(iir_filter_to_str(this->
iir_filter_)));
172 LOG_UPDATE_INTERVAL(
this);
188 ESP_LOGV(TAG,
"Sending conversion request");
189 float meas_time = 1.0f;
195 ESP_LOGE(TAG,
"Failed start forced mode");
200 const uint32_t meas_timeout = uint32_t(ceilf(meas_time));
201 ESP_LOGVV(TAG,
"measurement time %" PRIu32, meas_timeout);
207 ESP_LOGW(TAG,
"Failed to read pressure and temperature - skipping update");
214 ESP_LOGW(TAG,
"Failed to read temperature - skipping update");
218 ESP_LOGD(TAG,
"Got temperature=%.1f°C",
temperature);
236 return event_.bit.por_detected;
253 osr_.bit.osr_p = oversampling;
259 osr_.bit.osr_t = oversampling;
278 ESP_LOGE(TAG,
"Failed to read temperature");
282 int32_t adc_temp = (int32_t) data[2] << 16 | (int32_t) data[1] << 8 | (int32_t) data[0];
298 ESP_LOGD(TAG,
"Get measurement - data not ready skipping update");
305 ESP_LOGE(TAG,
"Failed to read measurements");
309 int32_t adc_pres = (int32_t) data[2] << 16 | (int32_t) data[1] << 8 | (int32_t) data[0];
310 int32_t adc_temp = (int32_t) data[5] << 16 | (int32_t) data[4] << 8 | (int32_t) data[3];
330 osr_.reg = temperature_oversampling << 3 | pressure_oversampling;
338 ESP_LOGD(TAG,
"Not ready - sensor is in sleep mode");
344 ESP_LOGE(TAG,
"Failed to read status register");
348 ESP_LOGVV(TAG,
"data ready status %d",
status);
379 partial_data1 = uncomp_press * uncomp_press;
381 partial_data3 = partial_data1 * partial_data2;
382 float partial_data4 =
384 return partial_out1 + partial_out2 + partial_data4;
BedjetMode mode
BedJet operating mode.
virtual void mark_failed()
Mark this component as failed.
void status_set_warning(const char *message=nullptr)
void status_clear_warning()
void set_timeout(const std::string &name, uint32_t timeout, std::function< void()> &&f)
Set a timeout function with a unique name.
Oversampling pressure_oversampling_
union esphome::bmp3xx_base::BMP3XXComponent::@26 event_
struct esphome::bmp3xx_base::BMP3XXComponent::FloatParams compensation_float_params_
bool get_pressure(float &pressure)
Get a pressure measurement.
bool get_measurements(float &temperature, float &pressure)
Get a temperature and pressure measurement.
enum esphome::bmp3xx_base::BMP3XXComponent::ErrorCode NONE
bool start_forced_conversion()
Start a one shot measurement in FORCED_MODE.
sensor::Sensor * temperature_sensor_
union esphome::bmp3xx_base::BMP3XXComponent::@25 chip_id_
union esphome::bmp3xx_base::BMP3XXComponent::@31 config_
bool set_iir_filter(IIRFilter iir_filter)
Set the IIR filter setting: OFF, 2, 3, 8, 16, 32.
bool set_pressure_oversampling(Oversampling pressure_oversampling)
Set the pressure oversampling: OFF, X1, X2, X4, X8, X16, X32.
union esphome::bmp3xx_base::BMP3XXComponent::@28 pwr_ctrl_
@ ERROR_COMMUNICATION_FAILED
bool get_temperature(float &temperature)
Get a temperature measurement.
sensor::Sensor * pressure_sensor_
bool stop_conversion()
Stop the conversion and return to SLEEP_MODE.
float bmp388_compensate_temperature_(float uncomp_temp)
Oversampling temperature_oversampling_
float get_setup_priority() const override
virtual bool write_byte(uint8_t a_register, uint8_t data)=0
virtual bool read_bytes(uint8_t a_register, uint8_t *data, size_t len)=0
uint8_t reset()
Soft reset the sensor.
union esphome::bmp3xx_base::BMP3XXComponent::@27 int_status_
bool set_oversampling_register(Oversampling pressure_oversampling, Oversampling temperature_oversampling)
Set the BMP388 oversampling register.
bool data_ready()
Checks if a measurement is ready.
virtual bool read_byte(uint8_t a_register, uint8_t *data)=0
union esphome::bmp3xx_base::BMP3XXComponent::@29 osr_
bool set_mode(OperationMode mode)
Set the barometer mode.
float bmp388_compensate_pressure_(float uncomp_press, float t_lin)
void dump_config() override
bool set_temperature_oversampling(Oversampling temperature_oversampling)
Set the temperature oversampling: OFF, X1, X2, X4, X8, X16, X32.
void publish_state(float state)
Publish a new state to the front-end.
uint8_t oversampling_to_time(Oversampling over_sampling)
Oversampling
Oversampling bit fields in the control and measurement register.
OperationMode
Device mode bitfield in the control and measurement register.
IIRFilter
Infinite Impulse Response (IIR) filter bit field in the configuration register.
const float DATA
For components that import data from directly connected sensors like DHT.
Providing packet encoding functions for exchanging data with a remote host.
void IRAM_ATTR HOT delay(uint32_t ms)