-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closure Dimension server cluster code #2
base: feature/closure_dimension_cluster_xml_zap_code_generation
Are you sure you want to change the base?
Changes from all commits
5f9695e
a68b358
ffb66b4
defdbbf
15afbe9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,228 @@ | ||
/** | ||
* | ||
* Copyright (c) 2025 Project CHIP Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
/** | ||
* @file Cross-platform API to handle cluster-specific logic for the valve configuration and control cluster on a single endpoint. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "closure-dimension-delegate.h" | ||
#include "closure-dimension-matter-context.h" | ||
#include "closure-dimension-cluster-objects.h" | ||
|
||
namespace chip { | ||
namespace app { | ||
namespace Clusters { | ||
namespace ClosureDimension { | ||
|
||
struct ClusterConformance | ||
{ | ||
inline bool HasFeature(Feature feature) const { return featureMap & to_underlying(feature); } | ||
uint32_t featureMap; | ||
bool supportsOverflow; | ||
Comment on lines
+35
to
+36
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should always set a default value. |
||
bool Valid() const | ||
{ | ||
bool supportsRotation = HasFeature(Feature::kRotation); | ||
bool supportsMotionLatching = HasFeature(Feature::kMotionLatching); | ||
if (supportsOverflow && !(supportsRotation || supportsMotionLatching)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
{ | ||
ChipLogError(Zcl, | ||
"Invalid Valve configuration and control conformance - Overflow is not supported without Rotation or MotionLatching features"); | ||
return false; | ||
} | ||
return true; | ||
} | ||
}; | ||
|
||
struct ClusterState | ||
{ | ||
GenericCurrentStruct current; | ||
GenericTargetStruct target; | ||
Percent100ths resolution = 0; | ||
Percent100ths stepValue = 0; | ||
ClosureUnitEnum unit = ClosureUnitEnum::kMillimeter; | ||
Structs::UnitRangeStruct::Type unitRange; | ||
Structs::RangePercent100thsStruct::Type limitRange; | ||
TranslationDirectionEnum translationDirection = TranslationDirectionEnum::kBackward; | ||
RotationAxisEnum rotationAxis = RotationAxisEnum::kBottom; | ||
OverflowEnum overflow = OverflowEnum::kBottomInside; | ||
ModulationTypeEnum modulationType = ModulationTypeEnum::kOpacity; | ||
}; | ||
|
||
class ClusterLogic | ||
{ | ||
public: | ||
/** | ||
* @brief Instantiates a ClusterLogic class. The caller maintains ownership of the driver and the context, | ||
* but provides them for use by the ClusterLogic class. | ||
*/ | ||
ClusterLogic(DelegateBase & clusterDriver, MatterContext & matterContext) : | ||
mClusterDriver(clusterDriver), mMatterContext(matterContext) | ||
{ | ||
(void) mClusterDriver; | ||
} | ||
|
||
const ClusterState & GetState() { return mState; } | ||
|
||
const ClusterConformance & GetConformance() { return mConformance; } | ||
|
||
|
||
/** | ||
* @brief Validates the conformance and performs initialization | ||
* @param [in] conformance cluster conformance | ||
* @return Returns CHIP_ERROR_INCORRECT_STATE if the cluster has already been initialized, | ||
* Returns CHIP_ERROR_INVALID_DEVICE_DESCRIPTOR if the conformance is incorrect. | ||
* Returns CHIP_NO_ERROR on succesful initialization. | ||
*/ | ||
CHIP_ERROR Init(const ClusterConformance & conformance); | ||
|
||
/** | ||
* @brief Set Current. | ||
* @param[in] current Current Position, Latching and/or Speed. | ||
* @return CHIP_NO_ERROR if set was successful. | ||
*/ | ||
CHIP_ERROR SetCurrent(GenericCurrentStruct & current); | ||
|
||
/** | ||
sabollim-silabs marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* @brief Set Target. | ||
* @param[in] target Target Position, Latching and/or Speed. | ||
* @return CHIP_NO_ERROR if set was successful. | ||
*/ | ||
CHIP_ERROR SetTarget(GenericTargetStruct & target); | ||
|
||
/** | ||
* @brief Set Resolution. | ||
* @param[in] resolution Minimal acceptable change of Position fields of attributes. | ||
* @return CHIP_NO_ERROR if set was successful. | ||
*/ | ||
CHIP_ERROR SetResolution(const Percent100ths resolution); | ||
|
||
/** | ||
* @brief Set StepValue. | ||
* @param[in] stepValue One step value for Step command | ||
* @return CHIP_NO_ERROR if set was successful. | ||
*/ | ||
CHIP_ERROR SetStepValue(const Percent100ths stepValue); | ||
|
||
/** | ||
* @brief Set Unit. | ||
* @param[in] unit Unit related to the Positioning. | ||
* @return CHIP_NO_ERROR if set was successful. | ||
*/ | ||
CHIP_ERROR SetUnit(const ClosureUnitEnum unit); | ||
|
||
/** | ||
* @brief Set UnitRange. | ||
* @param[in] unitRange Minimum and Maximum values expressed by positioning following the unit. | ||
* @return CHIP_NO_ERROR if set was successful. | ||
*/ | ||
CHIP_ERROR SetUnitRange(Structs::UnitRangeStruct::Type & unitRange); | ||
|
||
/** | ||
* @brief Set LimitRange. | ||
* @param[in] limitRange Range of possible values for the position field in Current attribute. | ||
* @return CHIP_NO_ERROR if set was successful. | ||
*/ | ||
CHIP_ERROR SetLimitRange(Structs::RangePercent100thsStruct::Type & limitRange); | ||
|
||
/** | ||
* @brief Set TranslationDirection. | ||
* @param[in] translationDirection Direction of the translation. | ||
* @return CHIP_NO_ERROR if set was successful. | ||
*/ | ||
CHIP_ERROR SetTranslationDirection(const TranslationDirectionEnum translationDirection); | ||
|
||
/** | ||
* @brief Set RotationAxis. | ||
* @param[in] rotationAxis Axis of the rotation. | ||
* @return CHIP_NO_ERROR if set was successful. | ||
*/ | ||
CHIP_ERROR SetRotationAxis(const RotationAxisEnum rotationAxis); | ||
|
||
/** | ||
* @brief Set Overflow. | ||
* @param[in] overflow Overflow related to Rotation. | ||
* @return CHIP_NO_ERROR if set was successful. | ||
*/ | ||
CHIP_ERROR SetOverflow(const OverflowEnum overflow); | ||
|
||
/** | ||
* @brief Set ModulationType. | ||
* @param[in] modulationType Modulation type. | ||
* @return CHIP_NO_ERROR if set was successful. | ||
*/ | ||
CHIP_ERROR SetModulationType(const ModulationTypeEnum modulationType); | ||
|
||
// All Get functions: | ||
// Return CHIP_ERROR_INCORRECT_STATE if the class has not been initialized. | ||
// Return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE if the attribute is not supported by the conformance. | ||
// Otherwise return CHIP_NO_ERROR and set the input parameter value to the current cluster state value | ||
CHIP_ERROR GetCurrent(GenericCurrentStruct & current); | ||
CHIP_ERROR GetTarget(GenericTargetStruct & target); | ||
CHIP_ERROR GetResolution(Percent100ths & resolution); | ||
CHIP_ERROR GetStepValue(Percent100ths & stepValue); | ||
CHIP_ERROR GetUnit(ClosureUnitEnum & unit); | ||
CHIP_ERROR GetUnitRange(DataModel::Nullable<Structs::UnitRangeStruct::Type> & unitRange); | ||
CHIP_ERROR GetLimitRange(Structs::RangePercent100thsStruct::Type & limitRange); | ||
CHIP_ERROR GetTranslationDirection(TranslationDirectionEnum & translationDirection); | ||
CHIP_ERROR GetRotationAxis(RotationAxisEnum & rotationAxis); | ||
CHIP_ERROR GetOverflow(OverflowEnum & overflow); | ||
CHIP_ERROR GetModulationType(ModulationTypeEnum & modulationType); | ||
CHIP_ERROR GetFeatureMap(Attributes::FeatureMap::TypeInfo::Type & featureMap); | ||
CHIP_ERROR GetClusterRevision(Attributes::ClusterRevision::TypeInfo::Type & clusterRevision); | ||
|
||
/** | ||
* @brief Calls delegate HandleSetTarget function after validating the parameters | ||
* @param [in] position target position | ||
* @param [in] latch Target latch | ||
* @param [in] speed Target speed | ||
* @return Returns CHIP_ERROR_INCORRECT_STATE if the class has not been initialized. | ||
* Returns CHIP_ERROR_INVALID_ARGUMENT if the input values are out is out of range | ||
* Returns CHIP_ERROR_INVALID_DEVICE_DESCRIPTOR if the conformance is incorrect. | ||
* Returns CHIP_NO_ERROR on succesful initialization. | ||
*/ | ||
Protocols::InteractionModel::Status HandleSetTargetCommand(Optional<Percent100ths> position, Optional<TargetLatchEnum> latch, Optional<Globals::ThreeLevelAutoEnum> speed); | ||
|
||
/** | ||
* @brief Calls delegate HandleStep function after validating the parameters | ||
* @param [in] direction step direction | ||
* @param [in] numberOfSteps Number of steps | ||
* @param [in] speed step speed | ||
* @return Returns CHIP_ERROR_INCORRECT_STATE if the class has not been initialized. | ||
* Returns CHIP_ERROR_INVALID_ARGUMENT if the input values are out is out of range | ||
* Returns CHIP_ERROR_INVALID_DEVICE_DESCRIPTOR if the conformance is incorrect. | ||
* Returns CHIP_NO_ERROR on succesful initialization. | ||
*/ | ||
Protocols::InteractionModel::Status HandleStepCommand(StepDirectionEnum direction, uint16_t numberOfSteps, Optional<Globals::ThreeLevelAutoEnum> speed); | ||
|
||
private: | ||
// This cluster implements version 1 of the valve cluster. Do not change this revision without updating | ||
// the cluster to implement the newest features. | ||
static constexpr Attributes::ClusterRevision::TypeInfo::Type kClusterRevision = 1u; | ||
|
||
bool mInitialized; | ||
ClusterState mState; | ||
ClusterConformance mConformance; | ||
DelegateBase & mClusterDriver; | ||
MatterContext & mMatterContext; | ||
}; | ||
|
||
} // namespace ClosureDimension | ||
} // namespace Clusters | ||
} // namespace app | ||
} // namespace chip | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/* | ||
* | ||
* Copyright (c) 2025 Project CHIP Authors | ||
* All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <app-common/zap-generated/cluster-objects.h> | ||
|
||
namespace chip { | ||
namespace app { | ||
namespace Clusters { | ||
namespace ClosureDimension { | ||
|
||
/** | ||
* Structure represents the current struct of a closure dimension cluster derivation instance. | ||
*/ | ||
struct GenericCurrentStruct : public Structs::CurrentStruct::Type | ||
{ | ||
GenericCurrentStruct(Optional<Percent100ths> positionValue = NullOptional, | ||
Optional<LatchingEnum> latchingValue = NullOptional, | ||
Optional<Globals::ThreeLevelAutoEnum> speedValue = NullOptional) | ||
{ | ||
Set(positionValue, latchingValue, speedValue); | ||
} | ||
|
||
GenericCurrentStruct(const GenericCurrentStruct & current) { *this = current; } | ||
|
||
GenericCurrentStruct & operator=(const GenericCurrentStruct & current) | ||
{ | ||
Set(current.position, current.latching, current.speed); | ||
return *this; | ||
} | ||
|
||
void Set(Optional<Percent100ths> positioningValue = NullOptional, Optional<LatchingEnum> latchingValue = NullOptional, | ||
Optional<Globals::ThreeLevelAutoEnum> speedValue = NullOptional) | ||
{ | ||
position = positioningValue; | ||
latching = latchingValue; | ||
speed = speedValue; | ||
} | ||
|
||
bool operator==(const Structs::CurrentStruct::Type & rhs) const | ||
{ | ||
return position == rhs.position && latching == rhs.latching && speed == rhs.speed; | ||
} | ||
|
||
bool operator!=(const Structs::CurrentStruct::Type & rhs) const | ||
{ | ||
return position != rhs.position || latching != rhs.latching || speed != rhs.speed; | ||
} | ||
}; | ||
|
||
/** | ||
* Structure represents the target struct of a closure dimension cluster derivation instance. | ||
*/ | ||
struct GenericTargetStruct : public Structs::TargetStruct::Type | ||
{ | ||
GenericTargetStruct(Optional<Percent100ths> positionValue = NullOptional, | ||
Optional<TargetLatchEnum> latchValue = NullOptional, | ||
Optional<Globals::ThreeLevelAutoEnum> speedValue = NullOptional) | ||
{ | ||
Set(positionValue, latchValue, speedValue); | ||
} | ||
|
||
GenericTargetStruct(const GenericTargetStruct & target) { *this = target; } | ||
|
||
GenericTargetStruct & operator=(const GenericTargetStruct & target) | ||
{ | ||
Set(target.position, target.latch, target.speed); | ||
return *this; | ||
} | ||
|
||
void Set(Optional<Percent100ths> positionValue = NullOptional, Optional<TargetLatchEnum> latchValue = NullOptional, | ||
Optional<Globals::ThreeLevelAutoEnum> speedValue = NullOptional) | ||
{ | ||
position = positionValue; | ||
latch = latchValue; | ||
speed = speedValue; | ||
} | ||
|
||
bool operator==(const Structs::TargetStruct::Type & rhs) const | ||
{ | ||
return position == rhs.position && latch == rhs.latch && speed == rhs.speed; | ||
} | ||
|
||
bool operator!=(const Structs::TargetStruct::Type & rhs) const | ||
{ | ||
return position != rhs.position && latch != rhs.latch && speed != rhs.speed; | ||
} | ||
}; | ||
} // namespace ClosureDimension | ||
} // namespace Clusters | ||
} // namespace app | ||
} // namespace chip |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do you keep a var
supportsOverflow
but not the others, HasFeature can be used for all of them no?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The overflow attribute is mandatory with the Rotation feature and optional with MotionLatching feature.
It is the device's responsibility to specify whether this attribute is supported. The values will be set using Clusterconformance struct.