ESPHome 2025.9.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 cfg.RST = true;
261 return this->write_unsigned_16_(RegisterMap::REG_CONFIG, cfg.raw_u16);
262}
263
265 constexpr uint16_t manufacturer_ti = 0x5449; // "TI"
266
267 uint16_t manufacturer_id{0}, rev_id{0};
270 this->dev_id_ = 0;
271 ESP_LOGV(TAG, "Can't read device ID");
272 };
273 rev_id = this->dev_id_ & 0x0F;
274 this->dev_id_ >>= 4;
275 ESP_LOGI(TAG, "Manufacturer: 0x%04X, Device ID: 0x%04X, Revision: %d", manufacturer_id, this->dev_id_, rev_id);
276
277 if (manufacturer_id != manufacturer_ti) {
278 ESP_LOGE(TAG, "Manufacturer ID doesn't match original 0x5449");
279 this->device_mismatch_ = true;
280 return false;
281 }
282
283 if (this->dev_id_ == 0x228 || this->dev_id_ == 0x229) {
284 ESP_LOGI(TAG, "Supported device found: INA%x, 85-V, 20-Bit, Ultra-Precise Power/Energy/Charge Monitor",
285 this->dev_id_);
286 } else if (this->dev_id_ == 0x238 || this->dev_id_ == 0x239) {
287 ESP_LOGI(TAG, "Supported device found: INA%x, 85-V, 16-Bit, High-Precision Power Monitor", this->dev_id_);
288 } else if (this->dev_id_ == 0x0 || this->dev_id_ == 0xFF) {
289 ESP_LOGI(TAG, "We assume device is: INA237 85-V, 16-Bit, Precision Power Monitor");
290 this->dev_id_ = 0x237;
291 } else {
292 ESP_LOGE(TAG, "Unknown device ID %x.", this->dev_id_);
293 this->device_mismatch_ = true;
294 return false;
295 }
296
297 // Check user-selected model agains what we have found. Mark as failed if selected model != found model
298 if (!check_model_and_device_match(this->ina_model_, this->dev_id_)) {
299 ESP_LOGE(TAG, "Selected model %s doesn't match found device INA%x", get_device_name(this->ina_model_),
300 this->dev_id_);
301 this->device_mismatch_ = true;
302 return false;
303 }
304
305 // setup device coefficients
306 if (this->ina_model_ == INAModel::INA_228 || this->ina_model_ == INAModel::INA_229) {
307 this->cfg_.vbus_lsb = 0.0001953125f;
308 this->cfg_.v_shunt_lsb_range0 = 0.0003125f;
309 this->cfg_.v_shunt_lsb_range1 = 0.000078125f;
310 this->cfg_.shunt_cal_scale = 13107.2f * 1000000.0f;
311 this->cfg_.current_lsb_scale_factor = -19;
312 this->cfg_.die_temp_lsb = 0.0078125f;
313 this->cfg_.power_coeff = 3.2f;
314 this->cfg_.energy_coeff = 16.0f * 3.2f;
315 } else {
316 this->cfg_.vbus_lsb = 0.0031250000f;
317 this->cfg_.v_shunt_lsb_range0 = 0.0050000f;
318 this->cfg_.v_shunt_lsb_range1 = 0.001250000f;
319 this->cfg_.shunt_cal_scale = 819.2f * 1000000.0f;
320 this->cfg_.current_lsb_scale_factor = -15;
321 this->cfg_.die_temp_lsb = 0.1250000f;
322 this->cfg_.power_coeff = 0.2f;
323 this->cfg_.energy_coeff = 0.0f; // N/A
324 }
325
326 return true;
327}
328
330 ESP_LOGV(TAG, "Setting ADCRANGE = %d", (uint8_t) this->adc_range_);
332 auto ret = this->read_unsigned_16_(RegisterMap::REG_CONFIG, cfg.raw_u16);
333 cfg.ADCRANGE = this->adc_range_;
334 ret = ret && this->write_unsigned_16_(RegisterMap::REG_CONFIG, cfg.raw_u16);
335
336 return ret;
337}
338
340 bool ret{false};
341 AdcConfigurationRegister adc_cfg{0};
342 adc_cfg.MODE = 0x0F; // Fh = Continuous bus voltage, shunt voltage and temperature
343 adc_cfg.VBUSCT = this->adc_time_bus_voltage_;
344 adc_cfg.VSHCT = this->adc_time_shunt_voltage_;
345 adc_cfg.VTCT = this->adc_time_die_temperature_;
346 adc_cfg.AVG = this->adc_avg_samples_;
347 ret = this->write_unsigned_16_(RegisterMap::REG_ADC_CONFIG, adc_cfg.raw_u16);
348 return ret;
349}
350
352 this->current_lsb_ = ldexp(this->max_current_a_, this->cfg_.current_lsb_scale_factor);
353 this->shunt_cal_ = (uint16_t) (this->cfg_.shunt_cal_scale * this->current_lsb_ * this->shunt_resistance_ohm_);
354 if (this->adc_range_)
355 this->shunt_cal_ *= 4;
356
357 if (this->shunt_cal_ & 0x8000) {
358 // cant be more than 15 bits
359 ESP_LOGW(TAG, "Shunt value too high");
360 }
361 this->shunt_cal_ &= 0x7FFF;
362 ESP_LOGV(TAG, "Given Rshunt=%f Ohm and Max_current=%.3f", this->shunt_resistance_ohm_, this->max_current_a_);
363 ESP_LOGV(TAG, "New CURRENT_LSB=%f, SHUNT_CAL=%u", this->current_lsb_, this->shunt_cal_);
365}
366
368 // Only for 228/229
369 // unsigned 14-bit value
370 // 0x0000 = 0 ppm/°C
371 // 0x3FFF = 16383 ppm/°C
372 if ((this->ina_model_ == INAModel::INA_228 || this->ina_model_ == INAModel::INA_229) &&
373 this->shunt_tempco_ppm_c_ > 0) {
375 }
376 return true;
377}
378
379bool INA2XX::read_shunt_voltage_mv_(float &volt_out) {
380 // Two's complement value
381 // 228, 229 - 24bit: 20(23-4) + 4(3-0) res
382 // 237, 238, 239 - 16bit
383
384 bool ret{false};
385 float volt_reading{0};
386 uint64_t raw{0};
387 if (this->ina_model_ == INAModel::INA_228 || this->ina_model_ == INAModel::INA_229) {
389 raw >>= 4;
390 volt_reading = this->two_complement_(raw, 20);
391 } else {
393 volt_reading = this->two_complement_(raw, 16);
394 }
395
396 if (ret) {
397 volt_out = (this->adc_range_ ? this->cfg_.v_shunt_lsb_range1 : this->cfg_.v_shunt_lsb_range0) * volt_reading;
398 }
399
400 ESP_LOGV(TAG, "read_shunt_voltage_mv_ ret=%s, shunt_cal=%d, reading_lsb=%f", OKFAILED(ret), this->shunt_cal_,
401 volt_reading);
402
403 return ret;
404}
405
406bool INA2XX::read_bus_voltage_(float &volt_out) {
407 // Two's complement value
408 // 228, 229 - 24bit: 20(23-4) + 4(3-0) res
409 // 237, 238, 239 - 16bit
410
411 bool ret{false};
412 float volt_reading{0};
413 uint64_t raw{0};
414 if (this->ina_model_ == INAModel::INA_228 || this->ina_model_ == INAModel::INA_229) {
416 raw >>= 4;
417 volt_reading = this->two_complement_(raw, 20);
418 } else {
420 volt_reading = this->two_complement_(raw, 16);
421 }
422 if (ret) {
423 volt_out = this->cfg_.vbus_lsb * (float) volt_reading;
424 }
425
426 ESP_LOGV(TAG, "read_bus_voltage_ ret=%s, reading_lsb=%f", OKFAILED(ret), volt_reading);
427 return ret;
428}
429
430bool INA2XX::read_die_temp_c_(float &temp_out) {
431 // Two's complement value
432 // 228, 229 - 16bit
433 // 237, 238, 239 - 16bit: 12(15-4) + 4(3-0) res
434
435 bool ret{false};
436 float temp_reading{0};
437 uint64_t raw{0};
438
439 if (this->ina_model_ == INAModel::INA_228 || this->ina_model_ == INAModel::INA_229) {
441 temp_reading = this->two_complement_(raw, 16);
442 } else {
444 raw >>= 4;
445 temp_reading = this->two_complement_(raw, 12);
446 }
447 if (ret) {
448 temp_out = this->cfg_.die_temp_lsb * (float) temp_reading;
449 }
450
451 ESP_LOGV(TAG, "read_die_temp_c_ ret=%s, reading_lsb=%f", OKFAILED(ret), temp_reading);
452 return ret;
453}
454
455bool INA2XX::read_current_a_(float &amps_out) {
456 // Two's complement value
457 // 228, 229 - 24bit: 20(23-4) + 4(3-0) res
458 // 237, 238, 239 - 16bit
459 bool ret{false};
460 float amps_reading{0};
461 uint64_t raw{0};
462
463 if (this->ina_model_ == INAModel::INA_228 || this->ina_model_ == INAModel::INA_229) {
465 raw >>= 4;
466 amps_reading = this->two_complement_(raw, 20);
467 } else {
469 amps_reading = this->two_complement_(raw, 16);
470 }
471
472 ESP_LOGV(TAG, "read_current_a_ ret=%s. current_lsb=%f. reading_lsb=%f", OKFAILED(ret), this->current_lsb_,
473 amps_reading);
474 if (ret) {
475 amps_out = this->current_lsb_ * (float) amps_reading;
476 }
477
478 return ret;
479}
480
481bool INA2XX::read_power_w_(float &power_out) {
482 // Unsigned value
483 // 228, 229 - 24bit
484 // 237, 238, 239 - 24bit
485 uint64_t power_reading{0};
486 auto ret = this->read_unsigned_((uint8_t) RegisterMap::REG_POWER, 3, power_reading);
487
488 ESP_LOGV(TAG, "read_power_w_ ret=%s, reading_lsb=%" PRIu32, OKFAILED(ret), (uint32_t) power_reading);
489 if (ret) {
490 power_out = this->cfg_.power_coeff * this->current_lsb_ * (float) power_reading;
491 }
492
493 return ret;
494}
495
496bool INA2XX::read_energy_(double &joules_out, double &watt_hours_out) {
497 // Unsigned value
498 // 228, 229 - 40bit
499 // 237, 238, 239 - not available
500 if (this->ina_model_ != INAModel::INA_228 && this->ina_model_ != INAModel::INA_229) {
501 joules_out = 0;
502 return false;
503 }
504 uint64_t joules_reading = 0;
505 uint64_t previous_energy = this->energy_overflows_count_ * (((uint64_t) 1) << 40);
506 auto ret = this->read_unsigned_((uint8_t) RegisterMap::REG_ENERGY, 5, joules_reading);
507
508 ESP_LOGV(TAG, "read_energy_j_ ret=%s, reading_lsb=0x%" PRIX64 ", current_lsb=%f, overflow_cnt=%" PRIu32,
509 OKFAILED(ret), joules_reading, this->current_lsb_, this->energy_overflows_count_);
510 if (ret) {
511 joules_out = this->cfg_.energy_coeff * this->current_lsb_ * (double) joules_reading + (double) previous_energy;
512 watt_hours_out = joules_out / 3600.0;
513 }
514 return ret;
515}
516
517bool INA2XX::read_charge_(double &coulombs_out, double &amp_hours_out) {
518 // Two's complement value
519 // 228, 229 - 40bit
520 // 237, 238, 239 - not available
521 if (this->ina_model_ != INAModel::INA_228 && this->ina_model_ != INAModel::INA_229) {
522 coulombs_out = 0;
523 return false;
524 }
525
526 // and what to do with this? datasheet doesnt tell us what if charge is negative
527 uint64_t previous_charge = this->charge_overflows_count_ * (((uint64_t) 1) << 39);
528 double coulombs_reading = 0;
529 uint64_t raw{0};
530 auto ret = this->read_unsigned_((uint8_t) RegisterMap::REG_CHARGE, 5, raw);
531 coulombs_reading = this->two_complement_(raw, 40);
532
533 ESP_LOGV(TAG, "read_charge_c_ ret=%d, curr_charge=%f + 39-bit overflow_cnt=%" PRIu32, ret, coulombs_reading,
535 if (ret) {
536 coulombs_out = this->current_lsb_ * (double) coulombs_reading + (double) previous_charge;
537 amp_hours_out = coulombs_out / 3600.0;
538 }
539 return ret;
540}
541
543 if (this->ina_model_ != INAModel::INA_228 && this->ina_model_ != INAModel::INA_229) {
544 return false;
545 }
546
547 DiagnosticRegister diag{0};
548 auto ret = this->read_unsigned_16_(RegisterMap::REG_DIAG_ALRT, diag.raw_u16);
549 ESP_LOGV(TAG, "read_diagnostics_and_act_ ret=%s, 0x%04X", OKFAILED(ret), diag.raw_u16);
550
551 if (diag.ENERGYOF) {
552 this->energy_overflows_count_++; // 40-bit overflow
553 }
554
555 if (diag.CHARGEOF) {
556 this->charge_overflows_count_++; // 39-bit overflow
557 }
558
559 return ret;
560}
561
562bool INA2XX::write_unsigned_16_(uint8_t reg, uint16_t val) {
563 uint16_t data_out = byteswap(val);
564 auto ret = this->write_ina_register(reg, (uint8_t *) &data_out, 2);
565 if (!ret) {
566 ESP_LOGV(TAG, "write_unsigned_16_ FAILED reg=0x%02X, val=0x%04X", reg, val);
567 }
568 return ret;
569}
570
571bool INA2XX::read_unsigned_(uint8_t reg, uint8_t reg_size, uint64_t &data_out) {
572 static uint8_t rx_buf[5] = {0}; // max buffer size
573
574 if (reg_size > 5) {
575 return false;
576 }
577
578 auto ret = this->read_ina_register(reg, rx_buf, reg_size);
579
580 // Combine bytes
581 data_out = rx_buf[0];
582 for (uint8_t i = 1; i < reg_size; i++) {
583 data_out = (data_out << 8) | rx_buf[i];
584 }
585 ESP_LOGV(TAG, "read_unsigned_ reg=0x%02X, ret=%s, len=%d, val=0x%" PRIX64, reg, OKFAILED(ret), reg_size, data_out);
586
587 return ret;
588}
589
590bool INA2XX::read_unsigned_16_(uint8_t reg, uint16_t &out) {
591 uint16_t data_in{0};
592 auto ret = this->read_ina_register(reg, (uint8_t *) &data_in, 2);
593 out = byteswap(data_in);
594 ESP_LOGV(TAG, "read_unsigned_16_ 0x%02X, ret= %s, val=0x%04X", reg, OKFAILED(ret), out);
595 return ret;
596}
597
598int64_t INA2XX::two_complement_(uint64_t value, uint8_t bits) {
599 if (value > (1ULL << (bits - 1))) {
600 return (int64_t) (value - (1ULL << bits));
601 } else {
602 return (int64_t) value;
603 }
604}
605} // namespace ina2xx_base
606} // 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)
struct esphome::ina2xx_base::INA2XX::@91 cfg_
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)
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:45
mopeka_std_values val[4]
const float DATA
For components that import data from directly connected sensors like DHT.
Definition component.cpp:50
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()