Skip to content

Commit

Permalink
WindowCovering: Update xml config to latest specs (#13076)
Browse files Browse the repository at this point in the history
* DEV: zzz_generated update

* DEV: Update Window Covering XML to specs compliance

* DEV: WC Update code to use nullable Attribute

* [Test] WC Update tests to support nullable

* FIX: Apply types patch from Boris Zbarsky

* Rollback the Tests WNCV 2-1

* DEV: Split isOpen and isClose

* FIX: Check target and current nullabilities

* Harmonize Wc Enum and fix compliance on command

* Fix Current declaration

* Use define for open
  • Loading branch information
jmeg-sfy authored and pull[bot] committed Feb 28, 2022
1 parent 845a19c commit 44fd091
Show file tree
Hide file tree
Showing 33 changed files with 1,996 additions and 1,083 deletions.
75 changes: 55 additions & 20 deletions examples/window-app/common/src/WindowApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,9 +425,15 @@ void WindowApp::Cover::Finish()

void WindowApp::Cover::LiftUp()
{
uint16_t percent100ths = 0;
EmberAfStatus status;
chip::app::DataModel::Nullable<chip::Percent100ths> current;
chip::Percent100ths percent100ths = 5000; // set at middle

status = Attributes::CurrentPositionLiftPercent100ths::Get(mEndpoint, current);

if ((status == EMBER_ZCL_STATUS_SUCCESS) && !current.IsNull())
percent100ths = current.Value();

Attributes::CurrentPositionLiftPercent100ths::Get(mEndpoint, &percent100ths);
if (percent100ths < 9000)
{
percent100ths += 1000;
Expand All @@ -441,9 +447,15 @@ void WindowApp::Cover::LiftUp()

void WindowApp::Cover::LiftDown()
{
uint16_t percent100ths = 0;
EmberAfStatus status;
chip::app::DataModel::Nullable<chip::Percent100ths> current;
chip::Percent100ths percent100ths = 5000; // set at middle

status = Attributes::CurrentPositionLiftPercent100ths::Get(mEndpoint, current);

if ((status == EMBER_ZCL_STATUS_SUCCESS) && !current.IsNull())
percent100ths = current.Value();

Attributes::CurrentPositionLiftPercent100ths::Get(mEndpoint, &percent100ths);
if (percent100ths > 1000)
{
percent100ths -= 1000;
Expand All @@ -457,10 +469,15 @@ void WindowApp::Cover::LiftDown()

void WindowApp::Cover::GotoLift(EventId action)
{
uint16_t current = 0;
uint16_t target = 0;
Attributes::TargetPositionLiftPercent100ths::Get(mEndpoint, &target);
Attributes::CurrentPositionLiftPercent100ths::Get(mEndpoint, &current);
chip::app::DataModel::Nullable<chip::Percent100ths> current;
chip::app::DataModel::Nullable<chip::Percent100ths> target;
Attributes::TargetPositionLiftPercent100ths::Get(mEndpoint, target);
Attributes::CurrentPositionLiftPercent100ths::Get(mEndpoint, current);

if (current.IsNull() || target.IsNull())
{
return;
}

if (EventId::None != action)
{
Expand All @@ -469,7 +486,7 @@ void WindowApp::Cover::GotoLift(EventId action)

if (EventId::LiftUp == mLiftAction)
{
if (current < target)
if (current.Value() < target.Value())
{
LiftUp();
}
Expand All @@ -480,7 +497,7 @@ void WindowApp::Cover::GotoLift(EventId action)
}
else
{
if (current > target)
if (current.Value() > target.Value())
{
LiftDown();
}
Expand All @@ -498,8 +515,15 @@ void WindowApp::Cover::GotoLift(EventId action)

void WindowApp::Cover::TiltUp()
{
uint16_t percent100ths = 0;
Attributes::CurrentPositionTiltPercent100ths::Get(mEndpoint, &percent100ths);
EmberAfStatus status;
chip::app::DataModel::Nullable<chip::Percent100ths> current;
chip::Percent100ths percent100ths = 5000; // set at middle

status = Attributes::CurrentPositionTiltPercent100ths::Get(mEndpoint, current);

if ((status == EMBER_ZCL_STATUS_SUCCESS) && !current.IsNull())
percent100ths = current.Value();

if (percent100ths < 9000)
{
percent100ths += 1000;
Expand All @@ -513,8 +537,15 @@ void WindowApp::Cover::TiltUp()

void WindowApp::Cover::TiltDown()
{
uint16_t percent100ths = 0;
Attributes::CurrentPositionTiltPercent100ths::Get(mEndpoint, &percent100ths);
EmberAfStatus status;
chip::app::DataModel::Nullable<chip::Percent100ths> current;
chip::Percent100ths percent100ths = 5000; // set at middle

status = Attributes::CurrentPositionTiltPercent100ths::Get(mEndpoint, current);

if ((status == EMBER_ZCL_STATUS_SUCCESS) && !current.IsNull())
percent100ths = current.Value();

if (percent100ths > 1000)
{
percent100ths -= 1000;
Expand All @@ -528,11 +559,15 @@ void WindowApp::Cover::TiltDown()

void WindowApp::Cover::GotoTilt(EventId action)
{
uint16_t current = 0;
uint16_t target = 0;
chip::app::DataModel::Nullable<chip::Percent100ths> current;
chip::app::DataModel::Nullable<chip::Percent100ths> target;
Attributes::TargetPositionTiltPercent100ths::Get(mEndpoint, target);
Attributes::CurrentPositionTiltPercent100ths::Get(mEndpoint, current);

Attributes::TargetPositionTiltPercent100ths::Get(mEndpoint, &target);
Attributes::CurrentPositionTiltPercent100ths::Get(mEndpoint, &current);
if (current.IsNull() || target.IsNull())
{
return;
}

if (EventId::None != action)
{
Expand All @@ -541,7 +576,7 @@ void WindowApp::Cover::GotoTilt(EventId action)

if (EventId::TiltUp == mTiltAction)
{
if (current < target)
if (current.Value() < target.Value())
{
TiltUp();
}
Expand All @@ -552,7 +587,7 @@ void WindowApp::Cover::GotoTilt(EventId action)
}
else
{
if (current > target)
if (current.Value() > target.Value())
{
TiltDown();
}
Expand Down
43 changes: 25 additions & 18 deletions examples/window-app/common/src/ZclCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ void MatterPostAttributeChangeCallback(const app::ConcreteAttributePath & attrib

WindowApp & app = WindowApp::Instance();
EndpointId endpoint = attributePath.mEndpointId;
uint16_t current;
uint16_t target;

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

switch (attributePath.mAttributeId)
{
Expand All @@ -73,28 +74,34 @@ void MatterPostAttributeChangeCallback(const app::ConcreteAttributePath & attrib
break;

case Attributes::TargetPositionLiftPercent100ths::Id:
Attributes::TargetPositionLiftPercent100ths::Get(endpoint, &target);
Attributes::CurrentPositionLiftPercent100ths::Get(endpoint, &current);
if (current > target)
{
app.PostEvent(WindowApp::Event(WindowApp::EventId::LiftDown, endpoint));
}
else if (current < target)
Attributes::TargetPositionLiftPercent100ths::Get(endpoint, target);
Attributes::CurrentPositionLiftPercent100ths::Get(endpoint, current);
if (!current.IsNull() && !target.IsNull())
{
app.PostEvent(WindowApp::Event(WindowApp::EventId::LiftUp, endpoint));
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));
}
}
break;

case Attributes::TargetPositionTiltPercent100ths::Id:
Attributes::TargetPositionTiltPercent100ths::Get(endpoint, &target);
Attributes::CurrentPositionTiltPercent100ths::Get(endpoint, &current);
if (current > target)
{
app.PostEvent(WindowApp::Event(WindowApp::EventId::TiltDown, endpoint));
}
else if (current < target)
Attributes::TargetPositionTiltPercent100ths::Get(endpoint, target);
Attributes::CurrentPositionTiltPercent100ths::Get(endpoint, current);
if (!current.IsNull() && !target.IsNull())
{
app.PostEvent(WindowApp::Event(WindowApp::EventId::TiltUp, endpoint));
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));
}
}
break;

Expand Down
18 changes: 11 additions & 7 deletions examples/window-app/efr32/src/WindowAppImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,11 +327,11 @@ void WindowAppImpl::UpdateLEDs()
{
mActionLED.Blink(100);
}
else if (IsOpen(cover.mEndpoint))
else if (IsLiftOpen(cover.mEndpoint))
{
mActionLED.Set(true);
}
else if (IsClosed(cover.mEndpoint))
else if (IsLiftClosed(cover.mEndpoint))
{
mActionLED.Set(false);
}
Expand All @@ -350,11 +350,15 @@ void WindowAppImpl::UpdateLCD()
{
Cover & cover = GetCover();
EmberAfWcType type = TypeGet(cover.mEndpoint);
uint16_t lift = 0;
uint16_t tilt = 0;
Attributes::CurrentPositionLift::Get(cover.mEndpoint, &lift);
Attributes::CurrentPositionTilt::Get(cover.mEndpoint, &tilt);
LcdPainter::Paint(type, static_cast<uint8_t>(lift), static_cast<uint8_t>(tilt), mIcon);
chip::app::DataModel::Nullable<uint16_t> lift;
chip::app::DataModel::Nullable<uint16_t> tilt;
Attributes::CurrentPositionLift::Get(cover.mEndpoint, lift);
Attributes::CurrentPositionTilt::Get(cover.mEndpoint, tilt);

if (!tilt.IsNull() && !lift.IsNull())
{
LcdPainter::Paint(type, static_cast<uint8_t>(lift.Value()), static_cast<uint8_t>(tilt.Value()), mIcon);
}
}
else
{
Expand Down
Loading

0 comments on commit 44fd091

Please sign in to comment.