8000 [Silabs] [Closure] Set initial states for closure endpoints in 917 sample app by arun-silabs · Pull Request #39868 · project-chip/connectedhomeip · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[Silabs] [Closure] Set initial states for closure endpoints in 917 sample app #39868

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions examples/closure-app/silabs/include/ClosureManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,28 @@ class ClosureManager
*/
const Action_t & GetCurrentAction() const { return mCurrentAction; }

/**
* @brief Sets the initial state for the ClosureControlEndpoint.
*
* This method initializes the closure control instance with default values and configurations.
*
* @param closureControlEndpoint The ClosureControlEndpoint to be initialized.
*
* @return CHIP_ERROR Returns CHIP_NO_ERROR on success, or an error code if initialization fails.
*/
CHIP_ERROR SetClosureControlInitialState(chip::app::Clusters::ClosureControl::ClosureControlEndpoint & closureControlEndpoint);

/**
* @brief Sets the initial state for the ClosureDimensionEndpoint.
*
* This method initializes the closure panel instance with default values and configurations.
*
* @param closurePanelEndpoint The ClosureDimensionEndpoint to be initialized.
*
* @return CHIP_ERROR Returns CHIP_NO_ERROR on success, or an error code if initialization fails.
*/
CHIP_ERROR SetClosurePanelInitialState(chip::app::Clusters::ClosureDimension::ClosureDimensionEndpoint & closurePanelEndpoint);
private:
static ClosureManager sClosureMgr;

Expand Down
61 changes: 61 additions & 0 deletions examples/closure-app/silabs/src/ClosureManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

using namespace chip;
using namespace chip::app;
using namespace chip::app::DataModel;
using namespace chip::app::Clusters;
using namespace chip::DeviceLayer;
using namespace chip::app::Clusters::ClosureControl;
Expand Down Expand Up @@ -105,9 +106,69 @@ void ClosureManager::Init()
SetTagList(/* endpoint= */ 2, Span<const Clusters::Descriptor::Structs::SemanticTagStruct::Type>(kEndpoint2TagList));
SetTagList(/* endpoint= */ 3, Span<const Clusters::Descriptor::Structs::SemanticTagStruct::Type>(kEndpoint3TagList));

// Set Initial state for Closure endpoints
VerifyOrDie(SetClosureControlInitialState(mClosureEndpoint1) == CHIP_NO_ERROR);
ChipLogProgress(AppServer, "Initial state for Closure Control Endpoint set successfully");
VerifyOrDie(SetClosurePanelInitialState(mClosurePanelEndpoint2) == CHIP_NO_ERROR);
ChipLogProgress(AppServer, "Initial state for Closure Panel Endpoint 2 set successfully");
VerifyOrDie(SetClosurePanelInitialState(mClosurePanelEndpoint3) == CHIP_NO_ERROR);
ChipLogProgress(AppServer, "Initial state for Closure Panel Endpoint 3 set successfully");

DeviceLayer::PlatformMgr().UnlockChipStack();
}

CHIP_ERROR ClosureManager::SetClosureControlInitialState(ClosureControlEndpoint & closureControlEndpoint)
{
ChipLogProgress(AppServer, "ClosureControlEndpoint SetInitialState");
ReturnErrorOnFailure(closureControlEndpoint.GetLogic().SetCountdownTimeFromDelegate(NullNullable));
ReturnErrorOnFailure(closureControlEndpoint.GetLogic().SetMainState(MainStateEnum::kStopped));

DataModel::Nullable<GenericOverallCurrentState> overallState(GenericOverallCurrentState(
MakeOptional(DataModel::MakeNullable(CurrentPositionEnum::kFullyClosed)), MakeOptional(DataModel::MakeNullable(true)),
MakeOptional(Globals::ThreeLevelAutoEnum::kAuto), MakeOptional(DataModel::MakeNullable(true))));
ReturnErrorOnFailure(closureControlEndpoint.GetLogic().SetOverallCurrentState(overallState));
DataModel::Nullable<GenericOverallTargetState> overallTarget(
GenericOverallTargetState(MakeOptional(DataModel::NullNullable), MakeOptional(DataModel::NullNullable),
MakeOptional(Globals::ThreeLevelAutoEnum::kAuto)));
ReturnErrorOnFailure(closureControlEndpoint.GetLogic().SetOverallTargetState(overallTarget));
BitFlags<ClosureControl::LatchControlModesBitmap> latchControlModes;
latchControlModes.Set(ClosureControl::LatchControlModesBitmap::kRemoteLatching)
.Set(ClosureControl::LatchControlModesBitmap::kRemoteUnlatching);
ReturnErrorOnFailure(closureControlEndpoint.GetLogic().SetLatchControlModes(latchControlModes));
return CHIP_NO_ERROR;
}

CHIP_ERROR ClosureManager::SetClosurePanelInitialState(ClosureDimensionEndpoint & closurePanelEndpoint)
{
ChipLogProgress(AppServer, "ClosurePanelEndpoint SetInitialState");
DataModel::Nullable<GenericDimensionStateStruct> currentState(
GenericDimensionStateStruct(MakeOptional(DataModel::MakeNullable<Percent100ths>(10000)),
MakeOptional(DataModel::MakeNullable(true)), MakeOptional(Globals::ThreeLevelAutoEnum::kAuto)));
ReturnErrorOnFailure(closurePanelEndpoint.GetLogic().SetCurrentState(currentState));

DataModel::Nullable<GenericDimensionStateStruct> targetState(
GenericDimensionStateStruct(MakeOptional(DataModel::NullNullable), MakeOptional(DataModel::NullNullable),
MakeOptional(Globals::ThreeLevelAutoEnum::kAuto)));
ReturnErrorOnFailure(closurePanelEndpoint.GetLogic().SetTargetState(targetState));

ReturnErrorOnFailure(closurePanelEndpoint.GetLogic().SetResolution(Percent100ths(100)));
ReturnErrorOnFailure(closurePanelEndpoint.GetLogic().SetStepValue(1000));
ReturnErrorOnFailure(closurePanelEndpoint.GetLogic().SetUnit(ClosureUnitEnum::kMillimeter));
ReturnErrorOnFailure(closurePanelEndpoint.GetLogic().SetUnitRange(
ClosureDimension::Structs::UnitRangeStruct::Type{ .min = static_cast<int16_t>(0), .max = static_cast<int16_t>(10000) }));
ReturnErrorOnFailure(closurePanelEndpoint.GetLogic().SetOverflow(OverflowEnum::kTopInside));

ClosureDimension::Structs::RangePercent100thsStruct::Type limitRange{ .min = static_cast<Percent100ths>(0),
.max = static_cast<Percent100ths>(10000) };
ReturnErrorOnFailure(closurePanelEndpoint.GetLogic().SetLimitRange(limitRange));
BitFlags<ClosureDimension::LatchControlModesBitmap> latchControlModes;
latchControlModes.Set(ClosureDimension::LatchControlModesBitmap::kRemoteLatching)
.Set(ClosureDimension::LatchControlModesBitmap::kRemoteUnlatching);
ReturnErrorOnFailure(closurePanelEndpoint.GetLogic().SetLatchControlModes(latchControlModes));

return CHIP_NO_ERROR;
}

void ClosureManager::StartTimer(uint32_t aTimeoutMs)
{
// Starts or restarts the function timer
Expand Down
Loading
0