mirror of
https://github.com/xoseperez/espurna.git
synced 2026-03-04 15:34:19 +01:00
Fix early access bug to HLW8012 instance on HLW8012Sensor
This commit is contained in:
@@ -421,33 +421,36 @@ void _sensorConfigure() {
|
||||
}
|
||||
#endif // EMON_ANALOG_SUPPORT
|
||||
|
||||
// Force sensor to reload config
|
||||
_sensors[i]->begin();
|
||||
|
||||
#if HLW8012_SUPPORT
|
||||
if (_sensors[i]->getID() == SENSOR_HLW8012_ID) {
|
||||
|
||||
HLW8012Sensor * sensor = (HLW8012Sensor *) _sensors[i];
|
||||
|
||||
if (value = getSetting("pwrExpectedC", 0).toInt() == 0) {
|
||||
value = getSetting("pwrRatioC", 0).toFloat();
|
||||
if (value > 0) sensor->setCurrentRatio(value);
|
||||
} else {
|
||||
if (value = getSetting("pwrExpectedC", 0).toFloat()) {
|
||||
sensor->expectedCurrent(value);
|
||||
setSetting("pwrRatioC", sensor->getCurrentRatio());
|
||||
} else {
|
||||
value = getSetting("pwrRatioC", 0).toFloat();
|
||||
if (value > 0) sensor->setCurrentRatio(value);
|
||||
}
|
||||
|
||||
if (value = getSetting("pwrExpectedV", 0).toInt() == 0) {
|
||||
value = getSetting("pwrRatioV", 0).toFloat();
|
||||
if (value > 0) sensor->setVoltageRatio(value);
|
||||
} else {
|
||||
if (value = getSetting("pwrExpectedV", 0).toInt()) {
|
||||
sensor->expectedVoltage(value);
|
||||
setSetting("pwrRatioV", sensor->getVoltageRatio());
|
||||
} else {
|
||||
value = getSetting("pwrRatioV", 0).toFloat();
|
||||
if (value > 0) sensor->setVoltageRatio(value);
|
||||
}
|
||||
|
||||
if (value = getSetting("pwrExpectedP", 0).toInt() == 0) {
|
||||
value = getSetting("pwrRatioP", 0).toFloat();
|
||||
if (value > 0) sensor->setPowerRatio(value);
|
||||
} else {
|
||||
if (value = getSetting("pwrExpectedP", 0).toInt()) {
|
||||
sensor->expectedPower(value);
|
||||
setSetting("pwrRatioP", sensor->getPowerRatio());
|
||||
} else {
|
||||
value = getSetting("pwrRatioP", 0).toFloat();
|
||||
if (value > 0) sensor->setPowerRatio(value);
|
||||
}
|
||||
|
||||
if (getSetting("pwrResetCalibration", 0).toInt() == 1) {
|
||||
@@ -459,10 +462,6 @@ void _sensorConfigure() {
|
||||
|
||||
}
|
||||
#endif // HLW8012_SUPPORT
|
||||
|
||||
// Force sensor to reload config
|
||||
_sensors[i]->begin();
|
||||
|
||||
}
|
||||
|
||||
// General sensor settings
|
||||
|
||||
@@ -198,6 +198,8 @@ static void (*_sensor_isrs[16])() = {
|
||||
};
|
||||
|
||||
void BaseSensor::attach(BaseSensor * instance, unsigned char gpio, unsigned char mode) {
|
||||
if ((6 <= gpio) && (gpio <=11)) return;
|
||||
if (gpio >= 16) return;
|
||||
detach(gpio);
|
||||
if (_sensor_isrs[gpio]) {
|
||||
_isr_sensor_instance[gpio] = instance;
|
||||
@@ -207,6 +209,8 @@ void BaseSensor::attach(BaseSensor * instance, unsigned char gpio, unsigned char
|
||||
}
|
||||
|
||||
void BaseSensor::detach(unsigned char gpio) {
|
||||
if ((6 <= gpio) && (gpio <=11)) return;
|
||||
if (gpio >= 16) return;
|
||||
if (_isr_sensor_instance[gpio]) {
|
||||
detachInterrupt(gpio);
|
||||
_isr_sensor_instance[gpio]->detached(gpio);
|
||||
|
||||
@@ -22,6 +22,7 @@ class HLW8012Sensor : public BaseSensor {
|
||||
HLW8012Sensor(): BaseSensor() {
|
||||
_count = 7;
|
||||
_sensor_id = SENSOR_HLW8012_ID;
|
||||
_hlw8012 = new HLW8012();
|
||||
}
|
||||
|
||||
~HLW8012Sensor() {
|
||||
@@ -119,9 +120,6 @@ class HLW8012Sensor : public BaseSensor {
|
||||
// Defined outside the class body
|
||||
void begin() {
|
||||
|
||||
if (_hlw8012) delete _hlw8012;
|
||||
_hlw8012 = new HLW8012();
|
||||
|
||||
// Initialize HLW8012
|
||||
// void begin(unsigned char cf_pin, unsigned char cf1_pin, unsigned char sel_pin, unsigned char currentWhen = HIGH, bool use_interrupts = false, unsigned long pulse_timeout = PULSE_TIMEOUT);
|
||||
// * cf_pin, cf1_pin and sel_pin are GPIOs to the HLW8012 IC
|
||||
|
||||
Reference in New Issue
Block a user