6static const char *
const TAG =
"cs5460a";
55 float voltage_full_scale = 0.25;
80 ESP_LOGE(TAG,
"CS5460A reset failed!");
86 ESP_LOGCONFIG(TAG,
" Version: %" PRIx32, (
status >> 6) & 7);
97 ESP_LOGCONFIG(TAG,
" Init ok");
134 time_left -= time_left / 5;
136 if (time_left > -500) {
147 if (time_left > -15000) {
151 ESP_LOGCONFIG(TAG,
"Device officially stuck, resetting");
158 this->
set_timeout(
"status-check", time_left, [
this]() {
168 if (!(status & 0xcbf83c)) {
179 ESP_LOGE(TAG,
"Low supply detected");
183 if (status & (1 << 3)) {
185 ESP_LOGE(TAG,
"Modulator oscillation on current channel");
189 if (status & (1 << 4)) {
191 ESP_LOGE(TAG,
"Modulator oscillation on voltage channel");
195 if (status & (1 << 5)) {
197 ESP_LOGE(TAG,
"Watch-dog timeout");
201 if (status & (1 << 11)) {
203 ESP_LOGE(TAG,
"EOUT Energy Accumulation Register out of range");
207 if (status & (1 << 12)) {
209 ESP_LOGE(TAG,
"Energy out of range");
213 if (status & (1 << 13)) {
215 ESP_LOGE(TAG,
"RMS voltage out of range");
219 if (status & (1 << 14)) {
221 ESP_LOGE(TAG,
"RMS current out of range");
225 if (status & (1 << 15)) {
227 ESP_LOGE(TAG,
"Power calculation out of range");
231 if (status & (1 << 16)) {
233 ESP_LOGE(TAG,
"Voltage out of range");
237 if (status & (1 << 17)) {
239 ESP_LOGE(TAG,
"Current out of range");
243 if (status & (1 << 19)) {
245 ESP_LOGE(TAG,
"Divide overflowed");
249 bool dir =
status & (1 << 21);
252 ESP_LOGI(TAG,
"Energy counter %s pulse", dir ?
"negative" :
"positive");
270 if (status & ((1 << 23) | (1 << 5))) {
293 if (status & (1 << 23)) {
305 int32_t
raw = (int32_t) (raw_energy << 8) >> 8;
323 LOG_PIN(
" CS Pin: ",
cs_);
325 " Samples / cycle: %" PRIu32
"\n"
326 " Phase offset: %i\n"
328 " Current gain: %.5f\n"
329 " Voltage gain: %.5f\n"
332 " Pulse energy: %.2f Wh",
void mark_failed()
Mark this component as failed.
uint8_t get_component_state() const
ESPDEPRECATED("Use const char* or uint32_t overload instead. Removed in 2026.7.0", "2026.1.0") void set_timeout(const std voi set_timeout)(const char *name, uint32_t timeout, std::function< void()> &&f)
Set a timeout function with a unique name.
void status_momentary_warning(const char *name, uint32_t length=5000)
Set warning status flag and automatically clear it after a timeout.
ESPDEPRECATED("Use const char* or uint32_t overload instead. Removed in 2026.7.0", "2026.1.0") bool cancel_timeout(const std boo cancel_timeout)(const char *name)
Cancel a timeout function.
float current_multiplier_
void dump_config() override
uint32_t prev_raw_energy_
void write_register_(enum CS5460ARegister addr, uint32_t value)
sensor::Sensor * voltage_sensor_
uint32_t read_register_(uint8_t addr)
void schedule_next_check_()
float voltage_multiplier_
sensor::Sensor * power_sensor_
uint32_t prev_raw_current_
sensor::Sensor * current_sensor_
void publish_state(float state)
Publish a new state to the front-end.
void spi_setup() override
void write_byte(uint8_t data)
uint8_t transfer_byte(uint8_t data)
constexpr uint8_t COMPONENT_STATE_FAILED
constexpr uint8_t COMPONENT_STATE_LOOP
void HOT delay(uint32_t ms)
uint32_t IRAM_ATTR HOT millis()