Skip to content

Commit

Permalink
WindowCovering: Add Target Positions support to scenes (#8032)
Browse files Browse the repository at this point in the history
* WC: Add Target Positions support to scenes

* Restyle fixing

* Empty commit to kick restyled

Co-authored-by: Michael Spang <[email protected]>
  • Loading branch information
2 people authored and pull[bot] committed Aug 16, 2021
1 parent 06a164a commit 1546264
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 7 deletions.
67 changes: 60 additions & 7 deletions src/app/clusters/scenes/scenes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,10 @@ void emAfPluginScenesServerPrintInfo(void)
emberAfCorePrint(" door %x", entry.lockStateValue);
#endif
#ifdef ZCL_USING_WINDOW_COVERING_CLUSTER_SERVER
emberAfCorePrint(" window %x %x", entry.currentPositionLiftPercentageValue, entry.currentPositionTiltPercentageValue);
emberAfCorePrint(" Window percentage Lift %3u, Tilt %3u", entry.currentPositionLiftPercentageValue,
entry.currentPositionTiltPercentageValue);
emberAfCorePrint(" Window percent100ths Lift %5u, Tilt %5u", entry.targetPositionLiftPercent100thsValue,
entry.targetPositionTiltPercent100thsValue);
#endif
}
emberAfCorePrintln("");
Expand Down Expand Up @@ -538,12 +541,20 @@ EmberAfStatus emberAfScenesClusterStoreCurrentSceneCallback(EndpointId endpoint,
#ifdef ZCL_USING_WINDOW_COVERING_CLUSTER_SERVER
entry.hasCurrentPositionLiftPercentageValue =
readServerAttribute(endpoint, ZCL_WINDOW_COVERING_CLUSTER_ID, ZCL_WC_CURRENT_POSITION_LIFT_PERCENTAGE_ATTRIBUTE_ID,
"current position lift percentage", (uint8_t *) &entry.currentPositionLiftPercentageValue,
"currentPositionLiftPercentage", (uint8_t *) &entry.currentPositionLiftPercentageValue,
sizeof(entry.currentPositionLiftPercentageValue));
entry.hasCurrentPositionTiltPercentageValue =
readServerAttribute(endpoint, ZCL_WINDOW_COVERING_CLUSTER_ID, ZCL_WC_CURRENT_POSITION_TILT_PERCENTAGE_ATTRIBUTE_ID,
"current position tilt percentage", (uint8_t *) &entry.currentPositionTiltPercentageValue,
"currentPositionTiltPercentage", (uint8_t *) &entry.currentPositionTiltPercentageValue,
sizeof(entry.currentPositionTiltPercentageValue));
entry.hasTargetPositionLiftPercent100thsValue =
readServerAttribute(endpoint, ZCL_WINDOW_COVERING_CLUSTER_ID, ZCL_WC_TARGET_POSITION_LIFT_PERCENT100_THS_ATTRIBUTE_ID,
"targetPositionLiftPercent100ths", (uint8_t *) &entry.targetPositionLiftPercent100thsValue,
sizeof(entry.targetPositionLiftPercent100thsValue));
entry.hasTargetPositionTiltPercent100thsValue =
readServerAttribute(endpoint, ZCL_WINDOW_COVERING_CLUSTER_ID, ZCL_WC_TARGET_POSITION_TILT_PERCENT100_THS_ATTRIBUTE_ID,
"targetPositionTiltPercent100ths", (uint8_t *) &entry.targetPositionTiltPercent100thsValue,
sizeof(entry.targetPositionTiltPercent100thsValue));
#endif

// When creating a new entry, the name is set to the null string (i.e., the
Expand Down Expand Up @@ -676,15 +687,27 @@ EmberAfStatus emberAfScenesClusterRecallSavedSceneCallback(EndpointId endpoint,
if (entry.hasCurrentPositionLiftPercentageValue)
{
writeServerAttribute(endpoint, ZCL_WINDOW_COVERING_CLUSTER_ID,
ZCL_WC_CURRENT_POSITION_LIFT_PERCENTAGE_ATTRIBUTE_ID, "current position lift percentage",
ZCL_WC_CURRENT_POSITION_LIFT_PERCENTAGE_ATTRIBUTE_ID, "CurrentPositionLiftPercentage",
(uint8_t *) &entry.currentPositionLiftPercentageValue, ZCL_INT8U_ATTRIBUTE_TYPE);
}
if (entry.hasCurrentPositionTiltPercentageValue)
{
writeServerAttribute(endpoint, ZCL_WINDOW_COVERING_CLUSTER_ID,
ZCL_WC_CURRENT_POSITION_TILT_PERCENTAGE_ATTRIBUTE_ID, "current position tilt percentage",
ZCL_WC_CURRENT_POSITION_TILT_PERCENTAGE_ATTRIBUTE_ID, "CurrentPositionTiltPercentage",
(uint8_t *) &entry.currentPositionTiltPercentageValue, ZCL_INT8U_ATTRIBUTE_TYPE);
}
if (entry.hasTargetPositionLiftPercent100thsValue)
{
writeServerAttribute(endpoint, ZCL_WINDOW_COVERING_CLUSTER_ID,
ZCL_WC_TARGET_POSITION_LIFT_PERCENT100_THS_ATTRIBUTE_ID, "TargetPositionLiftPercent100ths",
(uint8_t *) &entry.targetPositionLiftPercent100thsValue, ZCL_INT16U_ATTRIBUTE_TYPE);
}
if (entry.hasTargetPositionTiltPercent100thsValue)
{
writeServerAttribute(endpoint, ZCL_WINDOW_COVERING_CLUSTER_ID,
ZCL_WC_TARGET_POSITION_TILT_PERCENT100_THS_ATTRIBUTE_ID, "TargetPositionTiltPercent100ths",
(uint8_t *) &entry.targetPositionTiltPercent100thsValue, ZCL_INT16U_ATTRIBUTE_TYPE);
}
#endif
emberAfScenesMakeValid(endpoint, sceneId, groupId);
return EMBER_ZCL_STATUS_SUCCESS;
Expand Down Expand Up @@ -793,8 +816,10 @@ bool emberAfPluginScenesServerParseAddScene(chip::app::Command * commandObj, con
entry.hasLockStateValue = false;
#endif
#ifdef ZCL_USING_WINDOW_COVERING_CLUSTER_SERVER
entry.hasCurrentPositionLiftPercentageValue = false;
entry.hasCurrentPositionTiltPercentageValue = false;
entry.hasCurrentPositionLiftPercentageValue = false;
entry.hasCurrentPositionTiltPercentageValue = false;
entry.hasTargetPositionLiftPercent100thsValue = false;
entry.hasTargetPositionTiltPercent100thsValue = false;
#endif
}

Expand Down Expand Up @@ -978,6 +1003,24 @@ bool emberAfPluginScenesServerParseAddScene(chip::app::Command * commandObj, con
entry.hasCurrentPositionTiltPercentageValue = true;
entry.currentPositionTiltPercentageValue =
emberAfGetInt8u(extensionFieldSets, extensionFieldSetsIndex, extensionFieldSetsLen);
extensionFieldSetsIndex++;
length--;
if (length < 2)
{
break;
}
entry.hasTargetPositionLiftPercent100thsValue = true;
entry.targetPositionLiftPercent100thsValue =
emberAfGetInt16u(extensionFieldSets, extensionFieldSetsIndex, extensionFieldSetsLen);
extensionFieldSetsIndex = static_cast<uint16_t>(extensionFieldSetsIndex + 2);
length = static_cast<uint8_t>(length - 2);
if (length < 2)
{
break;
}
entry.hasTargetPositionTiltPercent100thsValue = true;
entry.targetPositionTiltPercent100thsValue =
emberAfGetInt16u(extensionFieldSets, extensionFieldSetsIndex, extensionFieldSetsLen);
// If additional Window Covering extensions are added, adjust the index
// and length variables here.
break;
Expand Down Expand Up @@ -1210,6 +1253,16 @@ bool emberAfPluginScenesServerParseViewScene(chip::app::Command * commandObj, co
{
emberAfPutInt8uInResp(entry.currentPositionTiltPercentageValue);
(*length)++;
if (entry.hasTargetPositionLiftPercent100thsValue)
{
emberAfPutInt16uInResp(entry.targetPositionLiftPercent100thsValue);
*length = static_cast<uint8_t>(*length + 2);
if (entry.hasTargetPositionTiltPercent100thsValue)
{
emberAfPutInt16uInResp(entry.targetPositionTiltPercent100thsValue);
*length = static_cast<uint8_t>(*length + 2);
}
}
}
}
#endif
Expand Down
4 changes: 4 additions & 0 deletions src/app/util/af-types.h
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,10 @@ typedef struct
uint8_t currentPositionLiftPercentageValue;
bool hasCurrentPositionTiltPercentageValue;
uint8_t currentPositionTiltPercentageValue;
bool hasTargetPositionLiftPercent100thsValue;
uint16_t targetPositionLiftPercent100thsValue;
bool hasTargetPositionTiltPercent100thsValue;
uint16_t targetPositionTiltPercent100thsValue;
#endif
} EmberAfSceneTableEntry;

Expand Down

0 comments on commit 1546264

Please sign in to comment.