Skip to content

Commit 1b622ea

Browse files
authored
[CodeDriven conversion] PR#1 Renames and code movement WindowCovering Cluster (#71944)
* File renames and code movement * Address gemini comments * Add alias for Delegate for backwards compatibility
1 parent c4cbcf4 commit 1b622ea

9 files changed

Lines changed: 248 additions & 202 deletions

File tree

examples/all-clusters-app/linux/WindowCoveringManager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ namespace app {
2424
namespace Clusters {
2525
namespace WindowCovering {
2626

27-
class WindowCoveringManager : public Delegate
27+
class WindowCoveringManager : public WindowCoveringDelegate
2828
{
2929
public:
3030
void Init(chip::EndpointId endpoint);

examples/chef/common/clusters/window-covering/chef-window-covering.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ namespace WindowCovering {
3131
/** @brief
3232
* Defines methods for implementing application-specific logic for the WindowCovering Cluster.
3333
*/
34-
class ChefDelegate : public Delegate
34+
class ChefDelegate : public WindowCoveringDelegate
3535
{
3636
public:
3737
/**

src/app/clusters/window-covering-server/WindowCoveringCluster.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ static_assert(kWindowCoveringDelegateTableSize <= kEmberInvalidEndpointIndex, "W
5151

5252
WindowCoverAttrAccess gAttrAccess;
5353

54-
Delegate * gDelegateTable[kWindowCoveringDelegateTableSize] = { nullptr };
54+
WindowCoveringDelegate * gDelegateTable[kWindowCoveringDelegateTableSize] = { nullptr };
5555

56-
Delegate * GetDelegate(EndpointId endpoint)
56+
WindowCoveringDelegate * GetDelegate(EndpointId endpoint)
5757
{
5858
uint16_t ep =
5959
emberAfGetClusterServerEndpointIndex(endpoint, WindowCovering::Id, MATTER_DM_WINDOW_COVERING_CLUSTER_SERVER_ENDPOINT_COUNT);
@@ -606,7 +606,7 @@ Status GetMotionLockStatus(chip::EndpointId endpoint)
606606
return Status::Success;
607607
}
608608

609-
void SetDefaultDelegate(EndpointId endpoint, Delegate * delegate)
609+
void SetDefaultDelegate(EndpointId endpoint, WindowCoveringDelegate * delegate)
610610
{
611611
uint16_t ep =
612612
emberAfGetClusterServerEndpointIndex(endpoint, WindowCovering::Id, MATTER_DM_WINDOW_COVERING_CLUSTER_SERVER_ENDPOINT_COUNT);
@@ -658,7 +658,7 @@ bool emberAfWindowCoveringClusterUpOrOpenCallback(app::CommandHandler * commandO
658658
Attributes::TargetPositionTiltPercent100ths::Set(endpoint, WC_PERCENT100THS_MIN_OPEN);
659659
}
660660

661-
Delegate * delegate = GetDelegate(endpoint);
661+
WindowCoveringDelegate * delegate = GetDelegate(endpoint);
662662
if (delegate)
663663
{
664664
if (HasFeature(endpoint, Feature::kPositionAwareLift))
@@ -709,7 +709,7 @@ bool emberAfWindowCoveringClusterDownOrCloseCallback(app::CommandHandler * comma
709709
}
710710
commandObj->AddStatus(commandPath, Status::Success);
711711

712-
Delegate * delegate = GetDelegate(endpoint);
712+
WindowCoveringDelegate * delegate = GetDelegate(endpoint);
713713
if (delegate)
714714
{
715715
if (HasFeature(endpoint, Feature::kPositionAwareLift))
@@ -751,7 +751,7 @@ bool emberAfWindowCoveringClusterStopMotionCallback(app::CommandHandler * comman
751751

752752
bool changeTarget = true;
753753

754-
Delegate * delegate = GetDelegate(endpoint);
754+
WindowCoveringDelegate * delegate = GetDelegate(endpoint);
755755
if (delegate)
756756
{
757757
CHIP_ERROR err = delegate->HandleStopMotion();
@@ -812,7 +812,7 @@ bool emberAfWindowCoveringClusterGoToLiftValueCallback(app::CommandHandler * com
812812
if (HasFeature(endpoint, Feature::kAbsolutePosition) && HasFeaturePaLift(endpoint))
813813
{
814814
Attributes::TargetPositionLiftPercent100ths::Set(endpoint, LiftToPercent100ths(endpoint, liftValue));
815-
Delegate * delegate = GetDelegate(endpoint);
815+
WindowCoveringDelegate * delegate = GetDelegate(endpoint);
816816
if (delegate)
817817
{
818818
LogErrorOnFailure(delegate->HandleMovement(WindowCoveringType::Lift));
@@ -856,7 +856,7 @@ bool emberAfWindowCoveringClusterGoToLiftPercentageCallback(app::CommandHandler
856856
if (IsPercent100thsValid(percent100ths))
857857
{
858858
Attributes::TargetPositionLiftPercent100ths::Set(endpoint, percent100ths);
859-
Delegate * delegate = GetDelegate(endpoint);
859+
WindowCoveringDelegate * delegate = GetDelegate(endpoint);
860860
if (delegate)
861861
{
862862
LogErrorOnFailure(delegate->HandleMovement(WindowCoveringType::Lift));
@@ -904,7 +904,7 @@ bool emberAfWindowCoveringClusterGoToTiltValueCallback(app::CommandHandler * com
904904
if (HasFeature(endpoint, Feature::kAbsolutePosition) && HasFeaturePaTilt(endpoint))
905905
{
906906
Attributes::TargetPositionTiltPercent100ths::Set(endpoint, TiltToPercent100ths(endpoint, tiltValue));
907-
Delegate * delegate = GetDelegate(endpoint);
907+
WindowCoveringDelegate * delegate = GetDelegate(endpoint);
908908
if (delegate)
909909
{
910910
LogErrorOnFailure(delegate->HandleMovement(WindowCoveringType::Tilt));
@@ -948,7 +948,7 @@ bool emberAfWindowCoveringClusterGoToTiltPercentageCallback(app::CommandHandler
948948
if (IsPercent100thsValid(percent100ths))
949949
{
950950
Attributes::TargetPositionTiltPercent100ths::Set(endpoint, percent100ths);
951-
Delegate * delegate = GetDelegate(endpoint);
951+
WindowCoveringDelegate * delegate = GetDelegate(endpoint);
952952
if (delegate)
953953
{
954954
LogErrorOnFailure(delegate->HandleMovement(WindowCoveringType::Tilt));
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
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
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
*
3+
* Copyright (c) 2026 Project CHIP Authors
4+
* All rights reserved.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
#pragma once
20+
21+
#include <app-common/zap-generated/cluster-objects.h>
22+
#include <app/CommandResponseHelper.h>
23+
24+
namespace chip {
25+
namespace app {
26+
namespace Clusters {
27+
namespace WindowCovering {
28+
29+
// Window Covering Type
30+
enum class WindowCoveringType : uint8_t
31+
{
32+
Lift = 0x00, // window coverings that lift up and down or slide left to right
33+
Tilt = 0x01, // window coverings with vertical or horizontal strips
34+
Reserved = 0x02, // dont use
35+
};
36+
37+
/** @brief
38+
* Defines methods for implementing application-specific logic for the WindowCovering Cluster.
39+
*/
40+
class WindowCoveringDelegate
41+
{
42+
public:
43+
/**
44+
* @brief
45+
* This method adjusts window covering position so the physical lift/slide and tilt is at the target
46+
* open/up position set before calling this method. This will happen as fast as possible.
47+
*
48+
* @param[in] type window covering type.
49+
*
50+
* @return CHIP_NO_ERROR On success.
51+
* @return Other Value indicating it failed to adjust window covering position.
52+
*/
53+
virtual CHIP_ERROR HandleMovement(WindowCoveringType type) = 0;
54+
55+
/**
56+
* @brief
57+
* This method stops any adjusting to the physical tilt and lift/slide that is currently occurring.
58+
*
59+
* @return CHIP_NO_ERROR On success.
60+
* @return Other Value indicating it failed to stop any adjusting to the physical tilt and lift/slide that is currently
61+
* occurring..
62+
*/
63+
virtual CHIP_ERROR HandleStopMotion() = 0;
64+
65+
virtual ~WindowCoveringDelegate() = default;
66+
67+
void SetEndpoint(chip::EndpointId endpoint) { mEndpoint = endpoint; }
68+
69+
protected:
70+
EndpointId mEndpoint = 0;
71+
};
72+
73+
// alias for backwards compatibility
74+
using Delegate = WindowCoveringDelegate;
75+
76+
} // namespace WindowCovering
77+
} // namespace Clusters
78+
} // namespace app
79+
} // namespace chip

src/app/clusters/window-covering-server/app_config_dependent_sources.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
TARGET_SOURCES(
1717
${APP_TARGET}
1818
PRIVATE
19+
"${CLUSTER_DIR}/WindowCoveringCluster.h"
20+
"${CLUSTER_DIR}/WindowCoveringDelegate.h"
1921
"${CLUSTER_DIR}/window-covering-delegate.h"
2022
"${CLUSTER_DIR}/WindowCoveringCluster.cpp"
2123
"${CLUSTER_DIR}/window-covering-server.h"

src/app/clusters/window-covering-server/app_config_dependent_sources.gni

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
# limitations under the License.
1414
app_config_dependent_sources = [
1515
"WindowCoveringCluster.cpp",
16+
"WindowCoveringCluster.h",
17+
"WindowCoveringDelegate.h",
1618
"window-covering-delegate.h",
1719
"window-covering-server.h",
1820
]

0 commit comments

Comments
 (0)