Skip to content

Commit

Permalink
Enable Identify server cluster in lighting-app
Browse files Browse the repository at this point in the history
* sample implementation in lighting-app/nrfconnect
* pulls in zll-identify-server because of
   emberAfIdentifyClusterTriggerEffectCallback
  • Loading branch information
markus-becker-tridonic-com committed Jul 20, 2021
1 parent 37df562 commit 254fbf8
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 32 deletions.
28 changes: 19 additions & 9 deletions examples/lighting-app/lighting-common/gen/af-gen-event.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@

// Code used to configure the cluster event mechanism
#define EMBER_AF_GENERATED_EVENT_CODE \
EmberEventControl emberAfIdentifyClusterServerTickCallbackControl1; \
EmberEventControl emberAfLevelControlClusterServerTickCallbackControl1; \
extern EmberEventControl emberAfPluginColorControlServerHueSatTransitionEventControl; \
extern EmberEventControl emberAfPluginColorControlServerTempTransitionEventControl; \
Expand All @@ -55,30 +56,39 @@
(*callback)(endpoint); \
/* emberAfPopNetworkIndex(); */ \
} \
\
void emberAfIdentifyClusterServerTickCallbackWrapperFunction1(void) \
{ \
clusterTickWrapper(&emberAfIdentifyClusterServerTickCallbackControl1, emberAfIdentifyClusterServerTickCallback, 1); \
} \
void emberAfLevelControlClusterServerTickCallbackWrapperFunction1(void) \
{ \
clusterTickWrapper(&emberAfLevelControlClusterServerTickCallbackControl1, emberAfLevelControlClusterServerTickCallback, \
1); \
}
} \
EmberEventControl emberAfPluginZllIdentifyServerTriggerEffectEndpointEventControls[1]; \
extern void emberAfPluginZllIdentifyServerTriggerEffectEndpointEventHandler(EndpointId endpoint); \
void emberAfPluginZllIdentifyServerTriggerEffectEndpointEventWrapper1(void) { clusterTickWrapper(&emberAfPluginZllIdentifyServerTriggerEffectEndpointEventControls[0], emberAfPluginZllIdentifyServerTriggerEffectEndpointEventHandler, 1); }

// EmberEventData structs used to populate the EmberEventData table
#define EMBER_AF_GENERATED_EVENTS \
{ &emberAfIdentifyClusterServerTickCallbackControl1, emberAfIdentifyClusterServerTickCallbackWrapperFunction1 }, \
{ &emberAfLevelControlClusterServerTickCallbackControl1, emberAfLevelControlClusterServerTickCallbackWrapperFunction1 }, \
{ &emberAfPluginColorControlServerHueSatTransitionEventControl, \
emberAfPluginColorControlServerHueSatTransitionEventHandler }, \
{ &emberAfPluginColorControlServerTempTransitionEventControl, emberAfPluginColorControlServerTempTransitionEventHandler }, \
{ &emberAfPluginColorControlServerXyTransitionEventControl, emberAfPluginColorControlServerXyTransitionEventHandler },
{ &emberAfPluginColorControlServerHueSatTransitionEventControl, emberAfPluginColorControlServerHueSatTransitionEventHandler }, \
{ &emberAfPluginColorControlServerTempTransitionEventControl, emberAfPluginColorControlServerTempTransitionEventHandler }, \
{ &emberAfPluginColorControlServerXyTransitionEventControl, emberAfPluginColorControlServerXyTransitionEventHandler }, \
{ &emberAfPluginZllIdentifyServerTriggerEffectEndpointEventControls[0], emberAfPluginZllIdentifyServerTriggerEffectEndpointEventWrapper1 },

#define EMBER_AF_GENERATED_EVENT_STRINGS \
"Level Control Cluster Server EP 1", "Color Control Cluster Server Plugin HueSatTransition", \
"Color Control Cluster Server Plugin TempTransition", "Color Control Cluster Server Plugin XyTransition",
"Identify Cluster Server EP 1", "Level Control Cluster Server EP 1", "Color Control Cluster Server Plugin HueSatTransition", \
"Color Control Cluster Server Plugin TempTransition", "Color Control Cluster Server Plugin XyTransition", \
"ZLL Identify Server Plugin TriggerEffect EP 1",

