summaryrefslogtreecommitdiffstats
path: root/control
diff options
context:
space:
mode:
authorMatthew Barth <msbarth@us.ibm.com>2017-08-14 11:07:46 -0500
committerMatthew Barth <msbarth@us.ibm.com>2017-08-16 09:47:01 -0500
commit172f393696b967f23e1d166fc7eb952a11994c5d (patch)
treed4b35553bcd918edb64e8230f33e08fc454537f6 /control
parentbe25083d3d74310ecd1024a3e7986341f4d3c549 (diff)
downloadphosphor-fan-presence-172f393696b967f23e1d166fc7eb952a11994c5d.tar.gz
phosphor-fan-presence-172f393696b967f23e1d166fc7eb952a11994c5d.zip
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>
Diffstat (limited to 'control')
-rw-r--r--control/actions.hpp38
1 files changed, 23 insertions, 15 deletions
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 @@ auto set_ceiling_from_average_sensor_value(
* 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 @@ auto set_ceiling_from_average_sensor_value(
* 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 @@ auto set_net_increase_speed(T&& state, uint64_t speedDelta)
// 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 @@ auto set_net_increase_speed(T&& state, uint64_t speedDelta)
* 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 @@ auto set_net_increase_speed(T&& state, uint64_t speedDelta)
* 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 @@ auto set_net_decrease_speed(T&& state, uint64_t speedDelta)
{
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);
}
}
}
OpenPOWER on IntegriCloud