7 namespace ade7953_base {
9 static const char *
const TAG =
"ade7953";
11 static const float ADE_POWER_FACTOR = 154.0f;
12 static const float ADE_WATTSEC_POWER_FACTOR = ADE_POWER_FACTOR * ADE_POWER_FACTOR / 3600;
49 LOG_UPDATE_INTERVAL(
this);
62 ESP_LOGCONFIG(TAG,
" PGA_V_8: 0x%X",
pga_v_);
63 ESP_LOGCONFIG(TAG,
" PGA_IA_8: 0x%X",
pga_ia_);
64 ESP_LOGCONFIG(TAG,
" PGA_IB_8: 0x%X",
pga_ib_);
65 ESP_LOGCONFIG(TAG,
" VGAIN_32: 0x%08jX", (uintmax_t)
vgain_);
66 ESP_LOGCONFIG(TAG,
" AIGAIN_32: 0x%08jX", (uintmax_t)
aigain_);
67 ESP_LOGCONFIG(TAG,
" BIGAIN_32: 0x%08jX", (uintmax_t)
bigain_);
68 ESP_LOGCONFIG(TAG,
" AWGAIN_32: 0x%08jX", (uintmax_t)
awgain_);
69 ESP_LOGCONFIG(TAG,
" BWGAIN_32: 0x%08jX", (uintmax_t)
bwgain_);
72 #define ADE_PUBLISH_(name, val, factor) \ 73 if (err == 0 && this->name##_sensor_) { \ 74 float value = (val) / (factor); \ 75 this->name##_sensor_->publish_state(value); \ 77 #define ADE_PUBLISH(name, val, factor) ADE_PUBLISH_(name, val, factor) 85 uint32_t interrupts_a = 0;
86 uint32_t interrupts_b = 0;
99 ADE_PUBLISH(power_factor_a, (int16_t) val_16, (0x7FFF / 100.0f));
101 ADE_PUBLISH(power_factor_b, (int16_t) val_16, (0x7FFF / 100.0f));
103 float pf = ADE_POWER_FACTOR;
105 const uint32_t now =
millis();
107 this->last_update_ = now;
109 pf = ADE_WATTSEC_POWER_FACTOR * (diff < 10 ? 10 : diff) / 1000;
110 ESP_LOGVV(TAG,
"ADE7953::update() diff=%" PRIu32
" pf=%f", diff, pf);
116 ADE_PUBLISH(apparent_power_a, (int32_t) val, pf);
118 ADE_PUBLISH(apparent_power_b, (int32_t) val, pf);
123 ADE_PUBLISH(active_power_a, (int32_t) val, pf);
125 ADE_PUBLISH(active_power_b, (int32_t) val, pf);
130 ADE_PUBLISH(reactive_power_a, (int32_t) val, pf);
132 ADE_PUBLISH(reactive_power_b, (int32_t) val, pf);
136 ADE_PUBLISH(current_a, (uint32_t) val, 100000.0f);
138 ADE_PUBLISH(current_b, (uint32_t) val, 100000.0f);
142 ADE_PUBLISH(voltage, (uint32_t) val, 26000.0f);
146 ADE_PUBLISH(
frequency, 223750.0f, 1 + val_16);
sensor::Sensor * apparent_power_b_sensor_
sensor::Sensor * voltage_sensor_
virtual bool ade_read_32(uint16_t reg, uint32_t *value)=0
sensor::Sensor * reactive_power_a_sensor_
bool use_acc_energy_regs_
sensor::Sensor * power_factor_b_sensor_
void set_timeout(const std::string &name, uint32_t timeout, std::function< void()> &&f)
Set a timeout function with a unique name.
virtual bool ade_write_32(uint16_t reg, uint32_t value)=0
uint32_t IRAM_ATTR HOT millis()
void dump_config() override
sensor::Sensor * active_power_b_sensor_
virtual bool ade_read_8(uint16_t reg, uint8_t *value)=0
sensor::Sensor * power_factor_a_sensor_
InternalGPIOPin * irq_pin_
virtual bool ade_write_16(uint16_t reg, uint16_t value)=0
sensor::Sensor * reactive_power_b_sensor_
sensor::Sensor * current_b_sensor_
sensor::Sensor * active_power_a_sensor_
Implementation of SPI Controller mode.
virtual bool ade_read_16(uint16_t reg, uint16_t *value)=0
sensor::Sensor * apparent_power_a_sensor_
sensor::Sensor * current_a_sensor_
virtual bool ade_write_8(uint16_t reg, uint8_t value)=0