12static const char *
const TAG =
"xgzp68xx.sensor";
14static const uint8_t CMD_ADDRESS = 0x30;
15static const uint8_t SYSCONFIG_ADDRESS = 0xA5;
16static const uint8_t PCONFIG_ADDRESS = 0xA6;
17static const uint8_t READ_COMMAND = 0x0A;
20 switch (oversampling) {
45 uint8_t oldconfig = 0;
49 ESP_LOGD(TAG,
"oversampling to %s: oldconfig = 0x%x newconfig = 0x%x",
60 uint32_t pressure_raw = 0;
61 uint16_t temperature_raw = 0;
67 ESP_LOGE(TAG,
"Failed to read sensor data! Error code: %i", success);
75 ESP_LOGV(TAG,
"Got raw pressure=%" PRIu32
", raw temperature=%u", pressure_raw, temperature_raw);
76 ESP_LOGV(TAG,
"K value is %u", this->
k_value_);
79 float pressure_in_pa = (float) (((int32_t) pressure_raw << 8) >> 8);
80 pressure_in_pa /= (float) (this->
k_value_);
82 float temperature = ((float) (int16_t) temperature_raw) / 256.0f;
84 if (this->pressure_sensor_ !=
nullptr)
85 this->pressure_sensor_->publish_state(pressure_in_pa);
87 if (this->temperature_sensor_ !=
nullptr)
88 this->temperature_sensor_->publish_state(
temperature);
93 uint8_t config1 = 0, config2 = 0;
104 ESP_LOGD(TAG,
"sys_config 0x%x, p_config 0x%x", config1, config2);
108 ESP_LOGCONFIG(TAG,
"XGZP68xx:");
109 LOG_SENSOR(
" ",
"Temperature: ", this->temperature_sensor_);
110 LOG_SENSOR(
" ",
"Pressure: ", this->pressure_sensor_);
111 if (this->pressure_sensor_ !=
nullptr) {
114 LOG_I2C_DEVICE(
this);
116 ESP_LOGE(TAG,
" Connection failed");
118 LOG_UPDATE_INTERVAL(
this);
virtual void mark_failed()
Mark this component as failed.
void set_timeout(const std::string &name, uint32_t timeout, std::function< void()> &&f)
Set a timeout function with a unique 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
Providing packet encoding functions for exchanging data with a remote host.
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 uint16_t encode_uint16(uint8_t msb, uint8_t lsb)
Encode a 16-bit value given the most and least significant byte.