9static const char *
const TAG =
"tem3200";
19 ESP_LOGCONFIG(TAG,
"Running setup");
22 uint16_t raw_temperature(0);
23 uint16_t raw_pressure(0);
27 ESP_LOGCONFIG(TAG, ESP_LOG_MSG_COMM_FAIL);
34 ESP_LOGE(TAG,
"Invalid RESERVED Device Status");
38 ESP_LOGE(TAG,
"FAULT condition in the SSC or sensing element");
42 ESP_LOGE(TAG,
"STALE data. Data has not been updated since last fetch");
49 ESP_LOGCONFIG(TAG,
"TEM3200:");
51 LOG_UPDATE_INTERVAL(
this);
59 uint8_t response[4] = {0x00, 0x00, 0x00, 0x00};
78 err = this->
read(response, 4);
91 raw_pressure = (((response[0] & 0x3f)) << 8 | response[1]);
94 raw_temperature = ((response[2] << 3) | (response[3] & 0xe0) >> 5);
100 const float temperature_bits_span = 2048;
101 const float temperature_max = 150;
102 const float temperature_min = -50;
103 const float temperature_span = temperature_max - temperature_min;
105 float temperature = (raw_temperature * temperature_span / temperature_bits_span) + temperature_min;
112 uint16_t raw_temperature(0);
113 uint16_t raw_pressure(0);
117 ESP_LOGW(TAG, ESP_LOG_MSG_COMM_FAIL);
124 ESP_LOGE(TAG,
"Failed: Device return RESERVED status");
128 ESP_LOGE(TAG,
"Failed: FAULT condition in the SSC or sensing element");
132 ESP_LOGE(TAG,
"Warning: STALE data. Data has not been updated since last fetch");
139 ESP_LOGD(TAG,
"Got raw pressure=%d, temperature=%.1f°C", raw_pressure,
temperature);
virtual void mark_failed()
Mark this component as failed.
void status_set_warning(const char *message="unspecified")
void status_clear_warning()
ErrorCode read(uint8_t *data, size_t len)
reads an array of bytes from the device using an I2CBus
void publish_state(float state)
Publish a new state to the front-end.
i2c::ErrorCode read_(uint8_t &status, uint16_t &raw_temperature, uint16_t &raw_pressure)
sensor::Sensor * raw_pressure_sensor_
sensor::Sensor * temperature_sensor_
float get_setup_priority() const override
void dump_config() override
ErrorCode
Error codes returned by I2CBus and I2CDevice methods.
@ ERROR_OK
No error found during execution of method.
const float DATA
For components that import data from directly connected sensors like DHT.
float convert_temperature(uint16_t raw_temperature)
Providing packet encoding functions for exchanging data with a remote host.
void IRAM_ATTR HOT delay(uint32_t ms)