mirror of
https://github.com/esphome/esphome.git
synced 2024-11-28 12:46:22 +01:00
Use lower case _ style for member variables
This commit is contained in:
parent
49baaa50c7
commit
0924817844
@ -60,19 +60,19 @@ int32_t BL0910::read_register(uint8_t addr) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
float BL0910::get_voltage(uint8_t channel) {
|
float BL0910::get_voltage(uint8_t channel) {
|
||||||
return ((float) read_register(BL0910_REG_RMS[channel])) / this->voltage_reference[channel];
|
return ((float) read_register(BL0910_REG_RMS[channel])) / this->voltage_reference_[channel];
|
||||||
}
|
}
|
||||||
|
|
||||||
float BL0910::get_current(uint8_t channel) {
|
float BL0910::get_current(uint8_t channel) {
|
||||||
return ((float) read_register(BL0910_REG_RMS[channel])) / this->current_reference[channel];
|
return ((float) read_register(BL0910_REG_RMS[channel])) / this->current_reference_[channel];
|
||||||
}
|
}
|
||||||
|
|
||||||
float BL0910::get_power(uint8_t channel) {
|
float BL0910::get_power(uint8_t channel) {
|
||||||
return ((float) read_register(BL0910_REG_WATT[channel])) / this->power_reference[channel];
|
return ((float) read_register(BL0910_REG_WATT[channel])) / this->power_reference_[channel];
|
||||||
}
|
}
|
||||||
|
|
||||||
float BL0910::get_energy(uint8_t channel) {
|
float BL0910::get_energy(uint8_t channel) {
|
||||||
return ((float) read_register(BL0910_REG_CF_CNT[channel])) / this->energy_reference[channel];
|
return ((float) read_register(BL0910_REG_CF_CNT[channel])) / this->energy_reference_[channel];
|
||||||
}
|
}
|
||||||
|
|
||||||
float BL0910::get_frequency(void) {
|
float BL0910::get_frequency(void) {
|
||||||
@ -96,23 +96,23 @@ void BL0910::update() {
|
|||||||
static int i = 0;
|
static int i = 0;
|
||||||
static float freq = 50.0;
|
static float freq = 50.0;
|
||||||
if (i < NUM_CHANNELS) {
|
if (i < NUM_CHANNELS) {
|
||||||
if (voltage_sensor[i])
|
if (voltage_sensor_[i])
|
||||||
voltage_sensor[i]->publish_state(get_voltage(i));
|
voltage_sensor_[i]->publish_state(get_voltage(i));
|
||||||
if (current_sensor[i])
|
if (current_sensor_[i])
|
||||||
current_sensor[i]->publish_state(get_current(i));
|
current_sensor_[i]->publish_state(get_current(i));
|
||||||
if (power_sensor[i])
|
if (power_sensor_[i])
|
||||||
power_sensor[i]->publish_state(get_power(i));
|
power_sensor_[i]->publish_state(get_power(i));
|
||||||
if (energy_sensor[i])
|
if (energy_sensor_[i])
|
||||||
energy_sensor[i]->publish_state(get_energy(i));
|
energy_sensor_[i]->publish_state(get_energy(i));
|
||||||
if (power_factor_sensor[i])
|
if (power_factor_sensor_[i])
|
||||||
power_factor_sensor[i]->publish_state(get_powerfactor(i, freq));
|
power_factor_sensor_[i]->publish_state(get_powerfactor(i, freq));
|
||||||
i++;
|
i++;
|
||||||
} else {
|
} else {
|
||||||
freq = get_frequency();
|
freq = get_frequency();
|
||||||
if (frequency_sensor)
|
if (frequency_sensor_)
|
||||||
frequency_sensor->publish_state(freq);
|
frequency_sensor_->publish_state(freq);
|
||||||
if (temperature_sensor)
|
if (temperature_sensor_)
|
||||||
temperature_sensor->publish_state(get_temperature());
|
temperature_sensor_->publish_state(get_temperature());
|
||||||
i = 0;
|
i = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -130,38 +130,38 @@ void BL0910::setup() {
|
|||||||
void BL0910::dump_config() { // NOLINT(readability-function-cognitive-complexity)
|
void BL0910::dump_config() { // NOLINT(readability-function-cognitive-complexity)
|
||||||
ESP_LOGCONFIG(TAG, "BL0910:");
|
ESP_LOGCONFIG(TAG, "BL0910:");
|
||||||
for (int i = 0; i < NUM_CHANNELS; i++) {
|
for (int i = 0; i < NUM_CHANNELS; i++) {
|
||||||
if (voltage_sensor[i]) {
|
if (voltage_sensor_[i]) {
|
||||||
char buf[20];
|
char buf[20];
|
||||||
snprintf(buf, sizeof(buf), "Voltage %d", i + 1);
|
snprintf(buf, sizeof(buf), "Voltage %d", i + 1);
|
||||||
LOG_SENSOR("", buf, voltage_sensor[i]);
|
LOG_SENSOR("", buf, voltage_sensor_[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (current_sensor[i]) {
|
if (current_sensor_[i]) {
|
||||||
char buf[20];
|
char buf[20];
|
||||||
snprintf(buf, sizeof(buf), "Current %d", i + 1);
|
snprintf(buf, sizeof(buf), "Current %d", i + 1);
|
||||||
LOG_SENSOR("", buf, current_sensor[i]);
|
LOG_SENSOR("", buf, current_sensor_[i]);
|
||||||
}
|
}
|
||||||
if (power_sensor[i]) {
|
if (power_sensor_[i]) {
|
||||||
char buf[20];
|
char buf[20];
|
||||||
snprintf(buf, sizeof(buf), "Power %d", i + 1);
|
snprintf(buf, sizeof(buf), "Power %d", i + 1);
|
||||||
LOG_SENSOR("", buf, power_sensor[i]);
|
LOG_SENSOR("", buf, power_sensor_[i]);
|
||||||
}
|
}
|
||||||
if (energy_sensor[i]) {
|
if (energy_sensor_[i]) {
|
||||||
char buf[20];
|
char buf[20];
|
||||||
snprintf(buf, sizeof(buf), "Energy %d", i + 1);
|
snprintf(buf, sizeof(buf), "Energy %d", i + 1);
|
||||||
LOG_SENSOR("", buf, energy_sensor[i]);
|
LOG_SENSOR("", buf, energy_sensor_[i]);
|
||||||
}
|
}
|
||||||
if (power_factor_sensor[i]) {
|
if (power_factor_sensor_[i]) {
|
||||||
char buf[20];
|
char buf[20];
|
||||||
snprintf(buf, sizeof(buf), "Power Factor %d", i + 1);
|
snprintf(buf, sizeof(buf), "Power Factor %d", i + 1);
|
||||||
LOG_SENSOR("", buf, power_factor_sensor[i]);
|
LOG_SENSOR("", buf, power_factor_sensor_[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (this->frequency_sensor) {
|
if (this->frequency_sensor_) {
|
||||||
LOG_SENSOR("", "Frequency", this->frequency_sensor);
|
LOG_SENSOR("", "Frequency", this->frequency_sensor_);
|
||||||
}
|
}
|
||||||
if (this->temperature_sensor) {
|
if (this->temperature_sensor_) {
|
||||||
LOG_SENSOR("", "Temperature", this->temperature_sensor);
|
LOG_SENSOR("", "Temperature", this->temperature_sensor_);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,26 +19,26 @@ class BL0910 : public PollingComponent,
|
|||||||
// Sensor index is 1-based to match the BL0910 documentation
|
// Sensor index is 1-based to match the BL0910 documentation
|
||||||
// but the array is 0-based to save memory and simplify code
|
// but the array is 0-based to save memory and simplify code
|
||||||
void set_voltage_sensor(sensor::Sensor *voltage_sensor, int index, float voltage_reference) {
|
void set_voltage_sensor(sensor::Sensor *voltage_sensor, int index, float voltage_reference) {
|
||||||
this->voltage_sensor[index - 1] = voltage_sensor;
|
this->voltage_sensor_[index - 1] = voltage_sensor;
|
||||||
this->voltage_reference[index - 1] = voltage_reference;
|
this->voltage_reference_[index - 1] = voltage_reference;
|
||||||
}
|
}
|
||||||
void set_current_sensor(sensor::Sensor *current_sensor, int index, float current_reference) {
|
void set_current_sensor(sensor::Sensor *current_sensor, int index, float current_reference) {
|
||||||
this->current_sensor[index - 1] = current_sensor;
|
this->current_sensor_[index - 1] = current_sensor;
|
||||||
this->current_reference[index - 1] = current_reference;
|
this->current_reference_[index - 1] = current_reference;
|
||||||
}
|
}
|
||||||
void set_power_sensor(sensor::Sensor *power_sensor, int index, float power_reference) {
|
void set_power_sensor(sensor::Sensor *power_sensor, int index, float power_reference) {
|
||||||
this->power_sensor[index - 1] = power_sensor;
|
this->power_sensor_[index - 1] = power_sensor;
|
||||||
this->power_reference[index - 1] = power_reference;
|
this->power_reference_[index - 1] = power_reference;
|
||||||
}
|
}
|
||||||
void set_energy_sensor(sensor::Sensor *energy_sensor, int index, float energy_reference) {
|
void set_energy_sensor(sensor::Sensor *energy_sensor, int index, float energy_reference) {
|
||||||
this->energy_sensor[index - 1] = energy_sensor;
|
this->energy_sensor_[index - 1] = energy_sensor;
|
||||||
this->energy_reference[index - 1] = energy_reference;
|
this->energy_reference_[index - 1] = energy_reference;
|
||||||
}
|
}
|
||||||
void set_power_factor_sensor(sensor::Sensor *power_factor_sensor, int index) {
|
void set_power_factor_sensor(sensor::Sensor *power_factor_sensor, int index) {
|
||||||
this->power_factor_sensor[index - 1] = power_factor_sensor;
|
this->power_factor_sensor_[index - 1] = power_factor_sensor;
|
||||||
}
|
}
|
||||||
void set_frequency_sensor(sensor::Sensor *frequency_sensor) { this->frequency_sensor = frequency_sensor; }
|
void set_frequency_sensor(sensor::Sensor *frequency_sensor) { this->frequency_sensor_ = frequency_sensor; }
|
||||||
void set_temperature_sensor(sensor::Sensor *temperature_sensor) { this->temperature_sensor = temperature_sensor; }
|
void set_temperature_sensor(sensor::Sensor *temperature_sensor) { this->temperature_sensor_ = temperature_sensor; }
|
||||||
|
|
||||||
void loop() override;
|
void loop() override;
|
||||||
|
|
||||||
@ -47,20 +47,20 @@ class BL0910 : public PollingComponent,
|
|||||||
void dump_config() override;
|
void dump_config() override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
sensor::Sensor *voltage_sensor[NUM_CHANNELS] = {};
|
sensor::Sensor *voltage_sensor_[NUM_CHANNELS] = {};
|
||||||
sensor::Sensor *current_sensor[NUM_CHANNELS] = {};
|
sensor::Sensor *current_sensor_[NUM_CHANNELS] = {};
|
||||||
// NB This may be negative as the circuits is seemingly able to measure
|
// NB This may be negative as the circuits is seemingly able to measure
|
||||||
// power in both directions
|
// power in both directions
|
||||||
sensor::Sensor *power_sensor[NUM_CHANNELS] = {};
|
sensor::Sensor *power_sensor_[NUM_CHANNELS] = {};
|
||||||
sensor::Sensor *energy_sensor[NUM_CHANNELS] = {};
|
sensor::Sensor *energy_sensor_[NUM_CHANNELS] = {};
|
||||||
sensor::Sensor *power_factor_sensor[NUM_CHANNELS] = {};
|
sensor::Sensor *power_factor_sensor_[NUM_CHANNELS] = {};
|
||||||
sensor::Sensor *frequency_sensor{nullptr};
|
sensor::Sensor *frequency_sensor_{nullptr};
|
||||||
sensor::Sensor *temperature_sensor{nullptr};
|
sensor::Sensor *temperature_sensor_{nullptr};
|
||||||
|
|
||||||
float voltage_reference[NUM_CHANNELS] = {};
|
float voltage_reference_[NUM_CHANNELS] = {};
|
||||||
float current_reference[NUM_CHANNELS] = {};
|
float current_reference_[NUM_CHANNELS] = {};
|
||||||
float power_reference[NUM_CHANNELS] = {};
|
float power_reference_[NUM_CHANNELS] = {};
|
||||||
float energy_reference[NUM_CHANNELS] = {};
|
float energy_reference_[NUM_CHANNELS] = {};
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void write_register(uint8_t addr, uint32_t data) {
|
void write_register(uint8_t addr, uint32_t data) {
|
||||||
|
Loading…
Reference in New Issue
Block a user