// The length of the event context table used to track and retrieve cluster events
#define EMBER_AF_EVENT_CONTEXT_LENGTH 1
#define EMBER_AF_EVENT_CONTEXT_LENGTH 2

// EmberAfEventContext structs used to populate the EmberAfEventContext table
#define EMBER_AF_GENERATED_EVENT_CONTEXT \
{ 0x1, 0x3, false, EMBER_AF_LONG_POLL, EMBER_AF_OK_TO_SLEEP, &emberAfIdentifyClusterServerTickCallbackControl1 }, \
{ 0x1, 0x8, false, EMBER_AF_LONG_POLL, EMBER_AF_OK_TO_SLEEP, &emberAfLevelControlClusterServerTickCallbackControl1 },

#endif // __AF_GEN_EVENT__
4 changes: 2 additions & 2 deletions examples/lighting-app/lighting-common/lighting-app.zap
Original file line number Diff line number Diff line change
Expand Up @@ -3100,7 +3100,7 @@
"mfgCode": null,
"define": "IDENTIFY_CLUSTER",
"side": "server",
"enabled": 0,
"enabled": 1,
"commands": [
{
"name": "IdentifyQueryResponse",
Expand Down Expand Up @@ -4842,4 +4842,4 @@
}
],
"log": []
}
}
2 changes: 2 additions & 0 deletions examples/lighting-app/nrfconnect/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ target_sources(app PRIVATE
${CHIP_ROOT}/src/app/clusters/occupancy-sensor-server/occupancy-sensor-server.cpp
${CHIP_ROOT}/src/app/clusters/network-commissioning/network-commissioning-ember.cpp
${CHIP_ROOT}/src/app/clusters/network-commissioning/network-commissioning.cpp
${CHIP_ROOT}/src/app/clusters/identify/identify.cpp
${CHIP_ROOT}/src/app/clusters/zll-identify-server/zll-identify-server.cpp
)

if (BOARD STREQUAL "nrf52840dongle_nrf52840")
Expand Down
17 changes: 17 additions & 0 deletions examples/lighting-app/nrfconnect/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,19 @@ void AppTask::ActionInitiated(LightingManager::Action_t aAction, int32_t aActor)
{
LOG_INF("Level Action has been initiated");
}
else if (aAction == LightingManager::IDENTIFY_ACTION)
{
LOG_INF("Identify Action has been initiated");
// Turn off all LEDs before starting blink to make sure blink is co-ordinated.
// except the "main" LED which is PWMed
sStatusLED.Set(false);
sUnusedLED_1.Set(false);
sUnusedLED.Set(false);

sStatusLED.Blink(500);
sUnusedLED.Blink(500);
sUnusedLED_1.Blink(500);
}
}

void AppTask::ActionCompleted(LightingManager::Action_t aAction, int32_t aActor)
Expand All @@ -489,6 +502,10 @@ void AppTask::ActionCompleted(LightingManager::Action_t aAction, int32_t aActor)
{
LOG_INF("Level Action has been completed");
}
else if (aAction == LightingManager::IDENTIFY_ACTION)
{
LOG_INF("Identify Action has been completed");
}

