ESPHome  2024.11.2
ct_clamp_sensor.h
Go to the documentation of this file.
1 #pragma once
2 
4 #include "esphome/core/hal.h"
7 
8 namespace esphome {
9 namespace ct_clamp {
10 
12  public:
13  void update() override;
14  void loop() override;
15  void dump_config() override;
16  float get_setup_priority() const override {
17  // After the base sensor has been initialized
18  return setup_priority::DATA - 1.0f;
19  }
20 
21  void set_sample_duration(uint32_t sample_duration) { sample_duration_ = sample_duration; }
23 
24  protected:
27 
29  uint32_t sample_duration_;
32 
46  float last_value_ = 0.0f;
47  float sample_sum_ = 0.0f;
48  float sample_squared_sum_ = 0.0f;
49  uint32_t num_samples_ = 0;
50  bool is_sampling_ = false;
51 };
52 
53 } // namespace ct_clamp
54 } // namespace esphome
const float DATA
For components that import data from directly connected sensors like DHT.
Definition: component.cpp:19
uint32_t sample_duration_
Duration in ms of the sampling phase.
void set_sample_duration(uint32_t sample_duration)
Helper class to request loop() to be called as fast as possible.
Definition: helpers.h:613
HighFrequencyLoopRequester high_freq_
High Frequency loop() requester used during sampling phase.
Abstract interface for components to request voltage (usually ADC readings)
This class simplifies creating components that periodically check a state.
Definition: component.h:283
voltage_sampler::VoltageSampler * source_
The sampling source to read values from.
float last_value_
The DC offset of the circuit.
void set_source(voltage_sampler::VoltageSampler *source)
float get_setup_priority() const override
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
Base-class for all sensors.
Definition: sensor.h:57