9 static const char *
const TAG =
"npi19";
11 static const uint8_t READ_COMMAND = 0xAC;
14 ESP_LOGCONFIG(TAG,
"Setting up NPI19...");
16 uint16_t raw_temperature(0);
17 uint16_t raw_pressure(0);
20 ESP_LOGCONFIG(TAG,
" I2C Communication Failed...");
25 ESP_LOGCONFIG(TAG,
" Success...");
29 ESP_LOGCONFIG(TAG,
"NPI19:");
31 LOG_UPDATE_INTERVAL(
this);
46 uint8_t response[4] = {0x00, 0x00, 0x00, 0x00};
54 raw_pressure = ((response[0] & 0x3F) << 8) | response[1];
57 raw_temperature = (response[2] << 3) | ((response[3] & 0xE0) >> 5);
76 const float temperature_bits_span = 2048;
77 const float temperature_max = 150;
78 const float temperature_min = -50;
79 const float temperature_span = temperature_max - temperature_min;
81 float temperature = (raw_temperature * temperature_span / temperature_bits_span) + temperature_min;
87 uint16_t raw_temperature(0);
88 uint16_t raw_pressure(0);
93 ESP_LOGW(TAG,
"I2C Communication Failed");
100 ESP_LOGD(TAG,
"Got raw pressure=%d, temperature=%.1f°C", raw_pressure, temperature);
const float DATA
For components that import data from directly connected sensors like DHT.
void status_set_warning(const char *message="unspecified")
ErrorCode read(uint8_t *data, size_t len)
reads an array of bytes from the device using an I2CBus
i2c::ErrorCode read_(uint16_t &raw_temperature, uint16_t &raw_pressure)
void dump_config() override
sensor::Sensor * temperature_sensor_
ErrorCode write(const uint8_t *data, size_t len, bool stop=true)
writes an array of bytes to a device using an I2CBus
No error found during execution of method.
void status_clear_warning()
void publish_state(float state)
Publish a new state to the front-end.
float convert_temperature(uint16_t raw_temperature)
sensor::Sensor * raw_pressure_sensor_
virtual void mark_failed()
Mark this component as failed.
Implementation of SPI Controller mode.
ErrorCode
Error codes returned by I2CBus and I2CDevice methods.
float get_setup_priority() const override