13static constexpr uint32_t MEASUREMENT_TIMEOUT_ID = 0;
15static const uint8_t CMD_ADDRESS = 0x30;
16static const uint8_t SYSCONFIG_ADDRESS = 0xA5;
17static const uint8_t PCONFIG_ADDRESS = 0xA6;
18static const uint8_t READ_COMMAND = 0x0A;
21 switch (oversampling) {
46 uint8_t oldconfig = 0;
50 ESP_LOGD(TAG,
"oversampling to %s: oldconfig = 0x%x newconfig = 0x%x",
59 this->
set_timeout(MEASUREMENT_TIMEOUT_ID, 20, [
this]() {
62 uint16_t temperature_raw = 0;
68 ESP_LOGE(TAG,
"Failed to read sensor data! Error code: %i", success);
76 ESP_LOGV(TAG,
"Got raw pressure=%" PRIu32
", raw temperature=%u, K value=%u", pressure_raw, temperature_raw,
81 float temperature = ((float) (int16_t) temperature_raw) / 256.0f;
83 if (this->pressure_sensor_ !=
nullptr)
84 this->pressure_sensor_->publish_state(pressure_in_pa);
86 if (this->temperature_sensor_ !=
nullptr)
87 this->temperature_sensor_->publish_state(
temperature);
92 uint8_t config1 = 0, config2 = 0;
103 ESP_LOGD(TAG,
"sys_config 0x%x, p_config 0x%x", config1, config2);
107 ESP_LOGCONFIG(TAG,
"XGZP68xx:");
108 LOG_SENSOR(
" ",
"Temperature: ", this->temperature_sensor_);
109 LOG_SENSOR(
" ",
"Pressure: ", this->pressure_sensor_);
110 if (this->pressure_sensor_ !=
nullptr) {
113 LOG_I2C_DEVICE(
this);
114 LOG_UPDATE_INTERVAL(
this);
void mark_failed()
Mark this component as failed.
void set_timeout(const char *name, uint32_t timeout, std::function< void()> &&f)
Set a timeout function with a const char* name.
ErrorCode write_register(uint8_t a_register, const uint8_t *data, size_t len) const
writes an array of bytes to a specific register in the I²C device
ErrorCode read_register(uint8_t a_register, uint8_t *data, size_t len)
reads an array of bytes from a specific register in the I²C device
XGZP68XXOversampling last_pressure_oversampling_
void dump_config() override
XGZP68XXOversampling pressure_oversampling_
@ ERROR_OK
No error found during execution of method.
XGZP68XXOversampling
Enum listing all oversampling options for the XGZP68XX.
@ XGZP68XX_OVERSAMPLING_32768X
@ XGZP68XX_OVERSAMPLING_1024X
@ XGZP68XX_OVERSAMPLING_256X
@ XGZP68XX_OVERSAMPLING_8192X
@ XGZP68XX_OVERSAMPLING_2048X
@ XGZP68XX_OVERSAMPLING_4096X
@ XGZP68XX_OVERSAMPLING_16384X
@ XGZP68XX_OVERSAMPLING_512X
ESPHOME_LOG_TAG(TAG, "xgzp68xx.sensor")
constexpr uint32_t encode_uint24(uint8_t byte1, uint8_t byte2, uint8_t byte3)
Encode a 24-bit value given three bytes in most to least significant byte order.
constexpr int32_t sign_extend(uint32_t value)
Sign-extend the low BITS bits of value, e.g. sign_extend<24>(0xFFFFFE) == -2. Higher bits are ignored...
constexpr uint16_t encode_uint16(uint8_t msb, uint8_t lsb)
Encode a 16-bit value given the most and least significant byte.