Correct ADC sensors max reading

Set ADC max reading to be reference voltage 1.8Volt.
Calculate maxReading from it. This fixes threshold hysteresis.

Tested:
Use sensor override to trigger alarm and verify that
de-assert happens when sensor reading back to normal.
Without the change, the de-assert never happens.
Example:
    busctl set-property xyz.openbmc_project.ADCSensor /xyz/openbmc_project/sensors/voltage/ABC_CPU1 xyz.openbmc_project.Sensor.Value Value d 1.348
    intel-obmc adcsensor[412]: Sensor ABC_CPU1 high threshold 1.301 assert: value 1.348 raw data 1244
    intel-obmc adcsensor[412]: Sensor ABC_CPU1 high threshold 1.263 assert: value 1.348 raw data 1244
    intel-obmc ipmid[242]: thresholdChanged: Assert
    intel-obmc ipmid[242]: thresholdChanged: Assert
    intel-obmc sel-logger[288]: ABC_CPU1 sensor crossed a critical high threshold going high. Reading=1.348000 Threshold=1.301000.
    intel-obmc sel-logger[288]: ABC_CPU1 sensor crossed a warning high threshold going high. Reading=1.348000 Threshold=1.263000.
    intel-obmc ipmid[242]: thresholdChanged: deassert
    intel-obmc ipmid[242]: thresholdChanged: deassert
    intel-obmc sel-logger[288]: ABC_CPU1 sensor crossed a critical high threshold going low. Reading=1.244000 Threshold=1.301000.
    intel-obmc sel-logger[288]: ABC_CPU1 sensor crossed a warning high threshold going low. Reading=1.244000 Threshold=1.263000.

Also ran "ipmitool sensor list" and varified ADCSensor values are correct
    A P12V PSU SCALE | 12.096     | Volts      | ok    | na        | 10.647    | 10.962    | 13.104    | 13.482    | na
    P1V8 PCH         | 1.805      | Volts      | ok    | na        | 1.645     | 1.701     | 1.908     | 1.965     | na
    P3V3             | 3.320      | Volts      | ok    | na        | 2.976     | 3.062     | 3.543     | 3.646     | na
    P3VBAT           | 3.074      | Volts      | ok    | na        | 2.141     | 2.459     | 3.265     | 3.286     | na
    P12V AUX         | 12.096     | Volts      | ok    | na        | 10.647    | 10.962    | 13.104    | 13.482    | na
    P105 PCH AUX     | 1.058      | Volts      | ok    | na        | 0.966     | 0.994     | 1.108     | 1.136     | na
    PVCCIN CPU1      | 1.824      | Volts      | ok    | na        | 1.372     | 1.419     | 2.087     | 2.153     | na
    PVCCIO CPU1      | 1.030      | Volts      | ok    | na        | 0.731     | 0.753     | 1.157     | 1.193     | na
    PVDQ ABC CPU1    | 1.243      | Volts      | ok    | na        | 1.101     | 1.136     | 1.264     | 1.299     | na
    PVDQ DEF CPU1    | 1.243      | Volts      | ok    | na        | 1.101     | 1.136     | 1.264     | 1.299     | na
    PVNN PCH AUX     | 0.902      | Volts      | ok    | na        | 0.781     | 0.809     | 1.051     | 1.079     | na

Signed-off-by: Zhikui Ren <zhikui.ren@intel.com>
Change-Id: If0dd132f963253172862d1b5e2b96c3bbedcdfd4
diff --git a/src/ADCSensor.cpp b/src/ADCSensor.cpp
index 7afb2ab..fe600d7 100644
--- a/src/ADCSensor.cpp
+++ b/src/ADCSensor.cpp
@@ -41,9 +41,9 @@
 // scaling factor from hwmon
 static constexpr unsigned int sensorScaleFactor = 1000;
 
-static constexpr double roundFactor = 10000; // 3 decimal places
-static constexpr double maxReading = 20;
-static constexpr double minReading = 0;
+static constexpr double roundFactor = 10000;     // 3 decimal places
+static constexpr double maxVoltageReading = 1.8; // pre sensor scaling
+static constexpr double minVoltageReading = 0;
 
 ADCSensor::ADCSensor(const std::string& path,
                      sdbusplus::asio::object_server& objectServer,
@@ -55,7 +55,8 @@
                      std::optional<BridgeGpio>&& bridgeGpio) :
     Sensor(boost::replace_all_copy(sensorName, " ", "_"),
            std::move(_thresholds), sensorConfiguration,
-           "xyz.openbmc_project.Configuration.ADC", maxReading, minReading,
+           "xyz.openbmc_project.Configuration.ADC",
+           maxVoltageReading / scaleFactor, minVoltageReading / scaleFactor,
            conn, readState),
     std::enable_shared_from_this<ADCSensor>(), objServer(objectServer),
     inputDev(io, open(path.c_str(), O_RDONLY)), waitTimer(io), path(path),
@@ -79,7 +80,6 @@
     }
     association = objectServer.add_interface(
         "/xyz/openbmc_project/sensors/voltage/" + name, association::interface);
-
     setInitialProperties(conn);
 }
 
diff --git a/src/ADCSensorMain.cpp b/src/ADCSensorMain.cpp
index 9024eb9..473d8a1 100644
--- a/src/ADCSensorMain.cpp
+++ b/src/ADCSensorMain.cpp
@@ -210,6 +210,11 @@
                 {
                     scaleFactor = std::visit(VariantToFloatVisitor(),
                                              findScaleFactor->second);
+                    // scaleFactor is used in division
+                    if (scaleFactor == 0.0f)
+                    {
+                        scaleFactor = 1.0;
+                    }
                 }
 
                 auto findPowerOn = baseConfiguration->second.find("PowerState");