Respect polarity config on input signals

Previously the polarity setting was (in all but one case) only being
used in setting outputs driven by the daemon.  With this change we also
take it into account in determining whether input signals are asserted
or deasserted.

Signed-off-by: Zev Weiss <zev@bewilderbeest.net>
Change-Id: Ifd326e9c64de144dc45d217be5212329a5f3d242
diff --git a/src/power_control.cpp b/src/power_control.cpp
index bba7088..a4ef078 100644
--- a/src/power_control.cpp
+++ b/src/power_control.cpp
@@ -2014,15 +2014,17 @@
 
 static void psPowerOKHandler(bool state)
 {
-    Event powerControlEvent = state ? Event::psPowerOKAssert
-                                    : Event::psPowerOKDeAssert;
+    Event powerControlEvent = (state == powerOkConfig.polarity)
+                                  ? Event::psPowerOKAssert
+                                  : Event::psPowerOKDeAssert;
     sendPowerControlEvent(powerControlEvent);
 }
 
 static void sioPowerGoodHandler(bool state)
 {
-    Event powerControlEvent = state ? Event::sioPowerGoodAssert
-                                    : Event::sioPowerGoodDeAssert;
+    Event powerControlEvent = (state == sioPwrGoodConfig.polarity)
+                                  ? Event::sioPowerGoodAssert
+                                  : Event::sioPowerGoodDeAssert;
     sendPowerControlEvent(powerControlEvent);
 }
 
@@ -2034,14 +2036,17 @@
 
 static void sioS5Handler(bool state)
 {
-    Event powerControlEvent = state ? Event::sioS5DeAssert : Event::sioS5Assert;
+    Event powerControlEvent = (state == sioS5Config.polarity)
+                                  ? Event::sioS5Assert
+                                  : Event::sioS5DeAssert;
     sendPowerControlEvent(powerControlEvent);
 }
 
 static void powerButtonHandler(bool state)
 {
-    powerButtonIface->set_property("ButtonPressed", !state);
-    if (!state)
+    bool asserted = state == powerButtonConfig.polarity;
+    powerButtonIface->set_property("ButtonPressed", asserted);
+    if (asserted)
     {
         powerButtonPressLog();
         if (!powerButtonMask)
@@ -2058,8 +2063,9 @@
 
 static void resetButtonHandler(bool state)
 {
-    resetButtonIface->set_property("ButtonPressed", !state);
-    if (!state)
+    bool asserted = state == resetButtonConfig.polarity;
+    resetButtonIface->set_property("ButtonPressed", asserted);
+    if (asserted)
     {
         resetButtonPressLog();
         if (!resetButtonMask)
@@ -2210,8 +2216,10 @@
     {
         return;
     }
-    nmiButtonIface->set_property("ButtonPressed", !state);
-    if (!state)
+
+    bool asserted = state == nmiButtonConfig.polarity;
+    nmiButtonIface->set_property("ButtonPressed", asserted);
+    if (asserted)
     {
         nmiButtonPressLog();
         if (nmiButtonMasked)
@@ -2227,7 +2235,8 @@
 
 static void idButtonHandler(bool state)
 {
-    idButtonIface->set_property("ButtonPressed", !state);
+    bool asserted = state == idButtonConfig.polarity;
+    idButtonIface->set_property("ButtonPressed", asserted);
 }
 
 static void pltRstHandler(bool pltRst)
@@ -2279,7 +2288,8 @@
 
 static void postCompleteHandler(bool state)
 {
-    if (!state)
+    bool asserted = state == postCompleteConfig.polarity;
+    if (asserted)
     {
         sendPowerControlEvent(Event::postCompleteAssert);
         setOperatingSystemState(OperatingSystemStateStage::Standby);