10 static const char *
const TAG =
"xgzp68xx.sensor";
12 static const uint8_t CMD_ADDRESS = 0x30;
13 static const uint8_t SYSCONFIG_ADDRESS = 0xA5;
14 static const uint8_t PCONFIG_ADDRESS = 0xA6;
15 static const uint8_t READ_COMMAND = 0x0A;
24 uint32_t pressure_raw;
25 uint16_t temperature_raw;
32 ESP_LOGE(TAG,
"Failed to read sensor data! Error code: %i", success);
40 ESP_LOGV(TAG,
"Got raw pressure=%d, raw temperature=%d ", pressure_raw, temperature_raw);
41 ESP_LOGV(TAG,
"K value is %d ", this->
k_value_);
45 if (pressure_raw > pow(2, 23)) {
47 pressure_in_pa = (pressure_raw - pow(2, 24)) / (
float) (this->
k_value_);
50 pressure_in_pa = pressure_raw / (float) (this->
k_value_);
53 if (temperature_raw > pow(2, 15)) {
55 temperature = (float) (temperature_raw - pow(2, 16)) / 256.0f;
58 temperature = (float) temperature_raw / 256.0f;
61 if (this->pressure_sensor_ !=
nullptr)
62 this->pressure_sensor_->publish_state(pressure_in_pa);
64 if (this->temperature_sensor_ !=
nullptr)
65 this->temperature_sensor_->publish_state(temperature);
70 ESP_LOGD(TAG,
"Setting up XGZP68xx...");
75 ESP_LOGCONFIG(TAG,
"Gain value is %d", (config >> 3) & 0b111);
76 ESP_LOGCONFIG(TAG,
"XGZP68xx started!");
80 ESP_LOGCONFIG(TAG,
"XGZP68xx");
81 LOG_SENSOR(
" ",
"Temperature: ", this->temperature_sensor_);
82 LOG_SENSOR(
" ",
"Pressure: ", this->pressure_sensor_);
85 ESP_LOGE(TAG,
" Connection with XGZP68xx failed!");
87 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.
This is a workaround until we can figure out a way to get the tflite-micro idf component code availab...
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