21static const uint8_t SETUP_DELAY = 4;
22static const float VOUT_LSB = 14.0 / 1000.0;
23static const float TEMP_LSB = 0.48;
24static const float MICRO_VOLTS_PER_VOLT = 1000000.0;
29 this->
read(&value, 1);
36 if (this->
write(
reinterpret_cast<const uint8_t *
>(&setup_dat),
sizeof(setup_dat)) != ErrorCode::ERROR_OK) {
37 ESP_LOGE(TAG,
"GAIN SET failed");
41 if (this->
write(
reinterpret_cast<const uint8_t *
>(&fast_mode_dat),
sizeof(fast_mode_dat)) != ErrorCode::ERROR_OK) {
42 ESP_LOGE(TAG,
"FAST MODE SET failed");
46void MAX9611Component::dump_config() {
49 " CSA Gain Register: %x",
53void MAX9611Component::update() {
55 const uint8_t reg_base = 0x0;
59 if (write_result != ErrorCode::ERROR_OK || read_result != ErrorCode::ERROR_OK) {
60 ESP_LOGW(TAG,
"Update failed");
63 uint16_t csa_register =
65 uint16_t rs_register =
69 float voltage = rs_register * VOUT_LSB;
70 float shunt_voltage = (csa_register *
gain_to_lsb(
gain_)) / MICRO_VOLTS_PER_VOLT;
73 float watts = amps * voltage;
75 PUBLISH_STATE(this->voltage_sensor_, voltage);
76 PUBLISH_STATE(this->current_sensor_, amps);
77 PUBLISH_STATE(this->watt_sensor_, watts);
78 PUBLISH_STATE(this->temp_sensor_, temp);
80 ESP_LOGD(TAG,
"V: %f, A: %f, W: %f, Deg C: %f", voltage, amps, watts, temp);