From 31641aeffa5c8ad538e01fefadf5be6a272560ee Mon Sep 17 00:00:00 2001 From: Maxim Prokhorov Date: Fri, 1 May 2020 23:55:55 +0300 Subject: [PATCH] emon: default indexed methods to method without argument --- code/espurna/sensor.cpp | 10 ++--- code/espurna/sensors/BaseEmonSensor.h | 59 ++++++++++++++++++++------- 2 files changed, 50 insertions(+), 19 deletions(-) diff --git a/code/espurna/sensor.cpp b/code/espurna/sensor.cpp index 4dfb6a2e..f64d870d 100644 --- a/code/espurna/sensor.cpp +++ b/code/espurna/sensor.cpp @@ -1858,19 +1858,19 @@ void _sensorInit() { for (size_t index = 0; index < sensor->countDevices(); ++index) { sensor->resetEnergy(index, _sensorEnergyTotal(index)); sensor->setCurrentRatio( - get_ratio("pwrRatioC", index, sensor->getCurrentRatio(index)) + index, get_ratio("pwrRatioC", index, sensor->getCurrentRatio(index)) ); sensor->setVoltageRatio( - get_ratio("pwrRatioV", index, sensor->getVoltageRatio(index)) + index, get_ratio("pwrRatioV", index, sensor->getVoltageRatio(index)) ); sensor->setPowerRatio( - get_ratio("pwrRatioP", index, sensor->getPowerRatio(index)) + index, get_ratio("pwrRatioP", index, sensor->getPowerRatio(index)) ); sensor->setEnergyRatio( - get_ratio("pwrRatioE", index, sensor->getEnergyRatio(index)) + index, get_ratio("pwrRatioE", index, sensor->getEnergyRatio(index)) ); sensor->setVoltage( - get_ratio("pwrVoltage", index, sensor->getVoltage(index)) + index, get_ratio("pwrVoltage", index, sensor->getVoltage(index)) ); } diff --git a/code/espurna/sensors/BaseEmonSensor.h b/code/espurna/sensors/BaseEmonSensor.h index 9c12f006..d294929f 100644 --- a/code/espurna/sensors/BaseEmonSensor.h +++ b/code/espurna/sensors/BaseEmonSensor.h @@ -70,8 +70,15 @@ class BaseEmonSensor : public BaseSensor { // when sensor needs explicit mains voltage value virtual void setVoltage(double) {} - virtual double getVoltage() { return 0.0; } - virtual double getVoltage(unsigned char index) { return getVoltage(); } + virtual void setVoltage(unsigned char index, double value) { + setVoltage(value); + } + virtual double getVoltage() { + return 0.0; + } + virtual double getVoltage(unsigned char index) { + return getVoltage(); + } // when sensor implements ratios / multipliers virtual void setCurrentRatio(double) {} @@ -80,22 +87,46 @@ class BaseEmonSensor : public BaseSensor { virtual void setEnergyRatio(double) {} // when sensor implements ratios / multipliers - virtual void setCurrentRatio(unsigned char index, double) {} - virtual void setVoltageRatio(unsigned char index, double) {} - virtual void setPowerRatio(unsigned char index, double) {} - virtual void setEnergyRatio(unsigned char index, double) {} + virtual void setCurrentRatio(unsigned char index, double value) { + setCurrentRatio(value); + } + virtual void setVoltageRatio(unsigned char index, double value) { + setVoltageRatio(value); + } + virtual void setPowerRatio(unsigned char index, double value) { + setPowerRatio(value); + } + virtual void setEnergyRatio(unsigned char index, double value) { + setEnergyRatio(value); + } // when sensor implements a single device - virtual double getCurrentRatio() { return 0.0; } - virtual double getVoltageRatio() { return 0.0; } - virtual double getPowerRatio() { return 0.0; } - virtual double getEnergyRatio() { return 0.0; } + virtual double getCurrentRatio() { + return 0.0; + } + virtual double getVoltageRatio() { + return 0.0; + } + virtual double getPowerRatio() { + return 0.0; + } + virtual double getEnergyRatio() { + return 0.0; + } // when sensor implements more than one device - virtual double getCurrentRatio(unsigned char index) { return getCurrentRatio(); } - virtual double getVoltageRatio(unsigned char index) { return getCurrentRatio(); } - virtual double getPowerRatio(unsigned char index) { return getCurrentRatio(); } - virtual double getEnergyRatio(unsigned char index) { return getCurrentRatio(); } + virtual double getCurrentRatio(unsigned char index) { + return getCurrentRatio(); + } + virtual double getVoltageRatio(unsigned char index) { + return getVoltageRatio(); + } + virtual double getPowerRatio(unsigned char index) { + return getPowerRatio(); + } + virtual double getEnergyRatio(unsigned char index) { + return getEnergyRatio(); + } virtual void expectedCurrent(double value) {} virtual void expectedVoltage(unsigned int value) {}