Compute IIO reading from raw with offset and scale
For IIO RAW sensors we get a raw_value, an offset, and scale to
compute the value = (raw_value + offset) * scale, thus scale changes
from a divisor to a multiplier.
Tested: on Rainier and Everest the sensors function the same before
and after this commit is applied.
Signed-off-by: Bruce Mitchell <bruce.mitchell@linux.vnet.ibm.com>
Change-Id: I1f6658107ac4a44e622ce01ced39ee0ecf8ee48b
diff --git a/src/HwmonTempSensor.cpp b/src/HwmonTempSensor.cpp
index 667e517..9e2d845 100644
--- a/src/HwmonTempSensor.cpp
+++ b/src/HwmonTempSensor.cpp
@@ -31,7 +31,16 @@
#include <string>
#include <vector>
-static constexpr unsigned int sensorScaleFactor = 1000;
+// Temperatures are read in milli degrees Celsius, we need degrees Celsius.
+// Pressures are read in kilopascal, we need Pascals. On D-Bus for Open BMC
+// we use the International System of Units without prefixes.
+// Links to the kernel documentation:
+// https://www.kernel.org/doc/Documentation/hwmon/sysfs-interface
+// https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-bus-iio
+// For IIO RAW sensors we get a raw_value, an offset, and scale to compute
+// the value = (raw_value + offset) * scale
+static constexpr double sensorOffset = 0.0;
+static constexpr double sensorScale = 0.001;
static constexpr size_t warnAfterErrorCount = 10;
static constexpr double maxReading = 127;
@@ -142,7 +151,7 @@
try
{
rawValue = std::stod(response);
- double nvalue = rawValue / sensorScaleFactor;
+ double nvalue = (rawValue + sensorOffset) * sensorScale;
updateValue(nvalue);
}
catch (const std::invalid_argument&)