7static const char *
const TAG =
"bmp085.sensor";
9static const uint8_t BMP085_ADDRESS = 0x77;
10static const uint8_t BMP085_REGISTER_AC1_H = 0xAA;
11static const uint8_t BMP085_REGISTER_CONTROL = 0xF4;
12static const uint8_t BMP085_REGISTER_DATA_MSB = 0xF6;
13static const uint8_t BMP085_CONTROL_MODE_TEMPERATURE = 0x2E;
14static const uint8_t BMP085_CONTROL_MODE_PRESSURE_3 = 0xF4;
17 if (!this->
set_mode_(BMP085_CONTROL_MODE_TEMPERATURE))
24 if (!this->
read_bytes(BMP085_REGISTER_AC1_H, data, 22)) {
36 this->
calibration_.
b1 = ((data[12] & 0xFF) << 8) | (data[13] & 0xFF);
37 this->
calibration_.
b2 = ((data[14] & 0xFF) << 8) | (data[15] & 0xFF);
38 this->
calibration_.
mb = ((data[16] & 0xFF) << 8) | (data[17] & 0xFF);
39 this->
calibration_.
mc = ((data[18] & 0xFF) << 8) | (data[19] & 0xFF);
40 this->
calibration_.
md = ((data[20] & 0xFF) << 8) | (data[21] & 0xFF);
43 ESP_LOGCONFIG(TAG,
"BMP085:");
46 ESP_LOGE(TAG,
"Connection with BMP085 failed!");
48 LOG_UPDATE_INTERVAL(
this);
51 LOG_SENSOR(
" ",
"Pressure", this->
pressure_);
57 if (!this->
read_bytes(BMP085_REGISTER_DATA_MSB, buffer, 2)) {
62 int32_t ut = ((buffer[0] & 0xFF) << 8) | (buffer[1] & 0xFF);
64 ESP_LOGW(TAG,
"Invalid temperature!");
74 double a = c5 * (ut - c6);
75 float temp = a + (mc / (a + md));
78 ESP_LOGD(TAG,
"Got Temperature=%.1f °C", temp);
83 if (!this->
set_mode_(BMP085_CONTROL_MODE_PRESSURE_3)) {
92 if (!this->
read_bytes(BMP085_REGISTER_DATA_MSB, buffer, 3)) {
97 uint32_t value = (uint32_t(buffer[0]) << 16) | (uint32_t(buffer[1]) << 8) | uint32_t(buffer[2]);
98 if ((value >> 5) == 0) {
99 ESP_LOGW(TAG,
"Invalid pressure!");
106 double b1 = pow(160.0, 2.0) * pow(2.0, -30.0) * this->
calibration_.
b1;
109 double x2 = pow(160.0, 2.0) * pow(2.0, -25.0) * this->
calibration_.
b2;
110 double y0 = c4 * pow(2.0, 15.0);
113 double p0 = (3791.0 - 8.0) / 1600.0;
114 double p1 = 1.0 - 7357.0 * pow(2, -20);
115 double p2 = 3038.0 * 100.0 * pow(2, -36);
117 double p = value / 256.0;
119 double x = (x2 * s * s) + (x1 * s) + x0;
120 double y = (y2 * s * s) + (y1 * s) + y0;
121 double z = (p -
x) /
y;
124 ESP_LOGD(TAG,
"Got Pressure=%.1f hPa",
pressure);
131 ESP_LOGV(TAG,
"Setting mode to 0x%02X",
mode);
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.
CalibrationData calibration_
void setup() override
Setup the sensor and test for a connection.
void read_pressure_()
Internal method to read the pressure from the component after it has been scheduled.
void update() override
Schedule temperature+pressure readings.
float get_setup_priority() const override
void dump_config() override
sensor::Sensor * pressure_
void read_temperature_()
Internal method to read the temperature from the component after it has been scheduled.
bool set_mode_(uint8_t mode)
sensor::Sensor * temperature_
bool write_byte(uint8_t a_register, uint8_t data, bool stop=true)
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 publish_state(float state)
Publish a new state to the front-end.
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.