7static const char *
const TAG =
"bh1900nux.sensor";
10static const uint8_t TEMPERATURE_REG = 0x00;
11static const uint8_t CONFIG_REG = 0x01;
12static const uint8_t TEMPERATURE_LOW_REG = 0x02;
13static const uint8_t TEMPERATURE_HIGH_REG = 0x03;
14static const uint8_t SOFT_RESET_REG = 0x04;
17static const uint8_t SOFT_RESET_PAYLOAD = 0x01;
19static const float SENSOR_RESOLUTION = 0.0625f;
32 uint8_t temperature_raw[2];
34 ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
40 int16_t raw_temperature_register_value =
encode_uint16(temperature_raw[0], temperature_raw[1]);
41 raw_temperature_register_value >>= 4;
42 float temperature_value = raw_temperature_register_value * SENSOR_RESOLUTION;
48 LOG_SENSOR(
"",
"BH1900NUX",
this);
50 LOG_UPDATE_INTERVAL(
this);
virtual void mark_failed()
Mark this component as failed.
void dump_config() override
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
void publish_state(float state)
Publish a new state to the front-end.
ErrorCode
Error codes returned by I2CBus and I2CDevice methods.
@ ERROR_OK
No error found during execution of method.
Providing packet encoding functions for exchanging data with a remote host.
constexpr uint16_t encode_uint16(uint8_t msb, uint8_t lsb)
Encode a 16-bit value given the most and least significant byte.