Skip to content

Commit

Permalink
Added implementation for missing On/Off Cluster commands (#11877)
Browse files Browse the repository at this point in the history
* Refactor on off server to fit c++

* Enable missing on/off commands

* generated function code

* OnOff Cluster commands implementation

* Update OnOff hook attribute function

* Added hook so that device can manage the effect

* Clean up

* fix define

* Changed define constants to constexpr

* Clean up comments

* Restyled by clang-format

* fix constants

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
2 people authored and pull[bot] committed Feb 16, 2024
1 parent 7c18067 commit 1381372
Show file tree
Hide file tree
Showing 7 changed files with 610 additions and 74 deletions.
71 changes: 62 additions & 9 deletions examples/lighting-app/efr32/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <app-common/zap-generated/attribute-type.h>
#include <app-common/zap-generated/cluster-id.h>
#include <app/clusters/identify-server/identify-server.h>
#include <app/clusters/on-off-server/on-off-server.h>
#include <app/server/OnboardingCodesUtil.h>
#include <app/server/Server.h>
#include <app/util/attribute-storage.h>
Expand Down Expand Up @@ -84,12 +85,16 @@ StaticQueue_t sAppEventQueueStruct;
StackType_t appStack[APP_TASK_STACK_SIZE / sizeof(StackType_t)];
StaticTask_t appTaskStruct;

inline void OnTriggerEffectCompleted(chip::System::Layer * systemLayer, void * appState)
/**********************************************************
* Identify Callbacks
*********************************************************/

inline void OnTriggerIdentifyEffectCompleted(chip::System::Layer * systemLayer, void * appState)
{
sIdentifyEffect = EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_STOP_EFFECT;
}

void OnTriggerEffect(Identify * identify)
void OnTriggerIdentifyEffect(Identify * identify)
{
sIdentifyEffect = identify->mCurrentEffectIdentifier;

Expand All @@ -105,14 +110,16 @@ void OnTriggerEffect(Identify * identify)
case EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_BLINK:
case EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_BREATHE:
case EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_OKAY:
(void) chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Seconds16(5), OnTriggerEffectCompleted, identify);
(void) chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Seconds16(5), OnTriggerIdentifyEffectCompleted,
identify);
break;
case EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_FINISH_EFFECT:
(void) chip::DeviceLayer::SystemLayer().CancelTimer(OnTriggerEffectCompleted, identify);
(void) chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Seconds16(1), OnTriggerEffectCompleted, identify);
(void) chip::DeviceLayer::SystemLayer().CancelTimer(OnTriggerIdentifyEffectCompleted, identify);
(void) chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Seconds16(1), OnTriggerIdentifyEffectCompleted,
identify);
break;
case EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_STOP_EFFECT:
(void) chip::DeviceLayer::SystemLayer().CancelTimer(OnTriggerEffectCompleted, identify);
(void) chip::DeviceLayer::SystemLayer().CancelTimer(OnTriggerIdentifyEffectCompleted, identify);
sIdentifyEffect = EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_STOP_EFFECT;
break;
default:
Expand All @@ -125,7 +132,53 @@ Identify gIdentify = {
[](Identify *) { ChipLogProgress(Zcl, "onIdentifyStart"); },
[](Identify *) { ChipLogProgress(Zcl, "onIdentifyStop"); },
EMBER_ZCL_IDENTIFY_IDENTIFY_TYPE_VISIBLE_LED,
OnTriggerEffect,
OnTriggerIdentifyEffect,
};

/**********************************************************
* OffWithEffect Callbacks
*********************************************************/

