8static const char *
const TAG =
"ina260";
28static const uint8_t INA260_REGISTER_CONFIG = 0x00;
29static const uint8_t INA260_REGISTER_CURRENT = 0x01;
30static const uint8_t INA260_REGISTER_BUS_VOLTAGE = 0x02;
31static const uint8_t INA260_REGISTER_POWER = 0x03;
32static const uint8_t INA260_REGISTER_MASK_ENABLE = 0x06;
33static const uint8_t INA260_REGISTER_ALERT_LIMIT = 0x07;
34static const uint8_t INA260_REGISTER_MANUFACTURE_ID = 0xFE;
35static const uint8_t INA260_REGISTER_DEVICE_ID = 0xFF;
56 if (!this->
write_byte_16(INA260_REGISTER_CONFIG, (uint16_t) 0b0000001100000111)) {
64 ESP_LOGCONFIG(TAG,
"INA260:");
66 LOG_UPDATE_INTERVAL(
this);
69 ESP_LOGCONFIG(TAG,
" Device ID: 0x%x", this->
device_id_);
75 switch (this->error_code_) {
77 ESP_LOGE(TAG,
"Connected device does not match a known INA260 sensor");
80 ESP_LOGE(TAG,
"Device reset failed - Is the device connected?");
83 ESP_LOGE(TAG,
"Failed to update device configuration");
93 uint16_t raw_bus_voltage;
94 if (!this->
read_byte_16(INA260_REGISTER_BUS_VOLTAGE, &raw_bus_voltage)) {
98 float bus_voltage_v = int16_t(raw_bus_voltage) * 0.00125f;
103 uint16_t raw_current;
104 if (!this->
read_byte_16(INA260_REGISTER_CURRENT, &raw_current)) {
108 float current_a = int16_t(raw_current) * 0.00125f;
114 if (!this->
read_byte_16(INA260_REGISTER_POWER, &raw_power)) {
118 float power_w = ((int16_t(raw_power) * 10.0f) / 1000.0f);
virtual void mark_failed()
Mark this component as failed.
void status_set_warning(const char *message=nullptr)
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)
enum esphome::ina260::INA260Component::ErrorCode NONE
sensor::Sensor * bus_voltage_sensor_
sensor::Sensor * current_sensor_
sensor::Sensor * power_sensor_
void dump_config() override
@ FAILED_TO_UPDATE_CONFIGURATION
void publish_state(float state)
Publish a new state to the front-end.
Providing packet encoding functions for exchanging data with a remote host.
void IRAM_ATTR HOT delay(uint32_t ms)