ESPHome 2026.5.0b1
Loading...
Searching...
No Matches
ina2xx_base.cpp
Go to the documentation of this file.
1#include "ina2xx_base.h"
2#include "esphome/core/hal.h"
4#include "esphome/core/log.h"
5#include <cinttypes>
6#include <cmath>
7
9
10static const char *const TAG = "ina2xx";
11
12#define OKFAILED(b) ((b) ? "OK" : "FAILED")
13
14static const uint16_t ADC_TIMES[8] = {50, 84, 150, 280, 540, 1052, 2074, 4120};
15static const uint16_t ADC_SAMPLES[8] = {1, 4, 16, 64, 128, 256, 512, 1024};
16
17static const char *get_device_name(INAModel model) {
18 switch (model) {
20 return "INA228";
22 return "INA229";
24 return "INA238";
26 return "INA239";
28 return "INA237";
29 default:
30 return "UNKNOWN";
31 }
32};
33
34static bool check_model_and_device_match(INAModel model, uint16_t dev_id) {
35 switch (model) {
37 return dev_id == 0x228;
39 return dev_id == 0x229;
41 return dev_id == 0x238;
43 return dev_id == 0x239;
45 return dev_id == 0x237;
46 default:
47 return false;
48 }
49}
50
52 if (!this->reset_config_()) {
53 ESP_LOGE(TAG, "Reset failed, check connection");
54 this->mark_failed();
55 return;
56 }
57 delay(2);
58
59 if (!this->check_device_model_()) {
60 ESP_LOGE(TAG, "Device not supported or model selected improperly in yaml file");
61 this->mark_failed();
62 return;
63 }
64 delay(1);
65
67 delay(1);
68
69 this->configure_adc_();
70 delay(1);
71
72 this->configure_shunt_();
73 delay(1);
74
76 delay(1);
77
78 this->state_ = State::IDLE;
79}
80
82 ESP_LOGD(TAG, "Updating");
83 if (this->is_ready() && this->state_ == State::IDLE) {
84 ESP_LOGD(TAG, "Initiating new data collection");
85 this->state_ = State::DATA_COLLECTION_1;
86 return;
87 }
88}
89
91 if (this->is_ready()) {
92 switch (this->state_) {
94 case State::IDLE:
95 break;
96
98 this->full_loop_is_okay_ = true;
99
100 if (this->shunt_voltage_sensor_ != nullptr) {
101 float shunt_voltage{0};
102 this->full_loop_is_okay_ &= this->read_shunt_voltage_mv_(shunt_voltage);
103 this->shunt_voltage_sensor_->publish_state(shunt_voltage);
104 }
105 this->state_ = State::DATA_COLLECTION_2;
106 break;
107
109 if (this->bus_voltage_sensor_ != nullptr) {
110 float bus_voltage{0};
111 this->full_loop_is_okay_ &= this->read_bus_voltage_(bus_voltage);
112 this->bus_voltage_sensor_->publish_state(bus_voltage);
113 }
114 this->state_ = State::DATA_COLLECTION_3;
115 break;
116
118 if (this->die_temperature_sensor_ != nullptr) {
119 float die_temperature{0};
120 this->full_loop_is_okay_ &= this->read_die_temp_c_(die_temperature);
121 this->die_temperature_sensor_->publish_state(die_temperature);
122 }
123 this->state_ = State::DATA_COLLECTION_4;
124 break;
125
127 if (this->current_sensor_ != nullptr) {
128 float current{0};
129 this->full_loop_is_okay_ &= this->read_current_a_(current);
130 this->current_sensor_->publish_state(current);
131 }
132 this->state_ = State::DATA_COLLECTION_5;
133 break;
134
136 if (this->power_sensor_ != nullptr) {
137 float power{0};
138 this->full_loop_is_okay_ &= this->read_power_w_(power);
139 this->power_sensor_->publish_state(power);
140 }
141 this->state_ = State::DATA_COLLECTION_6;
142 break;
143
145 if (this->ina_model_ == INAModel::INA_228 || this->ina_model_ == INAModel::INA_229) {
146 if (this->energy_sensor_j_ != nullptr || this->energy_sensor_wh_ != nullptr ||
147 this->charge_sensor_c_ != nullptr || this->charge_sensor_ah_ != nullptr) {
149 }
150 if (this->energy_sensor_j_ != nullptr || this->energy_sensor_wh_ != nullptr) {
151 double energy_j{0}, energy_wh{0};
152 this->full_loop_is_okay_ &= this->read_energy_(energy_j, energy_wh);
153 if (this->energy_sensor_j_ != nullptr)
154 this->energy_sensor_j_->publish_state(energy_j);
155 if (this->energy_sensor_wh_ != nullptr)
156 this->energy_sensor_wh_->publish_state(energy_wh);
157 }
158 }
159 this->state_ = State::DATA_COLLECTION_7;
160 break;
161
163 if (this->ina_model_ == INAModel::INA_228 || this->ina_model_ == INAModel::INA_229) {
164 if (this->charge_sensor_c_ != nullptr || this->charge_sensor_ah_ != nullptr) {
165 double charge_c{0}, charge_ah{0};
166 this->full_loop_is_okay_ &= this->read_charge_(charge_c, charge_ah);
167 if (this->charge_sensor_c_ != nullptr)
168 this->charge_sensor_c_->publish_state(charge_c);
169 if (this->charge_sensor_ah_ != nullptr)
170 this->charge_sensor_ah_->publish_state(charge_ah);
171 }
172 }
173 this->state_ = State::DATA_COLLECTION_8;
174 break;
175
177 if (this->full_loop_is_okay_) {
178 this->status_clear_warning();
179 } else {
180 this->status_set_warning();
181 }
182 this->state_ = State::IDLE;
183 break;
184
185 default:
186 ESP_LOGW(TAG, "Unknown state of the component, might be due to memory corruption");
187 break;
188 }
189 }
190}
191
193 ESP_LOGCONFIG(TAG, "INA2xx:");
194 ESP_LOGCONFIG(TAG, " Device model = %s", get_device_name(this->ina_model_));
195
196 if (this->device_mismatch_) {
197 ESP_LOGE(TAG, " Device model mismatch. Found device with ID = %x. Please check your configuration.",
198 this->dev_id_);
199 }
200 if (this->is_failed()) {
201 ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
202 }
203 LOG_UPDATE_INTERVAL(this);
204 ESP_LOGCONFIG(TAG,
205 " Shunt resistance = %f Ohm\n"
206 " Max current = %f A\n"
207 " Shunt temp coeff = %d ppm/°C\n"
208 " ADCRANGE = %d (%s)\n"
209 " CURRENT_LSB = %f\n"
210 " SHUNT_CAL = %d",
212 (uint8_t) this->adc_range_, this->adc_range_ ? "±40.96 mV" : "±163.84 mV", this->current_lsb_,
213 this->shunt_cal_);
214
215 ESP_LOGCONFIG(TAG, " ADC Samples = %d; ADC times: Bus = %d μs, Shunt = %d μs, Temp = %d μs",
216 ADC_SAMPLES[0b111 & (uint8_t) this->adc_avg_samples_],
217 ADC_TIMES[0b111 & (uint8_t) this->adc_time_bus_voltage_],
218 ADC_TIMES[0b111 & (uint8_t) this->adc_time_shunt_voltage_],
219 ADC_TIMES[0b111 & (uint8_t) this->adc_time_die_temperature_]);
220
221 ESP_LOGCONFIG(TAG, " Device is %s", get_device_name(this->ina_model_));
222
223 LOG_SENSOR(" ", "Shunt Voltage", this->shunt_voltage_sensor_);
224 LOG_SENSOR(" ", "Bus Voltage", this->bus_voltage_sensor_);
225 LOG_SENSOR(" ", "Die Temperature", this->die_temperature_sensor_);
226 LOG_SENSOR(" ", "Current", this->current_sensor_);
227 LOG_SENSOR(" ", "Power", this->power_sensor_);
228
229 if (this->ina_model_ == INAModel::INA_228 || this->ina_model_ == INAModel::INA_229) {
230 LOG_SENSOR(" ", "Energy J", this->energy_sensor_j_);
231 LOG_SENSOR(" ", "Energy Wh", this->energy_sensor_wh_);
232 LOG_SENSOR(" ", "Charge C", this->charge_sensor_c_);
233 LOG_SENSOR(" ", "Charge Ah", this->charge_sensor_ah_);
234 }
235}
236
238 if (this->ina_model_ != INAModel::INA_228 && this->ina_model_ != INAModel::INA_229) {
239 return false;
240 }
241 ESP_LOGV(TAG, "reset_energy_counters");
242
244 auto ret = this->read_unsigned_16_(RegisterMap::REG_CONFIG, cfg.raw_u16);
245 cfg.RSTACC = true;
246 cfg.ADCRANGE = this->adc_range_;
247 ret = ret && this->write_unsigned_16_(RegisterMap::REG_CONFIG, cfg.raw_u16);
248
249 this->energy_overflows_count_ = 0;
250 this->charge_overflows_count_ = 0;
251 return ret;
252}
253
255 ESP_LOGV(TAG, "Reset");
257 if (!this->reset_on_boot_) {
258 ESP_LOGI(TAG, "Skipping on-boot device reset");
259 cfg.RST = false;
260 } else {
261 cfg.RST = true;
262 }
263 return this->write_unsigned_16_(RegisterMap::REG_CONFIG, cfg.raw_u16);
264}
265
267 constexpr uint16_t manufacturer_ti = 0x5449; // "TI"
268
269 uint16_t manufacturer_id{0}, rev_id{0};
272 this->dev_id_ = 0;
273 ESP_LOGV(TAG, "Can't read device ID");
274 };
275 rev_id = this->dev_id_ & 0x0F;
276 this->dev_id_ >>= 4;
277 ESP_LOGI(TAG, "Manufacturer: 0x%04X, Device ID: 0x%04X, Revision: %d", manufacturer_id, this->dev_id_, rev_id);
278
279 if (manufacturer_id != manufacturer_ti) {
280 ESP_LOGE(TAG, "Manufacturer ID doesn't match original 0x5449");
281 this->device_mismatch_ = true;
282 return false;
283 }
284
285 if (this->dev_id_ == 0x228 || this->dev_id_ == 0x229) {
286 ESP_LOGI(TAG, "Supported device found: INA%x, 85-V, 20-Bit, Ultra-Precise Power/Energy/Charge Monitor",
287 this->dev_id_);
288 } else if (this->dev_id_ == 0x238 || this->dev_id_ == 0x239) {
289 ESP_LOGI(TAG, "Supported device found: INA%x, 85-V, 16-Bit, High-Precision Power Monitor", this->dev_id_);
290 } else if (this->dev_id_ == 0x0 || this->dev_id_ == 0xFF) {
291 ESP_LOGI(TAG, "We assume device is: INA237 85-V, 16-Bit, Precision Power Monitor");
292 this->dev_id_ = 0x237;
293 } else {
294 ESP_LOGE(TAG, "Unknown device ID %x.", this->dev_id_);
295 this->device_mismatch_ = true;
296 return false;
297 }
298
299 // Check user-selected model agains what we have found. Mark as failed if selected model != found model
300 if (!check_model_and_device_match(this->ina_model_, this->dev_id_)) {
301 ESP_LOGE(TAG, "Selected model %s doesn't match found device INA%x", get_device_name(this->ina_model_),
302 this->dev_id_);
303 this->device_mismatch_ = true;
304 return false;
305 }
306
307 // setup device coefficients
308 if (this->ina_model_ == INAModel::INA_228 || this->ina_model_ == INAModel::INA_229) {
309 this->cfg_.vbus_lsb = 0.0001953125f;
310 this->cfg_.v_shunt_lsb_range0 = 0.0003125f;
311 this->cfg_.v_shunt_lsb_range1 = 0.000078125f;
312 this->cfg_.shunt_cal_scale = 13107.2f * 1000000.0f;
313 this->cfg_.current_lsb_scale_factor = -19;
314 this->cfg_.die_temp_lsb = 0.0078125f;
315 this->cfg_.power_coeff = 3.2f;
316 this->cfg_.energy_coeff = 16.0f * 3.2f;
317 } else {
318 this->cfg_.vbus_lsb = 0.0031250000f;
319 this->cfg_.v_shunt_lsb_range0 = 0.0050000f;
320 this->cfg_.v_shunt_lsb_range1 = 0.001250000f;
321 this->cfg_.shunt_cal_scale = 819.2f * 1000000.0f;
322 this->cfg_.current_lsb_scale_factor = -15;
323 this->cfg_.die_temp_lsb = 0.1250000f;
324 this->cfg_.power_coeff = 0.2f;
325 this->cfg_.energy_coeff = 0.0f; // N/A
326 }
327
328 return true;
329}
330
332 ESP_LOGV(TAG, "Setting ADCRANGE = %d", (uint8_t) this->adc_range_);
334 auto ret = this->read_unsigned_16_(RegisterMap::REG_CONFIG, cfg.raw_u16);
335 cfg.ADCRANGE = this->adc_range_;
336 ret = ret && this->write_unsigned_16_(RegisterMap::REG_CONFIG, cfg.raw_u16);
337
338 return ret;
339}
340
342 bool ret{false};
343 AdcConfigurationRegister adc_cfg{0};
344 adc_cfg.MODE = 0x0F; // Fh = Continuous bus voltage, shunt voltage and temperature
345 adc_cfg.VBUSCT = this->adc_time_bus_voltage_;
346 adc_cfg.VSHCT = this->adc_time_shunt_voltage_;
347 adc_cfg.VTCT = this->adc_time_die_temperature_;
348 adc_cfg.AVG = this->adc_avg_samples_;
349 ret = this->write_unsigned_16_(RegisterMap::REG_ADC_CONFIG, adc_cfg.raw_u16);
350 return ret;
351}
352
354 this->current_lsb_ = ldexp(this->max_current_a_, this->cfg_.current_lsb_scale_factor);
355 this->shunt_cal_ = (uint16_t) (this->cfg_.shunt_cal_scale * this->current_lsb_ * this->shunt_resistance_ohm_);
356 if (this->adc_range_)
357 this->shunt_cal_ *= 4;
358
359 if (this->shunt_cal_ & 0x8000) {
360 // cant be more than 15 bits
361 ESP_LOGW(TAG, "Shunt value too high");
362 }
363 this->shunt_cal_ &= 0x7FFF;
364 ESP_LOGV(TAG, "Rshunt=%f Ohm, max current=%.3f A, current LSB=%f, shunt cal=%u", this->shunt_resistance_ohm_,
365 this->max_current_a_, this->current_lsb_, this->shunt_cal_);
367}
368
370 // Only for 228/229
371 // unsigned 14-bit value
372 // 0x0000 = 0 ppm/°C
373 // 0x3FFF = 16383 ppm/°C
374 if ((this->ina_model_ == INAModel::INA_228 || this->ina_model_ == INAModel::INA_229) &&
375 this->shunt_tempco_ppm_c_ > 0) {
377 }
378 return true;
379}
380
381bool INA2XX::read_shunt_voltage_mv_(float &volt_out) {
382 // Two's complement value
383 // 228, 229 - 24bit: 20(23-4) + 4(3-0) res
384 // 237, 238, 239 - 16bit
385
386 bool ret{false};
387 float volt_reading{0};
388 uint64_t raw{0};
389 if (this->ina_model_ == INAModel::INA_228 || this->ina_model_ == INAModel::INA_229) {
391 raw >>= 4;
392 volt_reading = this->two_complement_(raw, 20);
393 } else {
395 volt_reading = this->two_complement_(raw, 16);
396 }
397
398 if (ret) {
399 volt_out = (this->adc_range_ ? this->cfg_.v_shunt_lsb_range1 : this->cfg_.v_shunt_lsb_range0) * volt_reading;
400 }
401
402 ESP_LOGV(TAG, "read_shunt_voltage_mv_ ret=%s, shunt_cal=%d, reading_lsb=%f", OKFAILED(ret), this->shunt_cal_,
403 volt_reading);
404
405 return ret;
406}
407
408bool INA2XX::read_bus_voltage_(float &volt_out) {
409 // Two's complement value
410 // 228, 229 - 24bit: 20(23-4) + 4(3-0) res
411 // 237, 238, 239 - 16bit
412
413 bool ret{false};
414 float volt_reading{0};
415 uint64_t raw{0};
416 if (this->ina_model_ == INAModel::INA_228 || this->ina_model_ == INAModel::INA_229) {
418 raw >>= 4;
419 volt_reading = this->two_complement_(raw, 20);
420 } else {
422 volt_reading = this->two_complement_(raw, 16);
423 }
424 if (ret) {
425 volt_out = this->cfg_.vbus_lsb * (float) volt_reading;
426 }
427
428 ESP_LOGV(TAG, "read_bus_voltage_ ret=%s, reading_lsb=%f", OKFAILED(ret), volt_reading);
429 return ret;
430}
431
432bool INA2XX::read_die_temp_c_(float &temp_out) {
433 // Two's complement value
434 // 228, 229 - 16bit
435 // 237, 238, 239 - 16bit: 12(15-4) + 4(3-0) res
436
437 bool ret{false};
438 float temp_reading{0};
439 uint64_t raw{0};
440
441 if (this->ina_model_ == INAModel::INA_228 || this->ina_model_ == INAModel::INA_229) {
443 temp_reading = this->two_complement_(raw, 16);
444 } else {
446 raw >>= 4;
447 temp_reading = this->two_complement_(raw, 12);
448 }
449 if (ret) {
450 temp_out = this->cfg_.die_temp_lsb * (float) temp_reading;
451 }
452
453 ESP_LOGV(TAG, "read_die_temp_c_ ret=%s, reading_lsb=%f", OKFAILED(ret), temp_reading);
454 return ret;
455}
456
457bool INA2XX::read_current_a_(float &amps_out) {
458 // Two's complement value
459 // 228, 229 - 24bit: 20(23-4) + 4(3-0) res
460 // 237, 238, 239 - 16bit
461 bool ret{false};
462 float amps_reading{0};
463 uint64_t raw{0};
464
465 if (this->ina_model_ == INAModel::INA_228 || this->ina_model_ == INAModel::INA_229) {
467 raw >>= 4;
468 amps_reading = this->two_complement_(raw, 20);
469 } else {
471 amps_reading = this->two_complement_(raw, 16);
472 }
473
474 ESP_LOGV(TAG, "read_current_a_ ret=%s. current_lsb=%f. reading_lsb=%f", OKFAILED(ret), this->current_lsb_,
475 amps_reading);
476 if (ret) {
477 amps_out = this->current_lsb_ * (float) amps_reading;
478 }
479
480 return ret;
481}
482
483bool INA2XX::read_power_w_(float &power_out) {
484 // Unsigned value
485 // 228, 229 - 24bit
486 // 237, 238, 239 - 24bit
487 uint64_t power_reading{0};
488 auto ret = this->read_unsigned_((uint8_t) RegisterMap::REG_POWER, 3, power_reading);
489
490 ESP_LOGV(TAG, "read_power_w_ ret=%s, reading_lsb=%" PRIu32, OKFAILED(ret), (uint32_t) power_reading);
491 if (ret) {
492 power_out = this->cfg_.power_coeff * this->current_lsb_ * (float) power_reading;
493 }
494
495 return ret;
496}
497
498bool INA2XX::read_energy_(double &joules_out, double &watt_hours_out) {
499 // Unsigned value
500 // 228, 229 - 40bit
501 // 237, 238, 239 - not available
502 if (this->ina_model_ != INAModel::INA_228 && this->ina_model_ != INAModel::INA_229) {
503 joules_out = 0;
504 return false;
505 }
506 uint64_t joules_reading = 0;
507 uint64_t previous_energy = this->energy_overflows_count_ * (((uint64_t) 1) << 40);
508 auto ret = this->read_unsigned_((uint8_t) RegisterMap::REG_ENERGY, 5, joules_reading);
509
510 ESP_LOGV(TAG, "read_energy_j_ ret=%s, reading_lsb=0x%" PRIX64 ", current_lsb=%f, overflow_cnt=%" PRIu32,
511 OKFAILED(ret), joules_reading, this->current_lsb_, this->energy_overflows_count_);
512 if (ret) {
513 joules_out = this->cfg_.energy_coeff * this->current_lsb_ * (double) joules_reading + (double) previous_energy;
514 watt_hours_out = joules_out / 3600.0;
515 }
516 return ret;
517}
518
519bool INA2XX::read_charge_(double &coulombs_out, double &amp_hours_out) {
520 // Two's complement value
521 // 228, 229 - 40bit
522 // 237, 238, 239 - not available
523 if (this->ina_model_ != INAModel::INA_228 && this->ina_model_ != INAModel::INA_229) {
524 coulombs_out = 0;
525 return false;
526 }
527
528 // and what to do with this? datasheet doesnt tell us what if charge is negative
529 uint64_t previous_charge = this->charge_overflows_count_ * (((uint64_t) 1) << 39);
530 double coulombs_reading = 0;
531 uint64_t raw{0};
532 auto ret = this->read_unsigned_((uint8_t) RegisterMap::REG_CHARGE, 5, raw);
533 coulombs_reading = this->two_complement_(raw, 40);
534
535 ESP_LOGV(TAG, "read_charge_c_ ret=%d, curr_charge=%f + 39-bit overflow_cnt=%" PRIu32, ret, coulombs_reading,
537 if (ret) {
538 coulombs_out = this->current_lsb_ * (double) coulombs_reading + (double) previous_charge;
539 amp_hours_out = coulombs_out / 3600.0;
540 }
541 return ret;
542}
543
545 if (this->ina_model_ != INAModel::INA_228 && this->ina_model_ != INAModel::INA_229) {
546 return false;
547 }
548
549 DiagnosticRegister diag{0};
550 auto ret = this->read_unsigned_16_(RegisterMap::REG_DIAG_ALRT, diag.raw_u16);
551 ESP_LOGV(TAG, "read_diagnostics_and_act_ ret=%s, 0x%04X", OKFAILED(ret), diag.raw_u16);
552
553 if (diag.ENERGYOF) {
554 this->energy_overflows_count_++; // 40-bit overflow
555 }
556
557 if (diag.CHARGEOF) {
558 this->charge_overflows_count_++; // 39-bit overflow
559 }
560
561 return ret;
562}
563
564bool INA2XX::write_unsigned_16_(uint8_t reg, uint16_t val) {
565 uint16_t data_out = byteswap(val);
566 auto ret = this->write_ina_register(reg, (uint8_t *) &data_out, 2);
567 if (!ret) {
568 ESP_LOGV(TAG, "write_unsigned_16_ FAILED reg=0x%02X, val=0x%04X", reg, val);
569 }
570 return ret;
571}
572
573bool INA2XX::read_unsigned_(uint8_t reg, uint8_t reg_size, uint64_t &data_out) {
574 uint8_t rx_buf[5]{};
575 if (reg_size > sizeof(rx_buf)) {
576 return false;
577 }
578
579 auto ret = this->read_ina_register(reg, rx_buf, reg_size);
580
581 // Combine bytes
582 data_out = rx_buf[0];
583 for (uint8_t i = 1; i < reg_size; i++) {
584 data_out = (data_out << 8) | rx_buf[i];
585 }
586 ESP_LOGV(TAG, "read_unsigned_ reg=0x%02X, ret=%s, len=%d, val=0x%" PRIX64, reg, OKFAILED(ret), reg_size, data_out);
587
588 return ret;
589}
590
591bool INA2XX::read_unsigned_16_(uint8_t reg, uint16_t &out) {
592 uint16_t data_in{0};
593 auto ret = this->read_ina_register(reg, (uint8_t *) &data_in, 2);
594 out = byteswap(data_in);
595 ESP_LOGV(TAG, "read_unsigned_16_ 0x%02X, ret= %s, val=0x%04X", reg, OKFAILED(ret), out);
596 return ret;
597}
598
599int64_t INA2XX::two_complement_(uint64_t value, uint8_t bits) {
600 return (int64_t) (value << (64 - bits)) >> (64 - bits);
601}
602} // namespace esphome::ina2xx_base
uint8_t raw[35]
Definition bl0939.h:0
void mark_failed()
Mark this component as failed.
bool is_failed() const
Definition component.h:284
bool is_ready() const
void status_clear_warning()
Definition component.h:306
bool read_die_temp_c_(float &temp)
bool write_unsigned_16_(uint8_t reg, uint16_t val)
sensor::Sensor * bus_voltage_sensor_
bool read_unsigned_(uint8_t reg, uint8_t reg_size, uint64_t &data_out)
sensor::Sensor * energy_sensor_j_
bool read_bus_voltage_(float &volt_out)
sensor::Sensor * power_sensor_
bool read_unsigned_16_(uint8_t reg, uint16_t &out)
sensor::Sensor * charge_sensor_c_
sensor::Sensor * die_temperature_sensor_
sensor::Sensor * energy_sensor_wh_
bool read_shunt_voltage_mv_(float &volt_out)
virtual bool read_ina_register(uint8_t a_register, uint8_t *data, size_t len)=0
sensor::Sensor * charge_sensor_ah_
bool read_power_w_(float &power_out)
int64_t two_complement_(uint64_t value, uint8_t bits)
bool read_charge_(double &coulombs_out, double &amp_hours_out)
sensor::Sensor * current_sensor_
bool read_energy_(double &joules_out, double &watt_hours_out)
struct esphome::ina2xx_base::INA2XX::@94 cfg_
bool read_current_a_(float &amps_out)
sensor::Sensor * shunt_voltage_sensor_
virtual bool write_ina_register(uint8_t a_register, const uint8_t *data, size_t len)=0
void publish_state(float state)
Publish a new state to the front-end.
Definition sensor.cpp:68
mopeka_std_values val[3]
void HOT delay(uint32_t ms)
Definition hal.cpp:82
static void uint32_t
void byteswap()