ESPHome 2025.6.0
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 ESP_LOGCONFIG(TAG, "Running setup");
54
55 if (!this->reset_config_()) {
56 ESP_LOGE(TAG, "Reset failed, check connection");
57 this->mark_failed();
58 return;
59 }
60 delay(2);
61
62 if (!this->check_device_model_()) {
63 ESP_LOGE(TAG, "Device not supported or model selected improperly in yaml file");
64 this->mark_failed();
65 return;
66 }
67 delay(1);
68
70 delay(1);
71
72 this->configure_adc_();
73 delay(1);
74
75 this->configure_shunt_();
76 delay(1);
77
79 delay(1);
80
81 this->state_ = State::IDLE;
82}
83
85
87 ESP_LOGD(TAG, "Updating");
88 if (this->is_ready() && this->state_ == State::IDLE) {
89 ESP_LOGD(TAG, "Initiating new data collection");
90 this->state_ = State::DATA_COLLECTION_1;
91 return;
92 }
93}
94
96 if (this->is_ready()) {
97 switch (this->state_) {
99 case State::IDLE:
100 break;
101
103 this->full_loop_is_okay_ = true;
104
105 if (this->shunt_voltage_sensor_ != nullptr) {
106 float shunt_voltage{0};
107 this->full_loop_is_okay_ &= this->read_shunt_voltage_mv_(shunt_voltage);
108 this->shunt_voltage_sensor_->publish_state(shunt_voltage);
109 }
110 this->state_ = State::DATA_COLLECTION_2;
111 break;
112
114 if (this->bus_voltage_sensor_ != nullptr) {
115 float bus_voltage{0};
116 this->full_loop_is_okay_ &= this->read_bus_voltage_(bus_voltage);
117 this->bus_voltage_sensor_->publish_state(bus_voltage);
118 }
119 this->state_ = State::DATA_COLLECTION_3;
120 break;
121
123 if (this->die_temperature_sensor_ != nullptr) {
124 float die_temperature{0};
125 this->full_loop_is_okay_ &= this->read_die_temp_c_(die_temperature);
126 this->die_temperature_sensor_->publish_state(die_temperature);
127 }
128 this->state_ = State::DATA_COLLECTION_4;
129 break;
130
132 if (this->current_sensor_ != nullptr) {
133 float current{0};
134 this->full_loop_is_okay_ &= this->read_current_a_(current);
135 this->current_sensor_->publish_state(current);
136 }
137 this->state_ = State::DATA_COLLECTION_5;
138 break;
139
141 if (this->power_sensor_ != nullptr) {
142 float power{0};
143 this->full_loop_is_okay_ &= this->read_power_w_(power);
144 this->power_sensor_->publish_state(power);
145 }
146 this->state_ = State::DATA_COLLECTION_6;
147 break;
148
150 if (this->ina_model_ == INAModel::INA_228 || this->ina_model_ == INAModel::INA_229) {
151 if (this->energy_sensor_j_ != nullptr || this->energy_sensor_wh_ != nullptr ||
152 this->charge_sensor_c_ != nullptr || this->charge_sensor_ah_ != nullptr) {
154 }
155 if (this->energy_sensor_j_ != nullptr || this->energy_sensor_wh_ != nullptr) {
156 double energy_j{0}, energy_wh{0};
157 this->full_loop_is_okay_ &= this->read_energy_(energy_j, energy_wh);
158 if (this->energy_sensor_j_ != nullptr)
159 this->energy_sensor_j_->publish_state(energy_j);
160 if (this->energy_sensor_wh_ != nullptr)
161 this->energy_sensor_wh_->publish_state(energy_wh);
162 }
163 }
164 this->state_ = State::DATA_COLLECTION_7;
165 break;
166
168 if (this->ina_model_ == INAModel::INA_228 || this->ina_model_ == INAModel::INA_229) {
169 if (this->charge_sensor_c_ != nullptr || this->charge_sensor_ah_ != nullptr) {
170 double charge_c{0}, charge_ah{0};
171 this->full_loop_is_okay_ &= this->read_charge_(charge_c, charge_ah);
172 if (this->charge_sensor_c_ != nullptr)
173 this->charge_sensor_c_->publish_state(charge_c);
174 if (this->charge_sensor_ah_ != nullptr)
175 this->charge_sensor_ah_->publish_state(charge_ah);
176 }
177 }
178 this->state_ = State::DATA_COLLECTION_8;
179 break;
180
182 if (this->full_loop_is_okay_) {
183 this->status_clear_warning();
184 } else {
185 this->status_set_warning();
186 }
187 this->state_ = State::IDLE;
188 break;
189
190 default:
191 ESP_LOGW(TAG, "Unknown state of the component, might be due to memory corruption");
192 break;
193 }
194 }
195}
196
198 ESP_LOGCONFIG(TAG, "INA2xx:");
199 ESP_LOGCONFIG(TAG, " Device model = %s", get_device_name(this->ina_model_));
200
201 if (this->device_mismatch_) {
202 ESP_LOGE(TAG, " Device model mismatch. Found device with ID = %x. Please check your configuration.",
203 this->dev_id_);
204 }
205 if (this->is_failed()) {
206 ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
207 }
208 LOG_UPDATE_INTERVAL(this);
209 ESP_LOGCONFIG(TAG,
210 " Shunt resistance = %f Ohm\n"
211 " Max current = %f A\n"
212 " Shunt temp coeff = %d ppm/°C\n"
213 " ADCRANGE = %d (%s)\n"
214 " CURRENT_LSB = %f\n"
215 " SHUNT_CAL = %d",
217 (uint8_t) this->adc_range_, this->adc_range_ ? "±40.96 mV" : "±163.84 mV", this->current_lsb_,
218 this->shunt_cal_);
219
220 ESP_LOGCONFIG(TAG, " ADC Samples = %d; ADC times: Bus = %d μs, Shunt = %d μs, Temp = %d μs",
221 ADC_SAMPLES[0b111 & (uint8_t) this->adc_avg_samples_],
222 ADC_TIMES[0b111 & (uint8_t) this->adc_time_bus_voltage_],
223 ADC_TIMES[0b111 & (uint8_t) this->adc_time_shunt_voltage_],
224 ADC_TIMES[0b111 & (uint8_t) this->adc_time_die_temperature_]);
225
226 ESP_LOGCONFIG(TAG, " Device is %s", get_device_name(this->ina_model_));
227
228 LOG_SENSOR(" ", "Shunt Voltage", this->shunt_voltage_sensor_);
229 LOG_SENSOR(" ", "Bus Voltage", this->bus_voltage_sensor_);
230 LOG_SENSOR(" ", "Die Temperature", this->die_temperature_sensor_);
231 LOG_SENSOR(" ", "Current", this->current_sensor_);
232 LOG_SENSOR(" ", "Power", this->power_sensor_);
233
234 if (this->ina_model_ == INAModel::INA_228 || this->ina_model_ == INAModel::INA_229) {
235 LOG_SENSOR(" ", "Energy J", this->energy_sensor_j_);
236 LOG_SENSOR(" ", "Energy Wh", this->energy_sensor_wh_);
237 LOG_SENSOR(" ", "Charge C", this->charge_sensor_c_);
238 LOG_SENSOR(" ", "Charge Ah", this->charge_sensor_ah_);
239 }
240}
241
243 if (this->ina_model_ != INAModel::INA_228 && this->ina_model_ != INAModel::INA_229) {
244 return false;
245 }
246 ESP_LOGV(TAG, "reset_energy_counters");
247
249 auto ret = this->read_unsigned_16_(RegisterMap::REG_CONFIG, cfg.raw_u16);
250 cfg.RSTACC = true;
251 cfg.ADCRANGE = this->adc_range_;
252 ret = ret && this->write_unsigned_16_(RegisterMap::REG_CONFIG, cfg.raw_u16);
253
254 this->energy_overflows_count_ = 0;
255 this->charge_overflows_count_ = 0;
256 return ret;
257}
258
260 ESP_LOGV(TAG, "Reset");
262 cfg.RST = true;
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, "Given Rshunt=%f Ohm and Max_current=%.3f", this->shunt_resistance_ohm_, this->max_current_a_);
365 ESP_LOGV(TAG, "New CURRENT_LSB=%f, SHUNT_CAL=%u", 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 static uint8_t rx_buf[5] = {0}; // max buffer size
575
576 if (reg_size > 5) {
577 return false;
578 }
579
580 auto ret = this->read_ina_register(reg, rx_buf, reg_size);
581
582 // Combine bytes
583 data_out = rx_buf[0];
584 for (uint8_t i = 1; i < reg_size; i++) {
585 data_out = (data_out << 8) | rx_buf[i];
586 }
587 ESP_LOGV(TAG, "read_unsigned_ reg=0x%02X, ret=%s, len=%d, val=0x%" PRIX64, reg, OKFAILED(ret), reg_size, data_out);
588
589 return ret;
590}
591
592bool INA2XX::read_unsigned_16_(uint8_t reg, uint16_t &out) {
593 uint16_t data_in{0};
594 auto ret = this->read_ina_register(reg, (uint8_t *) &data_in, 2);
595 out = byteswap(data_in);
596 ESP_LOGV(TAG, "read_unsigned_16_ 0x%02X, ret= %s, val=0x%04X", reg, OKFAILED(ret), out);
597 return ret;
598}
599
600int64_t INA2XX::two_complement_(uint64_t value, uint8_t bits) {
601 if (value > (1ULL << (bits - 1))) {
602 return (int64_t) (value - (1ULL << bits));
603 } else {
604 return (int64_t) value;
605 }
606}
607} // namespace ina2xx_base
608} // namespace esphome
uint8_t raw[35]
Definition bl0939.h:0
virtual void mark_failed()
Mark this component as failed.
bool is_failed() const
bool is_ready() const
void status_set_warning(const char *message="unspecified")
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
bool read_current_a_(float &amps_out)
struct esphome::ina2xx_base::INA2XX::@90 cfg_
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:39
mopeka_std_values val[4]
const float DATA
For components that import data from directly connected sensors like DHT.
Definition component.cpp:20
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:29
void byteswap()