diff options
-rw-r--r-- | control/actions.cpp | 18 | ||||
-rw-r--r-- | control/actions.hpp | 12 | ||||
-rw-r--r-- | control/zone.cpp | 16 | ||||
-rw-r--r-- | control/zone.hpp | 19 |
4 files changed, 60 insertions, 5 deletions
diff --git a/control/actions.cpp b/control/actions.cpp index b1eb9be..6eda2a6 100644 --- a/control/actions.cpp +++ b/control/actions.cpp @@ -81,6 +81,24 @@ Action call_actions_based_on_timer(Timer&& tConf, std::vector<Action>&& actions) }; } +void default_floor_on_missing_owner(Zone& zone, const Group& group) +{ + auto services = zone.getGroupServices(&group); + auto defFloor = std::any_of( + services.begin(), + services.end(), + [](const auto& s) + { + return !std::get<hasOwnerPos>(s); + }); + if (defFloor) + { + zone.setFloor(zone.getDefFloor()); + } + // Update fan control floor change allowed + zone.setFloorChangeAllow(&group, !defFloor); +} + void set_request_speed_base_with_max(control::Zone& zone, const Group& group) { diff --git a/control/actions.hpp b/control/actions.hpp index fff8250..4d2c5c3 100644 --- a/control/actions.hpp +++ b/control/actions.hpp @@ -30,6 +30,18 @@ Action call_actions_based_on_timer( std::vector<Action>&& actions); /** + * @brief An action that sets the floor to the default fan floor speed + * @details Sets the fan floor to the defined default fan floor speed when a + * service associated to the given group has terminated. Once all services + * are functional and providing the sensors again, the fan floor is allowed + * to be set normally. + * + * @param[in] zone - Zone containing fans + * @param[in] group - Group of sensors to determine services' states + */ +void default_floor_on_missing_owner(Zone& zone, const Group& group); + +/** * @brief An action to set the request speed base * @details A new target speed is determined using a speed delta being added * or subtracted, for increases or decrease respectively, from a base speed. diff --git a/control/zone.cpp b/control/zone.cpp index 018f594..418b3ba 100644 --- a/control/zone.cpp +++ b/control/zone.cpp @@ -147,11 +147,19 @@ void Zone::setServiceOwner(const Group* group, void Zone::setFloor(uint64_t speed) { - _floorSpeed = speed; - // Floor speed above target, update target to floor speed - if (_targetSpeed < _floorSpeed) + // Check all entries are set to allow floor to be set + auto pred = [](auto const& entry) {return entry.second;}; + auto setFloor = std::all_of(_floorChange.begin(), + _floorChange.end(), + pred); + if (setFloor) { - requestSpeedIncrease(_floorSpeed - _targetSpeed); + _floorSpeed = speed; + // Floor speed above target, update target to floor speed + if (_targetSpeed < _floorSpeed) + { + requestSpeedIncrease(_floorSpeed - _targetSpeed); + } } } diff --git a/control/zone.hpp b/control/zone.hpp index 1fdeaf2..fa3ed82 100644 --- a/control/zone.hpp +++ b/control/zone.hpp @@ -78,6 +78,17 @@ class Zone void setActiveAllow(const Group* group, bool isActiveAllow); /** + * @brief Sets the floor change allowed state + * + * @param[in] group - A group that affects floor changes + * @param[in] isAllow - Allow state according to group + */ + inline void setFloorChangeAllow(const Group* group, bool isAllow) + { + _floorChange[*(group)] = isAllow; + } + + /** * @brief Sets a given object's property value * * @param[in] object - Name of the object containing the property @@ -231,7 +242,8 @@ class Zone /** * @brief Set the floor speed to the given speed and increase target - * speed to the floor when target is below floor. + * speed to the floor when target is below floor where floor changes + * are allowed. * * @param[in] speed - Speed to set the floor to */ @@ -454,6 +466,11 @@ class Zone std::map<const Group, bool> _active; /** + * @brief Map of floor change allowed by groups + */ + std::map<const Group, bool> _floorChange; + + /** * @brief Map of group service names */ std::map<const Group, std::vector<Service>> _services; |