14static constexpr uint32_t MEASUREMENT_TIMEOUT_ID = 0;
16static const uint8_t CMD_ADDRESS = 0x30;
17static const uint8_t SYSCONFIG_ADDRESS = 0xA5;
18static const uint8_t PCONFIG_ADDRESS = 0xA6;
19static const uint8_t READ_COMMAND = 0x0A;
22PROGMEM_STRING_TABLE(OversamplingStrings,
"1024x",
"2048x",
"4096x",
"8192x",
"256x",
"512x",
"16384x",
"32768x",
26 return OversamplingStrings::get_log_str(
static_cast<uint8_t
>(
value), OversamplingStrings::LAST_INDEX);
32 uint8_t oldconfig = 0;
36 ESP_LOGD(TAG,
"oversampling to %s: oldconfig = 0x%x newconfig = 0x%x",
45 this->
set_timeout(MEASUREMENT_TIMEOUT_ID, 20, [
this]() {
48 uint16_t temperature_raw = 0;
54 ESP_LOGE(TAG,
"Failed to read sensor data! Error code: %i", success);
62 ESP_LOGV(TAG,
"Got raw pressure=%" PRIu32
", raw temperature=%u, K value=%u", pressure_raw, temperature_raw,
67 float temperature = ((float) (int16_t) temperature_raw) / 256.0f;
69 PUBLISH_STATE(this->pressure_sensor_, pressure_in_pa);
71 PUBLISH_STATE(this->temperature_sensor_,
temperature);
76 uint8_t config1 = 0, config2 = 0;
87 ESP_LOGD(TAG,
"sys_config 0x%x, p_config 0x%x", config1, config2);
91 ESP_LOGCONFIG(TAG,
"XGZP68xx:");
92 LOG_SENSOR(
" ",
"Temperature: ", this->temperature_sensor_);
93 LOG_SENSOR(
" ",
"Pressure: ", this->pressure_sensor_);
94 if (this->pressure_sensor_ !=
nullptr) {
98 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.
PROGMEM_STRING_TABLE(OversamplingStrings, "1024x", "2048x", "4096x", "8192x", "256x", "512x", "16384x", "32768x", "UNKNOWN")
ESPHOME_LOG_TAG(TAG, "xgzp6899dc.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.