27static const uint8_t INA260_REGISTER_CONFIG = 0x00;
28static const uint8_t INA260_REGISTER_CURRENT = 0x01;
29static const uint8_t INA260_REGISTER_BUS_VOLTAGE = 0x02;
30static const uint8_t INA260_REGISTER_POWER = 0x03;
31static const uint8_t INA260_REGISTER_MASK_ENABLE = 0x06;
32static const uint8_t INA260_REGISTER_ALERT_LIMIT = 0x07;
33static const uint8_t INA260_REGISTER_MANUFACTURE_ID = 0xFE;
34static const uint8_t INA260_REGISTER_DEVICE_ID = 0xFF;
39 this->
mark_failed(LOG_STR(
"Device reset failed - Is the device connected?"));
49 this->
mark_failed(LOG_STR(
"Connected device does not match a known INA260 sensor"));
53 if (!this->
write_byte_16(INA260_REGISTER_CONFIG, (uint16_t) 0b0000001100000111)) {
54 this->
mark_failed(LOG_STR(
"Failed to update device configuration"));
62 " Manufacture ID: 0x%x\n"
66 LOG_UPDATE_INTERVAL(
this);
74 uint16_t raw_bus_voltage;
75 if (!this->
read_byte_16(INA260_REGISTER_BUS_VOLTAGE, &raw_bus_voltage)) {
79 float bus_voltage_v = int16_t(raw_bus_voltage) * 0.00125f;
85 if (!this->
read_byte_16(INA260_REGISTER_CURRENT, &raw_current)) {
89 float current_a = int16_t(raw_current) * 0.00125f;
95 if (!this->
read_byte_16(INA260_REGISTER_POWER, &raw_power)) {
99 float power_w = ((int16_t(raw_power) * 10.0f) / 1000.0f);
void mark_failed()
Mark this component as failed.
void status_set_warning()
void status_clear_warning()
bool read_byte_16(uint8_t a_register, uint16_t *data)
bool write_byte_16(uint8_t a_register, uint16_t data) const
sensor::Sensor * bus_voltage_sensor_
sensor::Sensor * current_sensor_
sensor::Sensor * power_sensor_
void dump_config() override
void publish_state(float state)
Publish a new state to the front-end.
ESPHOME_LOG_TAG(TAG, "ina260")
void HOT delay(uint32_t ms)