12 static const char *
const TAG =
"xgzp68xx.sensor";
14 static const uint8_t CMD_ADDRESS = 0x30;
15 static const uint8_t SYSCONFIG_ADDRESS = 0xA5;
16 static const uint8_t PCONFIG_ADDRESS = 0xA6;
17 static const uint8_t READ_COMMAND = 0x0A;
26 uint32_t pressure_raw;
27 uint16_t temperature_raw;
34 ESP_LOGE(TAG,
"Failed to read sensor data! Error code: %i", success);
42 ESP_LOGV(TAG,
"Got raw pressure=%" PRIu32
", raw temperature=%u", pressure_raw, temperature_raw);
43 ESP_LOGV(TAG,
"K value is %u", this->
k_value_);
47 if (pressure_raw > pow(2, 23)) {
49 pressure_in_pa = (pressure_raw - pow(2, 24)) / (
float) (this->
k_value_);
52 pressure_in_pa = pressure_raw / (float) (this->
k_value_);
55 if (temperature_raw > pow(2, 15)) {
57 temperature = (float) (temperature_raw - pow(2, 16)) / 256.0f;
60 temperature = (float) temperature_raw / 256.0f;
63 if (this->pressure_sensor_ !=
nullptr)
64 this->pressure_sensor_->publish_state(pressure_in_pa);
66 if (this->temperature_sensor_ !=
nullptr)
67 this->temperature_sensor_->publish_state(temperature);
72 ESP_LOGD(TAG,
"Setting up XGZP68xx...");
77 ESP_LOGCONFIG(TAG,
"Gain value is %d", (config >> 3) & 0b111);
78 ESP_LOGCONFIG(TAG,
"XGZP68xx started!");
82 ESP_LOGCONFIG(TAG,
"XGZP68xx");
83 LOG_SENSOR(
" ",
"Temperature: ", this->temperature_sensor_);
84 LOG_SENSOR(
" ",
"Pressure: ", this->pressure_sensor_);
87 ESP_LOGE(TAG,
" Connection with XGZP68xx failed!");
89 LOG_UPDATE_INTERVAL(
this);
ErrorCode read_register(uint8_t a_register, uint8_t *data, size_t len, bool stop=true)
reads an array of bytes from a specific register in the I²C device
void set_timeout(const std::string &name, uint32_t timeout, std::function< void()> &&f)
Set a timeout function with a unique name.
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.
Implementation of SPI Controller mode.
ErrorCode write_register(uint8_t a_register, const uint8_t *data, size_t len, bool stop=true)
writes an array of bytes to a specific register in the I²C device
void dump_config() override