8 static const char *
const TAG =
"ina260";
28 static const uint8_t INA260_REGISTER_CONFIG = 0x00;
29 static const uint8_t INA260_REGISTER_CURRENT = 0x01;
30 static const uint8_t INA260_REGISTER_BUS_VOLTAGE = 0x02;
31 static const uint8_t INA260_REGISTER_POWER = 0x03;
32 static const uint8_t INA260_REGISTER_MASK_ENABLE = 0x06;
33 static const uint8_t INA260_REGISTER_ALERT_LIMIT = 0x07;
34 static const uint8_t INA260_REGISTER_MANUFACTURE_ID = 0xFE;
35 static const uint8_t INA260_REGISTER_DEVICE_ID = 0xFF;
38 ESP_LOGCONFIG(TAG,
"Setting up INA260...");
58 if (!this->
write_byte_16(INA260_REGISTER_CONFIG, (uint16_t) 0b0000001100000111)) {
66 ESP_LOGCONFIG(TAG,
"INA260:");
68 LOG_UPDATE_INTERVAL(
this);
71 ESP_LOGCONFIG(TAG,
" Device ID: 0x%x", this->
device_id_);
77 switch (this->error_code_) {
79 ESP_LOGE(TAG,
"Connected device does not match a known INA260 sensor");
82 ESP_LOGE(TAG,
"Device reset failed - Is the device connected?");
85 ESP_LOGE(TAG,
"Failed to update device configuration");
95 uint16_t raw_bus_voltage;
96 if (!this->
read_byte_16(INA260_REGISTER_BUS_VOLTAGE, &raw_bus_voltage)) {
100 float bus_voltage_v = int16_t(raw_bus_voltage) * 0.00125f;
105 uint16_t raw_current;
106 if (!this->
read_byte_16(INA260_REGISTER_CURRENT, &raw_current)) {
110 float current_a = int16_t(raw_current) * 0.00125f;
116 if (!this->
read_byte_16(INA260_REGISTER_POWER, &raw_power)) {
120 float power_w = ((int16_t(raw_power) * 10.0f) / 1000.0f);
bool read_byte_16(uint8_t a_register, uint16_t *data)
void status_set_warning(const char *message="unspecified")
enum esphome::ina260::INA260Component::ErrorCode NONE
sensor::Sensor * bus_voltage_sensor_
void dump_config() override
sensor::Sensor * power_sensor_
void status_clear_warning()
void publish_state(float state)
Publish a new state to the front-end.
sensor::Sensor * current_sensor_
virtual void mark_failed()
Mark this component as failed.
Implementation of SPI Controller mode.
bool write_byte_16(uint8_t a_register, uint16_t data)
void IRAM_ATTR HOT delay(uint32_t ms)