diff options
Diffstat (limited to 'control')
-rw-r--r-- | control/actions.hpp | 38 |
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); } } } |