|
| 1 | +/* |
| 2 | + * |
| 3 | + * Copyright (c) 2020 Project CHIP Authors |
| 4 | + * |
| 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | + * you may not use this file except in compliance with the License. |
| 7 | + * You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +#pragma once |
| 19 | + |
| 20 | +#include "WindowCoveringDelegate.h" |
| 21 | +#include <app-common/zap-generated/cluster-objects.h> |
| 22 | +#include <app/AttributeAccessInterfaceRegistry.h> |
| 23 | +#include <app/util/af-types.h> |
| 24 | +#include <protocols/interaction_model/StatusCode.h> |
| 25 | + |
| 26 | +#include <app/data-model/Nullable.h> |
| 27 | + |
| 28 | +static constexpr chip::Percent100ths WC_PERCENT100THS_MIN_OPEN = 0; |
| 29 | +static constexpr chip::Percent100ths WC_PERCENT100THS_MAX_CLOSED = 10000; |
| 30 | +static constexpr chip::Percent100ths WC_PERCENT100THS_MIDDLE = 5000; |
| 31 | +static constexpr chip::Percent100ths WC_PERCENT100THS_COEF = 100; |
| 32 | + |
| 33 | +namespace chip { |
| 34 | +namespace app { |
| 35 | +namespace Clusters { |
| 36 | +namespace WindowCovering { |
| 37 | + |
| 38 | +typedef DataModel::Nullable<Percent> NPercent; |
| 39 | +typedef DataModel::Nullable<Percent100ths> NPercent100ths; |
| 40 | +typedef DataModel::Nullable<uint16_t> NAbsolute; |
| 41 | +typedef Optional<Percent> OPercent; |
| 42 | +typedef Optional<Percent100ths> OPercent100ths; |
| 43 | + |
| 44 | +// Match directly with OperationalStatus 2 bits Fields |
| 45 | +enum class OperationalState : uint8_t |
| 46 | +{ |
| 47 | + Stall = 0x00, // currently not moving |
| 48 | + MovingUpOrOpen = 0x01, // is currently opening |
| 49 | + MovingDownOrClose = 0x02, // is currently closing |
| 50 | + Reserved = 0x03, // dont use |
| 51 | +}; |
| 52 | +static_assert(sizeof(OperationalState) == sizeof(uint8_t), "OperationalState Size is not correct"); |
| 53 | + |
| 54 | +// Declare Position Limit Status |
| 55 | +enum class LimitStatus : uint8_t |
| 56 | +{ |
| 57 | + Intermediate = 0x00, |
| 58 | + IsUpOrOpen = 0x01, |
| 59 | + IsDownOrClose = 0x02, |
| 60 | + Inverted = 0x03, |
| 61 | + IsPastUpOrOpen = 0x04, |
| 62 | + IsPastDownOrClose = 0x05, |
| 63 | +}; |
| 64 | +static_assert(sizeof(LimitStatus) == sizeof(uint8_t), "LimitStatus Size is not correct"); |
| 65 | + |
| 66 | +struct AbsoluteLimits |
| 67 | +{ |
| 68 | + uint16_t open; |
| 69 | + uint16_t closed; |
| 70 | +}; |
| 71 | + |
| 72 | +/** |
| 73 | + * @brief Window Covering Attribute Access Interface. |
| 74 | + */ |
| 75 | +class WindowCoverAttrAccess : public AttributeAccessInterface |
| 76 | +{ |
| 77 | +public: |
| 78 | + // Register for the Window Covering cluster on all endpoints. |
| 79 | + WindowCoverAttrAccess() : AttributeAccessInterface(Optional<EndpointId>::Missing(), WindowCovering::Id) {} |
| 80 | + |
| 81 | + CHIP_ERROR Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) override; |
| 82 | +}; |
| 83 | + |
| 84 | +bool HasFeature(chip::EndpointId endpoint, Feature feature); |
| 85 | +bool HasFeaturePaLift(chip::EndpointId endpoint); |
| 86 | +bool HasFeaturePaTilt(chip::EndpointId endpoint); |
| 87 | + |
| 88 | +void TypeSet(chip::EndpointId endpoint, Type type); |
| 89 | +Type TypeGet(chip::EndpointId endpoint); |
| 90 | + |
| 91 | +void ConfigStatusPrint(const chip::BitMask<ConfigStatus> & configStatus); |
| 92 | +void ConfigStatusSet(chip::EndpointId endpoint, const chip::BitMask<ConfigStatus> & status); |
| 93 | +chip::BitMask<ConfigStatus> ConfigStatusGet(chip::EndpointId endpoint); |
| 94 | +void ConfigStatusUpdateFeatures(chip::EndpointId endpoint); |
| 95 | + |
| 96 | +void OperationalStatusPrint(const chip::BitMask<OperationalStatus> & opStatus); |
| 97 | +void OperationalStatusSet(chip::EndpointId endpoint, chip::BitMask<OperationalStatus> newStatus); |
| 98 | +chip::BitMask<OperationalStatus> OperationalStatusGet(chip::EndpointId endpoint); |
| 99 | +void OperationalStateSet(chip::EndpointId endpoint, const chip::BitMask<OperationalStatus> field, OperationalState state); |
| 100 | +OperationalState OperationalStateGet(chip::EndpointId endpoint, const chip::BitMask<OperationalStatus> field); |
| 101 | + |
| 102 | +OperationalState ComputeOperationalState(uint16_t target, uint16_t current); |
| 103 | +OperationalState ComputeOperationalState(NPercent100ths target, NPercent100ths current); |
| 104 | +Percent100ths ComputePercent100thsStep(OperationalState direction, Percent100ths previous, Percent100ths delta); |
| 105 | + |
| 106 | +void EndProductTypeSet(chip::EndpointId endpoint, EndProductType type); |
| 107 | +EndProductType EndProductTypeGet(chip::EndpointId endpoint); |
| 108 | + |
| 109 | +void ModePrint(const chip::BitMask<Mode> & mode); |
| 110 | +void ModeSet(chip::EndpointId endpoint, chip::BitMask<Mode> & mode); |
| 111 | +chip::BitMask<Mode> ModeGet(chip::EndpointId endpoint); |
| 112 | + |
| 113 | +void SafetyStatusSet(chip::EndpointId endpoint, const chip::BitMask<SafetyStatus> & status); |
| 114 | +chip::BitMask<SafetyStatus> SafetyStatusGet(chip::EndpointId endpoint); |
| 115 | + |
| 116 | +LimitStatus CheckLimitState(uint16_t position, AbsoluteLimits limits); |
| 117 | + |
| 118 | +bool IsPercent100thsValid(Percent100ths percent100ths); |
| 119 | +bool IsPercent100thsValid(NPercent100ths npercent100ths); |
| 120 | + |
| 121 | +uint16_t Percent100thsToValue(AbsoluteLimits limits, Percent100ths relative); |
| 122 | + |
| 123 | +uint16_t LiftToPercent100ths(chip::EndpointId endpoint, uint16_t lift); |
| 124 | +uint16_t Percent100thsToLift(chip::EndpointId endpoint, uint16_t percent100ths); |
| 125 | +void LiftPositionSet(chip::EndpointId endpoint, NPercent100ths position); |
| 126 | + |
| 127 | +uint16_t TiltToPercent100ths(chip::EndpointId endpoint, uint16_t tilt); |
| 128 | +uint16_t Percent100thsToTilt(chip::EndpointId endpoint, uint16_t percent100ths); |
| 129 | +void TiltPositionSet(chip::EndpointId endpoint, NPercent100ths position); |
| 130 | + |
| 131 | +Protocols::InteractionModel::Status GetMotionLockStatus(chip::EndpointId endpoint); |
| 132 | + |
| 133 | +/** |
| 134 | + * @brief PostAttributeChange is called when an Attribute is modified. |
| 135 | + * |
| 136 | + * The method is called by MatterWindowCoveringClusterServerAttributeChangedCallback |
| 137 | + * to update cluster attributes values. If the application overrides MatterWindowCoveringClusterServerAttributeChangedCallback, |
| 138 | + * it should call the PostAttributeChange on its own. |
| 139 | + * |
| 140 | + * @param[in] endpoint |
| 141 | + * @param[in] attributeId |
| 142 | + */ |
| 143 | +void PostAttributeChange(chip::EndpointId endpoint, chip::AttributeId attributeId); |
| 144 | + |
| 145 | +void SetDefaultDelegate(EndpointId endpoint, WindowCoveringDelegate * delegate); |
| 146 | + |
| 147 | +} // namespace WindowCovering |
| 148 | +} // namespace Clusters |
| 149 | +} // namespace app |
| 150 | +} // namespace chip |
0 commit comments