Skip to content

Commit

Permalink
WindowCovering: fix Limits checks + factorization (project-chip#13729)
Browse files Browse the repository at this point in the history
* DEV: Remove IsOpen IsClosed function and use CheckLimitState

* DEV: Move HasFeature function for external usage

* DEV: Factorize conversion function

* DEV: Add IsPercent100thsValid check method

* DEV: Add OperationalStatusSet Global field helpers function

- automatically set global field

* DEV: Add ComputeOperationalState function

* Restyled by clang-format

* DEV: Rename limits using "Over" to "Post"

* DEV: Cleanup HasFeature function

* DEV: Add comments to explain the convert function

* DEV: Replace Limit Post by Past

* Style: correct bad description of ConvertValue

Co-authored-by: Restyled.io <commits@restyled.io>
  • Loading branch information
jmeg-sfy and restyled-commits authored Jan 26, 2022
1 parent 4ece9e8 commit 1ccf850
Show file tree
Hide file tree
Showing 4 changed files with 239 additions and 140 deletions.
33 changes: 15 additions & 18 deletions examples/window-app/common/src/ZclCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ void MatterPostAttributeChangeCallback(const app::ConcreteAttributePath & attrib

chip::app::DataModel::Nullable<chip::Percent100ths> current;
chip::app::DataModel::Nullable<chip::Percent100ths> target;
OperationalState opState;

switch (attributePath.mAttributeId)
{
Expand All @@ -76,32 +77,28 @@ void MatterPostAttributeChangeCallback(const app::ConcreteAttributePath & attrib
case Attributes::TargetPositionLiftPercent100ths::Id:
Attributes::TargetPositionLiftPercent100ths::Get(endpoint, target);
Attributes::CurrentPositionLiftPercent100ths::Get(endpoint, current);
if (!current.IsNull() && !target.IsNull())
opState = ComputeOperationalState(target, current);
if (OperationalState::MovingDownOrClose == opState)
{
if (current.Value() > target.Value())
{
app.PostEvent(WindowApp::Event(WindowApp::EventId::LiftDown, endpoint));
}
else if (current.Value() < target.Value())
{
app.PostEvent(WindowApp::Event(WindowApp::EventId::LiftUp, endpoint));
}
app.PostEvent(WindowApp::Event(WindowApp::EventId::LiftDown, endpoint));
}
else if (OperationalState::MovingUpOrOpen == opState)
{
app.PostEvent(WindowApp::Event(WindowApp::EventId::LiftUp, endpoint));
}
break;

case Attributes::TargetPositionTiltPercent100ths::Id:
Attributes::TargetPositionTiltPercent100ths::Get(endpoint, target);
Attributes::CurrentPositionTiltPercent100ths::Get(endpoint, current);
if (!current.IsNull() && !target.IsNull())
opState = ComputeOperationalState(target, current);
if (OperationalState::MovingDownOrClose == opState)
{
app.PostEvent(WindowApp::Event(WindowApp::EventId::TiltDown, endpoint));
}
else if (OperationalState::MovingUpOrOpen == opState)
{
if (current.Value() > target.Value())
{
app.PostEvent(WindowApp::Event(WindowApp::EventId::TiltDown, endpoint));
}
else if (current.Value() < target.Value())
{
app.PostEvent(WindowApp::Event(WindowApp::EventId::TiltUp, endpoint));
}
app.PostEvent(WindowApp::Event(WindowApp::EventId::TiltUp, endpoint));
}
break;

Expand Down
14 changes: 12 additions & 2 deletions examples/window-app/efr32/src/WindowAppImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,16 +338,26 @@ void WindowAppImpl::UpdateLEDs()
else { mStatusLED.Blink(50, 950); }

// Action LED
NPercent100ths current;
LimitStatus liftLimit = LimitStatus::Intermediate;

Attributes::CurrentPositionLiftPercent100ths::Get(cover.mEndpoint, current);

if (!current.IsNull())
{
AbsoluteLimits limits = { .open = WC_PERCENT100THS_MIN_OPEN, .closed = WC_PERCENT100THS_MAX_CLOSED };
liftLimit = CheckLimitState(current.Value(), limits);
}

if (EventId::None != cover.mLiftAction || EventId::None != cover.mTiltAction)
{
mActionLED.Blink(100);
}
else if (IsLiftOpen(cover.mEndpoint))
else if (LimitStatus::IsUpOrOpen == liftLimit)
{
mActionLED.Set(true);
}
else if (IsLiftClosed(cover.mEndpoint))
else if (LimitStatus::IsDownOrClose == liftLimit)
{
mActionLED.Set(false);
}
Expand Down
Loading

0 comments on commit 1ccf850

Please sign in to comment.