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