if (aActor == AppEvent::kEventType_Button)
{
Expand Down
11 changes: 11 additions & 0 deletions examples/lighting-app/nrfconnect/main/ZclCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,17 @@ void emberAfPostAttributeChangeCallback(EndpointId endpoint, ClusterId clusterId
ChipLogError(Zcl, "wrong length for level: %d", size);
}
}
else if (clusterId == ZCL_IDENTIFY_CLUSTER_ID)
{
if (attributeId != ZCL_IDENTIFY_COMMAND_ID)
{
ChipLogProgress(Zcl, "Unknown Identify attribute ID: %d", attributeId);
return;
}
ChipLogProgress(Zcl, "Identify %u %u!!!", size, *value);
LightingMgr().InitiateAction(LightingManager::IDENTIFY_ACTION,
AppEvent::kEventType_Lighting, size, value);
}
else
{
ChipLogProgress(Zcl, "Unknown cluster ID: %" PRIx32, clusterId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class LightingManager
ON_ACTION = 0,
OFF_ACTION,
LEVEL_ACTION,
IDENTIFY_ACTION,

INVALID_ACTION
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,31 @@
******************************************************************************/

// this file contains all the common includes for clusters in the util
#include "app/framework/include/af.h"
#include "app/framework/util/common.h"
#include <app/CommandHandler.h>
#include <app/common/gen/attribute-id.h>
#include <app/common/gen/attribute-type.h>
#include <app/common/gen/cluster-id.h>
#include <app/common/gen/command-id.h>
#include <app/common/gen/enums.h>
#include <app/util/af.h>
#include <app/util/common.h>

#ifndef EZSP_HOST
#include "hal/hal.h"
//#include "hal/hal.h"
#endif

using namespace chip;

// Copied in from Z3LightSoc/Z3LightSoc.h
// Use this macro to check if ZLL Identify Server plugin is included
#define EMBER_AF_PLUGIN_ZLL_IDENTIFY_SERVER
// User options for plugin ZLL Identify Server
#define EMBER_AF_PLUGIN_ZLL_IDENTIFY_SERVER_EVENT_DELAY 1024
#define EMBER_AF_PLUGIN_ZLL_IDENTIFY_SERVER_BLINK_EVENTS 2
#define EMBER_AF_PLUGIN_ZLL_IDENTIFY_SERVER_BREATHE_EVENTS 4
#define EMBER_AF_PLUGIN_ZLL_IDENTIFY_SERVER_OKAY_EVENTS 6
#define EMBER_AF_PLUGIN_ZLL_IDENTIFY_SERVER_CHANNEL_CHANGE_EVENTS 8

typedef struct
{
bool active;
Expand All @@ -72,29 +89,29 @@ typedef struct
uint16_t eventDelay;
} EmAfZllIdentifyState;

void emAfPluginZllIdentifyServerBlinkEffect(uint8_t endpoint);
void emAfPluginZllIdentifyServerBlinkEffect(EndpointId endpoint);

void emAfPluginZllIdentifyServerBreatheEffect(uint8_t endpoint);
void emAfPluginZllIdentifyServerBreatheEffect(EndpointId endpoint);

void emAfPluginZllIdentifyServerOkayEffect(uint8_t endpoint);
void emAfPluginZllIdentifyServerOkayEffect(EndpointId endpoint);

void emAfPluginZllIdentifyServerChannelChangeEffect(uint8_t endpoint);
void emAfPluginZllIdentifyServerChannelChangeEffect(EndpointId endpoint);

extern EmberEventControl emberAfPluginZllIdentifyServerTriggerEffectEndpointEventControls[];

static EmAfZllIdentifyState stateTable[EMBER_AF_IDENTIFY_CLUSTER_SERVER_ENDPOINT_COUNT];

static EmAfZllIdentifyState * getZllIdentifyState(uint8_t endpoint);
static EmAfZllIdentifyState * getZllIdentifyState(EndpointId endpoint);

static void deactivateZllIdentify(EmAfZllIdentifyState * state, uint8_t endpoint);
static void deactivateZllIdentify(EmAfZllIdentifyState * state, EndpointId endpoint);

static EmAfZllIdentifyState * getZllIdentifyState(uint8_t endpoint)
static EmAfZllIdentifyState * getZllIdentifyState(EndpointId endpoint)
{
uint8_t index = emberAfFindClusterServerEndpointIndex(endpoint, ZCL_IDENTIFY_CLUSTER_ID);
return (index == 0xFF ? NULL : &stateTable[index]);
}

static void deactivateZllIdentify(EmAfZllIdentifyState * state, uint8_t endpoint)
static void deactivateZllIdentify(EmAfZllIdentifyState * state, EndpointId endpoint)
{
if (state == NULL)
{
Expand All @@ -107,7 +124,7 @@ static void deactivateZllIdentify(EmAfZllIdentifyState * state, uint8_t endpoint
emberAfEndpointEventControlSetInactive(emberAfPluginZllIdentifyServerTriggerEffectEndpointEventControls, endpoint);
}

void emberAfPluginZllIdentifyServerTriggerEffectEndpointEventHandler(uint8_t endpoint)
void emberAfPluginZllIdentifyServerTriggerEffectEndpointEventHandler(EndpointId endpoint)
{
EmAfZllIdentifyState * state = getZllIdentifyState(endpoint);

Expand Down Expand Up @@ -151,7 +168,7 @@ void emberAfPluginZllIdentifyServerTriggerEffectEndpointEventHandler(uint8_t end

bool emberAfIdentifyClusterTriggerEffectCallback(chip::app::CommandHandler * commandObj, uint8_t effectId, uint8_t effectVariant)
{
uint8_t endpoint = emberAfCurrentEndpoint();
EndpointId endpoint = emberAfCurrentEndpoint();
EmAfZllIdentifyState * state = getZllIdentifyState(endpoint);
EmberAfStatus status;

Expand Down Expand Up @@ -219,7 +236,7 @@ bool emberAfIdentifyClusterTriggerEffectCallback(chip::app::CommandHandler * com
return true;
}

void emAfPluginZllIdentifyServerBlinkEffect(uint8_t endpoint)
void emAfPluginZllIdentifyServerBlinkEffect(EndpointId endpoint)
{
EmAfZllIdentifyState * state = getZllIdentifyState(endpoint);

Expand All @@ -230,26 +247,26 @@ void emAfPluginZllIdentifyServerBlinkEffect(uint8_t endpoint)
}

#ifndef EZSP_HOST
halToggleLed(BOARDLED0);
halToggleLed(BOARDLED1);
halToggleLed(BOARDLED2);
halToggleLed(BOARDLED3);
// halToggleLed(BOARDLED0);
// halToggleLed(BOARDLED1);
// halToggleLed(BOARDLED2);
// halToggleLed(BOARDLED3);
#endif

state->eventsRemaining = state->eventsRemaining - 1;
}

void emAfPluginZllIdentifyServerBreatheEffect(uint8_t endpoint)
void emAfPluginZllIdentifyServerBreatheEffect(EndpointId endpoint)
{
emAfPluginZllIdentifyServerBlinkEffect(endpoint);
}

void emAfPluginZllIdentifyServerOkayEffect(uint8_t endpoint)
void emAfPluginZllIdentifyServerOkayEffect(EndpointId endpoint)
{
emAfPluginZllIdentifyServerBlinkEffect(endpoint);
}

void emAfPluginZllIdentifyServerChannelChangeEffect(uint8_t endpoint)
void emAfPluginZllIdentifyServerChannelChangeEffect(EndpointId endpoint)
{
emAfPluginZllIdentifyServerBlinkEffect(endpoint);
}
11 changes: 11 additions & 0 deletions src/app/util/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1068,6 +1068,17 @@ EmberStatus emberAfEndpointEventControlSetActive(EmberEventControl * controls, E
return EMBER_SUCCESS;
}

EmberStatus emberAfEndpointEventControlSetDelayMS(EmberEventControl *controls,
EndpointId endpoint,
uint32_t delayMs)
{
uint16_t index = emberAfIndexFromEndpoint(endpoint);
if (index == 0xFF) {
return EMBER_INVALID_ENDPOINT;
}
return emberEventControlSetDelayMS(&controls[index], delayMs);
}

uint8_t emberAfAppendCharacters(uint8_t * zclString, uint8_t zclStringMaxLen, const uint8_t * appendingChars,
uint8_t appendingCharsLen)
{
Expand Down

0 comments on commit 254fbf8

Please sign in to comment.