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"));
59void INA260Component::dump_config() {
62 " Manufacture ID: 0x%x\n"
66 LOG_UPDATE_INTERVAL(
this);
67 LOG_SENSOR(
" ",
"Bus Voltage", this->bus_voltage_sensor_);
68 LOG_SENSOR(
" ",
"Current", this->current_sensor_);
69 LOG_SENSOR(
" ",
"Power", this->power_sensor_);
72void INA260Component::update() {
73 if (this->bus_voltage_sensor_ !=
nullptr) {
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;
80 this->bus_voltage_sensor_->publish_state(bus_voltage_v);
83 if (this->current_sensor_ !=
nullptr) {
85 if (!this->
read_byte_16(INA260_REGISTER_CURRENT, &raw_current)) {
89 float current_a = int16_t(raw_current) * 0.00125f;
90 this->current_sensor_->publish_state(current_a);
93 if (this->power_sensor_ !=
nullptr) {
95 if (!this->
read_byte_16(INA260_REGISTER_POWER, &raw_power)) {
99 float power_w = ((int16_t(raw_power) * 10.0f) / 1000.0f);
100 this->power_sensor_->publish_state(power_w);