Skip to content

Commit

Permalink
DEV: Update xml and simplify feature maps PositionAware
Browse files Browse the repository at this point in the history
  • Loading branch information
jmeg-sfy committed Dec 16, 2021
1 parent 62e53e0 commit 01a7413
Show file tree
Hide file tree
Showing 10 changed files with 557 additions and 1,915 deletions.
52 changes: 28 additions & 24 deletions src/app/clusters/window-covering-server/window-covering-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ using namespace chip::app::Clusters::WindowCovering;
#define WC_PERCENT100THS_MIN 0
#define WC_PERCENT100THS_MAX 10000

static bool HasFeature(chip::EndpointId endpoint, WindowCoveringFeature feature)
static bool HasFeature(chip::EndpointId endpoint, WcFeature feature)
{
uint32_t FeatureMap = 0;
if (EMBER_ZCL_STATUS_SUCCESS ==
Expand All @@ -73,6 +73,16 @@ static bool HasFeature(chip::EndpointId endpoint, WindowCoveringFeature feature)
return false;
}

static inline bool HasFeaturePaLift(chip::EndpointId endpoint)
{
return (HasFeature(endpoint, WcFeature::kLift) && HasFeature(endpoint, WcFeature::kPositionAwareLift));
}

static inline bool HasFeaturePaTilt(chip::EndpointId endpoint)
{
return (HasFeature(endpoint, WcFeature::kTilt) && HasFeature(endpoint, WcFeature::kPositionAwareTilt));
}

static uint16_t ValueToPercent100ths(uint16_t openLimit, uint16_t closedLimit, uint16_t value)
{
uint16_t minimum = 0, range = UINT16_MAX;
Expand Down Expand Up @@ -422,11 +432,11 @@ bool emberAfWindowCoveringClusterUpOrOpenCallback(app::CommandHandler * commandO
EndpointId endpoint = commandPath.mEndpointId;

emberAfWindowCoveringClusterPrint("UpOrOpen command received");
if (HasFeature(endpoint, WindowCoveringFeature::kLift))
if (HasFeature(endpoint, WcFeature::kLift))
{
Attributes::TargetPositionLiftPercent100ths::Set(endpoint, 0);
}
if (HasFeature(endpoint, WindowCoveringFeature::kTilt))
if (HasFeature(endpoint, WcFeature::kTilt))
{
Attributes::TargetPositionTiltPercent100ths::Set(endpoint, 0);
}
Expand All @@ -443,11 +453,11 @@ bool emberAfWindowCoveringClusterDownOrCloseCallback(app::CommandHandler * comma
EndpointId endpoint = commandPath.mEndpointId;

emberAfWindowCoveringClusterPrint("DownOrClose command received");
if (HasFeature(endpoint, WindowCoveringFeature::kLift))
if (HasFeature(endpoint, WcFeature::kLift))
{
Attributes::TargetPositionLiftPercent100ths::Set(endpoint, WC_PERCENT100THS_MAX);
}
if (HasFeature(endpoint, WindowCoveringFeature::kTilt))
if (HasFeature(endpoint, WcFeature::kTilt))
{
Attributes::TargetPositionTiltPercent100ths::Set(endpoint, WC_PERCENT100THS_MAX);
}
Expand All @@ -463,18 +473,18 @@ emberAfWindowCoveringClusterStopMotionCallback(app::CommandHandler * commandObj,
const Commands::StopMotion::DecodableType & fields)
{
emberAfWindowCoveringClusterPrint("StopMotion command received");
uint16_t current = 0;
app::DataModel::Nullable<Percent100ths> current;
chip::EndpointId endpoint = commandPath.mEndpointId;

if (HasFeature(endpoint, WindowCoveringFeature::kLift) && HasFeature(endpoint, WindowCoveringFeature::kPositionAwareLift))
if (HasFeaturePaLift(endpoint))
{
(void) Attributes::CurrentPositionLiftPercent100ths::Get(endpoint, &current);
(void) Attributes::CurrentPositionLiftPercent100ths::Get(endpoint, current);
(void) Attributes::TargetPositionLiftPercent100ths::Set(endpoint, current);
}

if (HasFeature(endpoint, WindowCoveringFeature::kTilt) && HasFeature(endpoint, WindowCoveringFeature::kPositionAwareTilt))
if (HasFeaturePaTilt(endpoint))
{
(void) Attributes::CurrentPositionTiltPercent100ths::Get(endpoint, &current);
(void) Attributes::CurrentPositionTiltPercent100ths::Get(endpoint, current);
(void) Attributes::TargetPositionTiltPercent100ths::Set(endpoint, current);
}

Expand All @@ -492,8 +502,8 @@ bool emberAfWindowCoveringClusterGoToLiftValueCallback(app::CommandHandler * com

EndpointId endpoint = commandPath.mEndpointId;

bool hasLift = HasFeature(endpoint, WindowCoveringFeature::kLift);
bool isPositionAware = HasFeature(endpoint, WindowCoveringFeature::kPositionAwareLift);
bool hasLift = HasFeature(endpoint, WcFeature::kLift);
bool isPositionAware = HasFeature(endpoint, WcFeature::kPositionAwareLift);

emberAfWindowCoveringClusterPrint("GoToLiftValue Value command received");
if (hasLift && isPositionAware)
Expand Down Expand Up @@ -521,19 +531,16 @@ bool emberAfWindowCoveringClusterGoToLiftPercentageCallback(app::CommandHandler

EndpointId endpoint = commandPath.mEndpointId;

bool hasLift = HasFeature(endpoint, WindowCoveringFeature::kLift);
bool isPositionAware = HasFeature(endpoint, WindowCoveringFeature::kPositionAwareLift);

emberAfWindowCoveringClusterPrint("GoToLiftPercentage Percentage command received");
if (hasLift && isPositionAware)
if (HasFeaturePaLift(endpoint))
{
Attributes::TargetPositionLiftPercent100ths::Set(
endpoint, static_cast<uint16_t>(liftPercentageValue > 100 ? liftPercent100thsValue : liftPercentageValue * 100));
emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_SUCCESS);
}
else
{
emberAfWindowCoveringClusterPrint("Err Device is not PA=%u or LF=%u", isPositionAware, hasLift);
emberAfWindowCoveringClusterPrint("Err Device is not LF_PA");
emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_ACTION_DENIED);
}
return true;
Expand All @@ -550,8 +557,8 @@ bool emberAfWindowCoveringClusterGoToTiltValueCallback(app::CommandHandler * com

EndpointId endpoint = commandPath.mEndpointId;

bool hasTilt = HasFeature(endpoint, WindowCoveringFeature::kTilt);
bool isPositionAware = HasFeature(endpoint, WindowCoveringFeature::kPositionAwareTilt);
bool hasTilt = HasFeature(endpoint, WcFeature::kTilt);
bool isPositionAware = HasFeature(endpoint, WcFeature::kPositionAwareTilt);

emberAfWindowCoveringClusterPrint("GoToTiltValue command received");
if (hasTilt && isPositionAware)
Expand Down Expand Up @@ -579,19 +586,16 @@ bool emberAfWindowCoveringClusterGoToTiltPercentageCallback(app::CommandHandler

EndpointId endpoint = commandPath.mEndpointId;

bool hasTilt = HasFeature(endpoint, WindowCoveringFeature::kTilt);
bool isPositionAware = HasFeature(endpoint, WindowCoveringFeature::kPositionAwareTilt);

emberAfWindowCoveringClusterPrint("GoToTiltPercentage command received");
if (hasTilt && isPositionAware)
if (HasFeaturePaTilt(endpoint))
{
Attributes::TargetPositionTiltPercent100ths::Set(
endpoint, static_cast<uint16_t>(tiltPercentageValue > 100 ? tiltPercent100thsValue : tiltPercentageValue * 100));
emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_SUCCESS);
}
else
{
emberAfWindowCoveringClusterPrint("Err Device is not PA=%u or TL=%u", isPositionAware, hasTilt);
emberAfWindowCoveringClusterPrint("Err Device is not TL_PA");
emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_ACTION_DENIED);
}
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ limitations under the License.
<field mask="0x0800" name="Protection"/>
</bitmap>

<bitmap name="WindowCoveringFeature" type="BITMAP32">
<bitmap name="WcFeature" type="BITMAP32">
<cluster code="0x0102"/>
<field name="Lift" mask="0x1"/>
<field name="Tilt" mask="0x2"/>
Expand Down
Loading

0 comments on commit 01a7413

Please sign in to comment.