From 2dcb5ea748f99523c70971152a370ba9ec666245 Mon Sep 17 00:00:00 2001 From: Max Prokhorov Date: Sat, 18 Jul 2020 18:55:19 +0300 Subject: [PATCH] sns: revert "Power factor fixes" (#2304) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit d57eb0721b7096f9e08448eebab2597e8cb52491. We can use raw value as-is. While the lack of unit is true for the value represented as cos θ , we don't specifically have any other sensors using it as such. As comment suggest (huh), we want to express the thing as a percentage. --- code/espurna/sensors/BaseSensor.h | 3 ++- code/espurna/sensors/PZEM004TV30Sensor.h | 7 +++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/code/espurna/sensors/BaseSensor.h b/code/espurna/sensors/BaseSensor.h index ed81adcb..b1f8cd79 100644 --- a/code/espurna/sensors/BaseSensor.h +++ b/code/espurna/sensors/BaseSensor.h @@ -95,7 +95,8 @@ class BaseSensor { switch (type(index)) { case MAGNITUDE_TEMPERATURE: return sensor::Unit::Celcius; - case MAGNITUDE_HUMIDITY: + case MAGNITUDE_HUMIDITY: + case MAGNITUDE_POWER_FACTOR: return sensor::Unit::Percentage; case MAGNITUDE_PRESSURE: return sensor::Unit::Hectopascal; diff --git a/code/espurna/sensors/PZEM004TV30Sensor.h b/code/espurna/sensors/PZEM004TV30Sensor.h index 62f0a71b..4eee4c2f 100644 --- a/code/espurna/sensors/PZEM004TV30Sensor.h +++ b/code/espurna/sensors/PZEM004TV30Sensor.h @@ -362,8 +362,8 @@ class PZEM004TV30Sensor : public BaseEmonSensor { if (std::distance(it, end) >= 2) { value = (static_cast(*(it)) << 8) | static_cast(*(it + 1)); + it += 2; } - it += 2; return value; }; @@ -375,8 +375,8 @@ class PZEM004TV30Sensor : public BaseEmonSensor { | (static_cast(*(it + 3)) << 16)) | ((static_cast(*it) << 8) | static_cast(*(it + 1)))); + it += 4; } - it += 4; return value; }; @@ -400,9 +400,8 @@ class PZEM004TV30Sensor : public BaseEmonSensor { _frequency = take_2(); _frequency /= 10.0; - // - Power Factor: 2 bytes in 0.1% (we return %) + // - Power Factor: 2 bytes in 0.01 (we return %) _power_factor = take_2(); - _power_factor /= 100.0; // - Alarms: 2 bytes, (NOT IMPLEMENTED) // XXX: it seems it can only be either 0xffff or 0 for ON and OFF respectively