mirror of
https://github.com/esphome/esphome.git
synced 2025-03-15 15:18:16 +00:00
Update lint
This commit is contained in:
parent
fffa342048
commit
0f1106e959
@ -27,33 +27,31 @@ float CTClampSensor::get_setup_priority() const { return setup_priority::DATA; }
|
|||||||
|
|
||||||
void CTClampSensor::update() {
|
void CTClampSensor::update() {
|
||||||
|
|
||||||
for (unsigned int n = 0; n < this->sample_size_; n++)
|
for (unsigned int n = 0; n < this->sample_size_; n++) {
|
||||||
{
|
sample_i_ = analogRead(this->pin_);
|
||||||
sampleI = analogRead(this->pin_);
|
|
||||||
|
|
||||||
// Digital low pass filter extracts the 1.65 V dc offset,
|
// Digital low pass filter extracts the 1.65 V dc offset,
|
||||||
// then subtract this - signal is now centered on 0 counts.
|
// then subtract this - signal is now centered on 0 counts.
|
||||||
offsetI = (offsetI + (sampleI-offsetI)/(ADC_COUNTS));
|
offset_i_ = (offset_i_ + (sample_i_ - offset_i_) / (ADC_COUNTS));
|
||||||
filteredI = sampleI - offsetI;
|
filtered_i_ = sample_i_ - offset_i_;
|
||||||
|
|
||||||
// Root-mean-square method current
|
// Root-mean-square method current
|
||||||
// 1) square current values
|
// 1) square current values
|
||||||
sqI = filteredI * filteredI;
|
sq_i_ = filtered_i_ * filtered_i_;
|
||||||
// 2) sum
|
// 2) sum
|
||||||
sumI += sqI;
|
sum_i_ += sq_i_;
|
||||||
}
|
}
|
||||||
|
|
||||||
double I_RATIO = this->calibration_ * ((supply_voltage_) / (ADC_COUNTS));
|
double i_ratio = this->calibration_ * ((supply_voltage_) / (ADC_COUNTS));
|
||||||
Irms = I_RATIO * sqrt(sumI / this->sample_size_);
|
irms_ = i_ratio * sqrt(sum_i_ / this->sample_size_);
|
||||||
|
|
||||||
//Reset accumulators
|
//Reset accumulators
|
||||||
sumI = 0;
|
sum_i_ = 0;
|
||||||
|
|
||||||
ESP_LOGD(TAG, "'%s'", this->get_name().c_str(), Irms);
|
ESP_LOGD(TAG, "'%s'", this->get_name().c_str(), irms_);
|
||||||
ESP_LOGD(TAG, " Amps=%.2fA", Irms);
|
ESP_LOGD(TAG, " Amps=%.2fA", irms_);
|
||||||
ESP_LOGD(TAG, " Watts=%.0fW", Irms * 230.0);
|
|
||||||
|
|
||||||
this->publish_state(Irms);
|
this->publish_state(irms_);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef ARDUINO_ARCH_ESP8266
|
#ifdef ARDUINO_ARCH_ESP8266
|
||||||
|
@ -32,8 +32,8 @@ class CTClampSensor : public sensor::Sensor, public PollingComponent {
|
|||||||
uint32_t sample_size_;
|
uint32_t sample_size_;
|
||||||
double supply_voltage_;
|
double supply_voltage_;
|
||||||
|
|
||||||
int sampleI;
|
int sample_i_;
|
||||||
double Irms,filteredI,offsetI,sumI,sqI;
|
double irms_,filtered_i_,offset_i_,sum_i_,sq_i_;
|
||||||
|
|
||||||
#ifdef ARDUINO_ARCH_ESP32
|
#ifdef ARDUINO_ARCH_ESP32
|
||||||
#define ADC_BITS 12
|
#define ADC_BITS 12
|
||||||
|
Loading…
x
Reference in New Issue
Block a user