FanSensor: Add configurable min max

Allow Min and Max reading to be configured

Tested-by: Set a fan to a different Min and it worked.

Change-Id: Ibeebcaa9672d7a9cd9511c3845f5b317db8962c8
Signed-off-by: James Feist <james.feist@linux.intel.com>
diff --git a/src/FanMain.cpp b/src/FanMain.cpp
index 365fd90..121621d 100644
--- a/src/FanMain.cpp
+++ b/src/FanMain.cpp
@@ -124,9 +124,7 @@
         const char* baseType;
         const SensorData* sensorData = nullptr;
         const std::string* interfacePath = nullptr;
-        const std::pair<std::string, boost::container::flat_map<
-                                         std::string, BasicVariantType>>*
-            baseConfiguration = nullptr;
+        const SensorBaseConfiguration* baseConfiguration = nullptr;
         for (const std::pair<sdbusplus::message::object_path, SensorData>&
                  sensor : sensorConfigurations)
         {
@@ -263,10 +261,15 @@
             redundancy = systemRedundancy;
         }
 
+        constexpr double defaultMaxReading = 25000;
+        constexpr double defaultMinReading = 0;
+        auto limits = std::make_pair(defaultMinReading, defaultMaxReading);
+
+        findLimits(limits, baseConfiguration);
         tachSensors[sensorName] = std::make_unique<TachSensor>(
             path.string(), baseType, objectServer, dbusConnection,
             std::move(presenceSensor), redundancy, io, sensorName,
-            std::move(sensorThresholds), *interfacePath);
+            std::move(sensorThresholds), *interfacePath, limits);
     }
     std::vector<fs::path> pwms;
     if (!findFiles(fs::path("/sys/class/hwmon"), R"(pwm\d+)", pwms))
diff --git a/src/TachSensor.cpp b/src/TachSensor.cpp
index 63ced19..70d7d4c 100644
--- a/src/TachSensor.cpp
+++ b/src/TachSensor.cpp
@@ -31,9 +31,6 @@
 static constexpr unsigned int pwmPollMs = 500;
 static constexpr size_t warnAfterErrorCount = 10;
 
-static constexpr double maxReading = 25000;
-static constexpr double minReading = 0;
-
 TachSensor::TachSensor(const std::string &path, const std::string &objectType,
                        sdbusplus::asio::object_server &objectServer,
                        std::shared_ptr<sdbusplus::asio::connection> &conn,
@@ -41,10 +38,11 @@
                        const std::shared_ptr<RedundancySensor> &redundancy,
                        boost::asio::io_service &io, const std::string &fanName,
                        std::vector<thresholds::Threshold> &&_thresholds,
-                       const std::string &sensorConfiguration) :
+                       const std::string &sensorConfiguration,
+                       const std::pair<size_t, size_t> &limits) :
     Sensor(boost::replace_all_copy(fanName, " ", "_"), path,
-           std::move(_thresholds), sensorConfiguration, objectType, maxReading,
-           minReading),
+           std::move(_thresholds), sensorConfiguration, objectType,
+           limits.second, limits.first),
     objServer(objectServer), dbusConnection(conn),
     presence(std::move(presence)), redundancy(redundancy),
     inputDev(io, open(path.c_str(), O_RDONLY)), waitTimer(io), errCount(0)
diff --git a/src/Utils.cpp b/src/Utils.cpp
index 15fce73..e4de9e0 100644
--- a/src/Utils.cpp
+++ b/src/Utils.cpp
@@ -156,3 +156,26 @@
 
     return powerStatusOn;
 }
+
+// replaces limits if MinReading and MaxReading are found.
+void findLimits(std::pair<double, double>& limits,
+                const SensorBaseConfiguration* data)
+{
+    if (!data)
+    {
+        return;
+    }
+    auto maxFind = data->second.find("MaxReading");
+    auto minFind = data->second.find("MinReading");
+
+    if (minFind != data->second.end())
+    {
+        limits.first = sdbusplus::message::variant_ns::visit(
+            VariantToDoubleVisitor(), minFind->second);
+    }
+    if (maxFind != data->second.end())
+    {
+        limits.second = sdbusplus::message::variant_ns::visit(
+            VariantToDoubleVisitor(), maxFind->second);
+    }
+}
\ No newline at end of file