9 static const char *
const TAG =
"sdp3x.sensor";
10 static const uint16_t SDP3X_SOFT_RESET = 0x0006;
11 static const uint16_t SDP3X_READ_ID1 = 0x367C;
12 static const uint16_t SDP3X_READ_ID2 = 0xE102;
13 static const uint16_t SDP3X_START_DP_AVG = 0x3615;
14 static const uint16_t SDP3X_START_MASS_FLOW_AVG = 0x3603;
15 static const uint16_t SDP3X_STOP_MEAS = 0x3FF9;
20 ESP_LOGD(TAG,
"Setting up SDP3X...");
23 ESP_LOGW(TAG,
"Stop SDP3X failed!");
27 ESP_LOGW(TAG,
"Soft Reset SDP3X failed!");
32 ESP_LOGE(TAG,
"Read ID1 SDP3X failed!");
37 ESP_LOGE(TAG,
"Read ID2 SDP3X failed!");
44 ESP_LOGE(TAG,
"Read ID SDP3X failed!");
52 if (data[1] >> 8 == 0x02) {
53 switch (data[1] & 0xFF) {
55 ESP_LOGCONFIG(TAG,
"Sensor is SDP800-500Pa");
58 ESP_LOGCONFIG(TAG,
"Sensor is SDP810-500Pa");
61 ESP_LOGCONFIG(TAG,
"Sensor is SDP801-500Pa");
64 ESP_LOGCONFIG(TAG,
"Sensor is SDP811-500Pa");
67 ESP_LOGCONFIG(TAG,
"Sensor is SDP800-125Pa");
70 ESP_LOGCONFIG(TAG,
"Sensor is SDP810-125Pa");
73 }
else if (data[1] >> 8 == 0x01) {
74 if ((data[1] & 0xFF) == 0x01) {
75 ESP_LOGCONFIG(TAG,
"Sensor is SDP31-500Pa");
76 }
else if ((data[1] & 0xFF) == 0x02) {
77 ESP_LOGCONFIG(TAG,
"Sensor is SDP32-125Pa");
82 ESP_LOGE(TAG,
"Start Measurements SDP3X failed!");
86 ESP_LOGCONFIG(TAG,
"SDP3X started!");
90 LOG_SENSOR(
" ",
"SDP3X",
this);
93 ESP_LOGE(TAG,
" Connection with SDP3X failed!");
95 LOG_UPDATE_INTERVAL(
this);
101 ESP_LOGW(TAG,
"Couldn't read SDP3X data!");
106 int16_t pressure_raw = data[0];
107 int16_t temperature_raw = data[1];
108 int16_t scale_factor_raw = data[2];
110 float pressure = pressure_raw / (scale_factor_raw * 100.0f);
111 ESP_LOGV(TAG,
"Got raw pressure=%d, raw scale factor =%d, raw temperature=%d ", pressure_raw, scale_factor_raw,
113 ESP_LOGD(TAG,
"Got Pressure=%.3f hPa", pressure);
const float DATA
For components that import data from directly connected sensors like DHT.
void status_set_warning(const char *message="unspecified")
bool write_command(T i2c_register)
Write a command to the i2c device.
void set_timeout(const std::string &name, uint32_t timeout, std::function< void()> &&f)
Set a timeout function with a unique name.
bool read_data(uint16_t *data, uint8_t len)
Read data words from i2c device.
MeasurementMode measurement_mode_
void setup() override
Setup the sensor and test for a connection.
void status_clear_warning()
void publish_state(float state)
Publish a new state to the front-end.
float get_setup_priority() const override
void update() override
Schedule temperature+pressure readings.
virtual void mark_failed()
Mark this component as failed.
void dump_config() override
Implementation of SPI Controller mode.
void read_pressure_()
Internal method to read the pressure from the component after it has been scheduled.