dbus-sensors: PwmSensor math types cleanup
Cleaned up types during math to avoid precision loss.
Integer pwmMax and associated constants now double.
Avoid floating-point comparison, convert to int first.
Corrected rounding from float to int.
Property setter now ignores floating-point NaN.
Rounding done more consistently and correctly now. In some edge
cases, the fan PWM setting will be different from what it was
before, because rounding is now proper instead of truncating.
Tested: Swept fans from 0.0 to 100.0 percent, stepping by 0.1 each
time, to exercise all values between 0 and 255. Behavior now seems
more correct to me. Also set NaN, and it was properly ignored.
Also tested on the uint64_t interface, swept from 0 to 255,
each value mapped cleanly to equivalent floating-point value.
Not tested on "PSU" fans. These are a special case, as the integers
in the underlying file range from 0 to 100, not 0 to 255. The
original logic to handle these remains unchanged, however.
Signed-off-by: Josh Lehan <krellan@google.com>
Change-Id: Ibc9ad978c1567bb2e7116e00d84e43b4ae22e664
diff --git a/include/PwmSensor.hpp b/include/PwmSensor.hpp
index 69a35c4..1f8a467 100644
--- a/include/PwmSensor.hpp
+++ b/include/PwmSensor.hpp
@@ -22,7 +22,7 @@
std::shared_ptr<sdbusplus::asio::dbus_interface> sensorInterface;
std::shared_ptr<sdbusplus::asio::dbus_interface> controlInterface;
std::shared_ptr<sdbusplus::asio::dbus_interface> association;
- size_t pwmMax;
+ double pwmMax;
void setValue(uint32_t value);
uint32_t getValue(bool errThrow = true);
};