Add factor parameter to inc/dec action functions

The factor parameter is used to correctly determine the increase or
decrease speed delta based on sensor inputs that have a scale. To get
the net speed delta change, the factor is applied to the difference in
sensor value and the defined state at which a speed change should be
requested.

Change-Id: I2aaa8f6b294b38d1f38238593dd851c3a205eb7a
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
diff --git a/control/actions.hpp b/control/actions.hpp
index ebdff60..167149b 100644
--- a/control/actions.hpp
+++ b/control/actions.hpp
@@ -252,6 +252,7 @@
  * request that new target speed.
  *
  * @param[in] state - State to compare the group's property value to
+ * @param[in] factor - Factor to apply to the calculated net delta
  * @param[in] speedDelta - Speed delta of the group
  *
  * @return Lambda function
@@ -259,17 +260,17 @@
  * a new target speed with that increase for the zone.
  */
 template <typename T>
-auto set_net_increase_speed(T&& state, uint64_t speedDelta)
+auto set_net_increase_speed(T&& state, T&& factor, uint64_t speedDelta)
 {
     return [speedDelta,
+            factor = std::forward<T>(factor),
             state = std::forward<T>(state)](auto& zone, auto& group)
     {
-        T singleDelta = 1;
         auto netDelta = zone.getIncSpeedDelta();
         std::for_each(
             group.begin(),
             group.end(),
-            [&zone, &state, &speedDelta, &singleDelta, &netDelta](
+            [&zone, &state, &factor, &speedDelta, &netDelta](
                 auto const& entry)
             {
                 try
@@ -282,12 +283,16 @@
                     // state types for comparison
                     if (value >= state)
                     {
-                        // Increase by at least a single delta
+                        // Increase by at least a single delta(factor)
                         // to attempt bringing under 'state'
-                        auto delta = std::max((value - state), singleDelta);
-                        // Increase is the difference times
-                        // the given speed delta
-                        netDelta = std::max(netDelta, delta * speedDelta);
+                        auto delta = std::max(
+                            (value - state),
+                            factor);
+                        // Increase is the factor applied to the
+                        // difference times the given speed delta
+                        netDelta = std::max(
+                            netDelta,
+                            (delta/factor) * speedDelta);
                     }
                 }
                 catch (const std::out_of_range& oore)
@@ -308,6 +313,7 @@
  * request that speed change occur on the next decrease interval.
  *
  * @param[in] state - State to compare the group's property value to
+ * @param[in] factor - Factor to apply to the calculated net delta
  * @param[in] speedDelta - Speed delta of the group
  *
  * @return Lambda function
@@ -315,16 +321,17 @@
  * a new target speed with that decrease for the zone.
  */
 template <typename T>
-auto set_net_decrease_speed(T&& state, uint64_t speedDelta)
+auto set_net_decrease_speed(T&& state, T&& factor, uint64_t speedDelta)
 {
     return [speedDelta,
+            factor = std::forward<T>(factor),
             state = std::forward<T>(state)](auto& zone, auto& group)
     {
         auto netDelta = zone.getDecSpeedDelta();
         std::for_each(
             group.begin(),
             group.end(),
-            [&zone, &state, &speedDelta, &netDelta](auto const& entry)
+            [&zone, &state, &factor, &speedDelta, &netDelta](auto const& entry)
             {
                 try
                 {
@@ -338,14 +345,15 @@
                     {
                         if (netDelta == 0)
                         {
-                            netDelta = (state - value) * speedDelta;
+                            netDelta = ((state - value)/factor) * speedDelta;
                         }
                         else
                         {
-                            // Decrease is the difference times
-                            // the given speed delta
-                            netDelta = std::min(netDelta,
-                                                (state - value) * speedDelta);
+                            // Decrease is the factor applied to the
+                            // difference times the given speed delta
+                            netDelta = std::min(
+                                netDelta,
+                                ((state - value)/factor) * speedDelta);
                         }
                     }
                 }