void OnTriggerOffWithEffect(OnOffEffect * effect)
{
uint8_t effectId = effect->mEffectIdentifier;
uint8_t effectVariant = effect->mEffectVariant;

// Uses print outs until we can support the effects
if (effectId == EMBER_ZCL_ON_OFF_EFFECT_IDENTIFIER_DELAYED_ALL_OFF)
{
if (effectVariant == EMBER_ZCL_ON_OFF_DELAYED_ALL_OFF_EFFECT_VARIANT_FADE_TO_OFF_IN_0P8_SECONDS)
{
ChipLogProgress(Zcl, "EMBER_ZCL_ON_OFF_DELAYED_ALL_OFF_EFFECT_VARIANT_FADE_TO_OFF_IN_0P8_SECONDS");
}
else if (effectVariant == EMBER_ZCL_ON_OFF_DELAYED_ALL_OFF_EFFECT_VARIANT_NO_FADE)
{
ChipLogProgress(Zcl, "EMBER_ZCL_ON_OFF_DELAYED_ALL_OFF_EFFECT_VARIANT_NO_FADE");
}
else if (effectVariant ==
EMBER_ZCL_ON_OFF_DELAYED_ALL_OFF_EFFECT_VARIANT_50_PERCENT_DIM_DOWN_IN_0P8_SECONDS_THEN_FADE_TO_OFF_IN_12_SECONDS)
{
ChipLogProgress(Zcl,
"EMBER_ZCL_ON_OFF_DELAYED_ALL_OFF_EFFECT_VARIANT_50_PERCENT_DIM_DOWN_IN_0P8_SECONDS_THEN_FADE_TO_OFF_"
"IN_12_SECONDS");
}
}
else if (effectId == EMBER_ZCL_ON_OFF_EFFECT_IDENTIFIER_DYING_LIGHT)
{
if (effectVariant ==
EMBER_ZCL_ON_OFF_DYING_LIGHT_EFFECT_VARIANT_20_PERCENTER_DIM_UP_IN_0P5_SECONDS_THEN_FADE_TO_OFF_IN_1_SECOND)
{
ChipLogProgress(
Zcl, "EMBER_ZCL_ON_OFF_DYING_LIGHT_EFFECT_VARIANT_20_PERCENTER_DIM_UP_IN_0P5_SECONDS_THEN_FADE_TO_OFF_IN_1_SECOND");
}
}
}

OnOffEffect gEffect = {
chip::EndpointId{ 1 },
OnTriggerOffWithEffect,
static_cast<uint8_t>(EMBER_ZCL_ON_OFF_EFFECT_IDENTIFIER_DELAYED_ALL_OFF),
static_cast<uint8_t>(EMBER_ZCL_ON_OFF_DELAYED_ALL_OFF_EFFECT_VARIANT_FADE_TO_OFF_IN_0P8_SECONDS),
};

} // namespace
Expand Down Expand Up @@ -586,8 +639,8 @@ void AppTask::UpdateClusterState(void)
uint8_t newValue = LightMgr().IsLightOn();

// write the new on/off value
EmberAfStatus status = emberAfWriteAttribute(1, ZCL_ON_OFF_CLUSTER_ID, ZCL_ON_OFF_ATTRIBUTE_ID, CLUSTER_MASK_SERVER,
(uint8_t *) &newValue, ZCL_BOOLEAN_ATTRIBUTE_TYPE);
EmberAfStatus status = OnOffServer::Instance().setOnOffValue(1, newValue, false);

if (status != EMBER_ZCL_STATUS_SUCCESS)
{
EFR32_LOG("ERR: updating on/off %x", status);
Expand Down
30 changes: 27 additions & 3 deletions examples/lighting-app/lighting-common/lighting-app.zap
Original file line number Diff line number Diff line change
Expand Up @@ -4405,23 +4405,23 @@
"code": 64,
"mfgCode": null,
"source": "client",
"incoming": 0,
"incoming": 1,
"outgoing": 0
},
{
"name": "OnWithRecallGlobalScene",
"code": 65,
"mfgCode": null,
"source": "client",
"incoming": 0,
"incoming": 1,
"outgoing": 0
},
{
"name": "OnWithTimedOff",
"code": 66,
"mfgCode": null,
"source": "client",
"incoming": 0,
"incoming": 1,
"outgoing": 0
}
],
Expand Down Expand Up @@ -6045,6 +6045,30 @@
"source": "client",
"incoming": 0,
"outgoing": 1
},
{
"name": "OffWithEffect",
"code": 64,
"mfgCode": null,
"source": "client",
"incoming": 0,
"outgoing": 1
},
{
"name": "OnWithRecallGlobalScene",
"code": 65,
"mfgCode": null,
"source": "client",
"incoming": 0,
"outgoing": 1
},
{
"name": "OnWithTimedOff",
"code": 66,
"mfgCode": null,
"source": "client",
"incoming": 0,
"outgoing": 1
}
],
"attributes": [
Expand Down
2 changes: 1 addition & 1 deletion src/app/clusters/level-control/level-control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ static void setOnOffValue(EndpointId endpoint, bool onOff)
if (emberAfContainsServer(endpoint, OnOff::Id))
{
emberAfLevelControlClusterPrintln("Setting on/off to %p due to level change", onOff ? "ON" : "OFF");
emberAfOnOffClusterSetValueCallback(endpoint, (onOff ? OnOff::Commands::On::Id : OnOff::Commands::Off::Id), true);
OnOffServer::Instance().setOnOffValue(endpoint, (onOff ? OnOff::Commands::On::Id : OnOff::Commands::Off::Id), true);
}
#endif // EMBER_AF_PLUGIN_ON_OFF
}
Expand Down
Loading

0 comments on commit 1381372

Please sign in to comment.