3 * Copyright (c) 2020 Project CHIP Authors
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
20 * Copyright (c) 2020 Silicon Labs
22 * Licensed under the Apache License, Version 2.0 (the "License");
23 * you may not use this file except in compliance with the License.
24 * You may obtain a copy of the License at
26 * http://www.apache.org/licenses/LICENSE-2.0
28 * Unless required by applicable law or agreed to in writing, software
29 * distributed under the License is distributed on an "AS IS" BASIS,
30 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 * See the License for the specific language governing permissions and
32 * limitations under the License.
37 * @brief Routines for the ZLL Identify Server plugin,
38 * which contains additions to the Identify server
40 *******************************************************************************
42 * <b>Copyright 2018 Silicon Laboratories Inc. www.silabs.com</b>
43 *******************************************************************************
45 * The licensor of this software is Silicon
46 * Laboratories Inc. Your use of this software is
47 * governed by the terms of Silicon Labs Master
48 * Software License Agreement (MSLA) available at
49 * www.silabs.com/about-us/legal/master-software-license-agreement.
50 * This software is distributed to you in Source Code
51 * format and is governed by the sections of the MSLA
52 * applicable to Source Code.
54 ******************************************************************************/
56 // this file contains all the common includes for clusters in the util
57 #include "app/framework/include/af.h"
58 #include "app/framework/util/common.h"
68 EmberAfIdentifyEffectIdentifier effectId;
69 EmberAfIdentifyEffectVariant commandVariant;
70 uint8_t eventsRemaining;
72 } EmAfZllIdentifyState;
74 void emAfPluginZllIdentifyServerBlinkEffect(uint8_t endpoint);
76 void emAfPluginZllIdentifyServerBreatheEffect(uint8_t endpoint);
78 void emAfPluginZllIdentifyServerOkayEffect(uint8_t endpoint);
80 void emAfPluginZllIdentifyServerChannelChangeEffect(uint8_t endpoint);
82 extern EmberEventControl emberAfPluginZllIdentifyServerTriggerEffectEndpointEventControls[];
84 static EmAfZllIdentifyState stateTable[EMBER_AF_IDENTIFY_CLUSTER_SERVER_ENDPOINT_COUNT];
86 static EmAfZllIdentifyState * getZllIdentifyState(uint8_t endpoint);
88 static void deactivateZllIdentify(EmAfZllIdentifyState * state, uint8_t endpoint);
90 static EmAfZllIdentifyState * getZllIdentifyState(uint8_t endpoint)
92 uint8_t index = emberAfFindClusterServerEndpointIndex(endpoint, ZCL_IDENTIFY_CLUSTER_ID);
93 return (index == 0xFF ? NULL : &stateTable[index]);
96 static void deactivateZllIdentify(EmAfZllIdentifyState * state, uint8_t endpoint)
103 state->active = false;
104 state->cancel = false;
106 emberAfEndpointEventControlSetInactive(emberAfPluginZllIdentifyServerTriggerEffectEndpointEventControls, endpoint);
109 void emberAfPluginZllIdentifyServerTriggerEffectEndpointEventHandler(uint8_t endpoint)
111 EmAfZllIdentifyState * state = getZllIdentifyState(endpoint);
118 switch (state->effectId)
120 case EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_BLINK:
121 emAfPluginZllIdentifyServerBlinkEffect(endpoint);
123 case EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_BREATHE:
124 emAfPluginZllIdentifyServerBreatheEffect(endpoint);
126 case EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_OKAY:
127 emAfPluginZllIdentifyServerOkayEffect(endpoint);
129 case EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_CHANNEL_CHANGE:
130 emAfPluginZllIdentifyServerChannelChangeEffect(endpoint);
132 case EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_FINISH_EFFECT: // At this point, these are functionally equivalent
133 case EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_STOP_EFFECT:
135 deactivateZllIdentify(state, endpoint);
140 deactivateZllIdentify(state, endpoint);
146 emberAfEndpointEventControlSetDelayMS(emberAfPluginZllIdentifyServerTriggerEffectEndpointEventControls, endpoint,
151 bool emberAfIdentifyClusterTriggerEffectCallback(uint8_t effectId, uint8_t effectVariant)
153 uint8_t endpoint = emberAfCurrentEndpoint();
154 EmAfZllIdentifyState * state = getZllIdentifyState(endpoint);
155 EmberAfStatus status;
159 status = EMBER_ZCL_STATUS_FAILURE;
160 goto default_response;
163 emberAfIdentifyClusterPrintln("RX identify:trigger effect 0x%x variant 0x%x", effectId, effectVariant);
167 switch (state->effectId)
169 case EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_FINISH_EFFECT:
170 state->cancel = true;
171 status = EMBER_ZCL_STATUS_SUCCESS;
173 case EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_STOP_EFFECT:
174 deactivateZllIdentify(state, endpoint);
175 status = EMBER_ZCL_STATUS_SUCCESS;
176 goto default_response;
178 status = EMBER_ZCL_STATUS_FAILURE;
186 case EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_BLINK:
187 state->eventsRemaining = EMBER_AF_PLUGIN_ZLL_IDENTIFY_SERVER_BLINK_EVENTS;
189 case EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_BREATHE:
190 state->eventsRemaining = EMBER_AF_PLUGIN_ZLL_IDENTIFY_SERVER_BREATHE_EVENTS;
192 case EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_OKAY:
193 state->eventsRemaining = EMBER_AF_PLUGIN_ZLL_IDENTIFY_SERVER_OKAY_EVENTS;
195 case EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_CHANNEL_CHANGE:
196 state->eventsRemaining = EMBER_AF_PLUGIN_ZLL_IDENTIFY_SERVER_CHANNEL_CHANGE_EVENTS;
198 case EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_FINISH_EFFECT: // At this point, these are functionally equivalent
199 case EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_STOP_EFFECT:
200 status = EMBER_ZCL_STATUS_SUCCESS;
201 goto default_response;
203 status = EMBER_ZCL_STATUS_FAILURE;
204 goto default_response;
206 state->active = true;
207 state->cancel = false;
208 state->effectId = (EmberAfIdentifyEffectIdentifier) effectId;
209 state->commandVariant = (EmberAfIdentifyEffectVariant) effectVariant;
210 state->eventDelay = EMBER_AF_PLUGIN_ZLL_IDENTIFY_SERVER_EVENT_DELAY;
211 emberAfEndpointEventControlSetDelayMS(emberAfPluginZllIdentifyServerTriggerEffectEndpointEventControls, endpoint,
213 status = EMBER_ZCL_STATUS_SUCCESS;
217 emberAfSendImmediateDefaultResponse(status);
221 void emAfPluginZllIdentifyServerBlinkEffect(uint8_t endpoint)
223 EmAfZllIdentifyState * state = getZllIdentifyState(endpoint);
225 if (state == NULL || state->eventsRemaining == 0)
227 deactivateZllIdentify(state, endpoint);
232 halToggleLed(BOARDLED0);
233 halToggleLed(BOARDLED1);
234 halToggleLed(BOARDLED2);
235 halToggleLed(BOARDLED3);
238 state->eventsRemaining = state->eventsRemaining - 1;
241 void emAfPluginZllIdentifyServerBreatheEffect(uint8_t endpoint)
243 emAfPluginZllIdentifyServerBlinkEffect(endpoint);
246 void emAfPluginZllIdentifyServerOkayEffect(uint8_t endpoint)
248 emAfPluginZllIdentifyServerBlinkEffect(endpoint);
251 void emAfPluginZllIdentifyServerChannelChangeEffect(uint8_t endpoint)
253 emAfPluginZllIdentifyServerBlinkEffect(endpoint);