Skip to content

Commit

Permalink
Restyled by clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
restyled-commits authored and andrei-menzopol committed Aug 19, 2022
1 parent 140e6ec commit 863b8b0
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 79 deletions.
139 changes: 66 additions & 73 deletions examples/lighting-app/nxp/k32w/k32w0/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,12 @@ using namespace chip;

AppTask AppTask::sAppTask;

static Identify gIdentify = {
chip::EndpointId{1},
AppTask::OnIdentifyStart,
AppTask::OnIdentifyStop,
EMBER_ZCL_IDENTIFY_IDENTIFY_TYPE_VISIBLE_LED,
AppTask::OnTriggerEffect,
//Use invalid value for identifiers to enable TriggerEffect command
//to stop Identify command for each effect
(EmberAfIdentifyEffectIdentifier)(EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_STOP_EFFECT - 0x10),
EMBER_ZCL_IDENTIFY_EFFECT_VARIANT_DEFAULT
};
static Identify gIdentify = { chip::EndpointId{ 1 }, AppTask::OnIdentifyStart, AppTask::OnIdentifyStop,
EMBER_ZCL_IDENTIFY_IDENTIFY_TYPE_VISIBLE_LED, AppTask::OnTriggerEffect,
// Use invalid value for identifiers to enable TriggerEffect command
// to stop Identify command for each effect
(EmberAfIdentifyEffectIdentifier)(EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_STOP_EFFECT - 0x10),
EMBER_ZCL_IDENTIFY_EFFECT_VARIANT_DEFAULT };

/* OTA related variables */
#if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR
Expand Down Expand Up @@ -687,7 +682,7 @@ void AppTask::ActionCompleted(LightingManager::Action_t aAction)

void AppTask::RestoreLightingState(void)
{
/* restore initial state for the LED indicating Lighting state */
/* restore initial state for the LED indicating Lighting state */
if (LightingMgr().IsTurnedOff())
{
sLightLED.Set(false);
Expand All @@ -698,91 +693,90 @@ void AppTask::RestoreLightingState(void)
}
}

void AppTask::OnIdentifyStart(Identify* identify)
void AppTask::OnIdentifyStart(Identify * identify)
{
if ((kFunction_NoneSelected != sAppTask.mFunction) && (kFunction_TriggerEffect != sAppTask.mFunction))
{
K32W_LOG("Another function is scheduled. Could not initiate Identify process!");
return;
}
if ((kFunction_NoneSelected != sAppTask.mFunction) && (kFunction_TriggerEffect != sAppTask.mFunction))
{
K32W_LOG("Another function is scheduled. Could not initiate Identify process!");
return;
}

if (kFunction_TriggerEffect == sAppTask.mFunction)
{
chip::DeviceLayer::SystemLayer().CancelTimer(OnTriggerEffectComplete, identify);
OnTriggerEffectComplete(&chip::DeviceLayer::SystemLayer(), identify);
}
if (kFunction_TriggerEffect == sAppTask.mFunction)
{
chip::DeviceLayer::SystemLayer().CancelTimer(OnTriggerEffectComplete, identify);
OnTriggerEffectComplete(&chip::DeviceLayer::SystemLayer(), identify);
}

ChipLogProgress(Zcl,"Identify process has started. Status LED should blink with a period of 0.5 seconds.");
sAppTask.mFunction = kFunction_Identify;
sLightLED.Set(false);
sLightLED.Blink(250);
ChipLogProgress(Zcl, "Identify process has started. Status LED should blink with a period of 0.5 seconds.");
sAppTask.mFunction = kFunction_Identify;
sLightLED.Set(false);
sLightLED.Blink(250);
}

void AppTask::OnIdentifyStop(Identify* identify)
void AppTask::OnIdentifyStop(Identify * identify)
{
if (kFunction_Identify == sAppTask.mFunction)
{
ChipLogProgress(Zcl,"Identify process has stopped.");
sAppTask.mFunction = kFunction_NoneSelected;

RestoreLightingState();
if (kFunction_Identify == sAppTask.mFunction)
{
ChipLogProgress(Zcl, "Identify process has stopped.");
sAppTask.mFunction = kFunction_NoneSelected;

}
RestoreLightingState();
}
}

void AppTask::OnTriggerEffectComplete(chip::System::Layer * systemLayer, void * appState)
{
//Let Identify command take over if called during TriggerEffect already running
if (kFunction_TriggerEffect == sAppTask.mFunction)
{
ChipLogProgress(Zcl,"TriggerEffect has stopped.");
sAppTask.mFunction = kFunction_NoneSelected;
// Let Identify command take over if called during TriggerEffect already running
if (kFunction_TriggerEffect == sAppTask.mFunction)
{
ChipLogProgress(Zcl, "TriggerEffect has stopped.");
sAppTask.mFunction = kFunction_NoneSelected;

//TriggerEffect finished - reset identifiers
//Use invalid value for identifiers to enable TriggerEffect command
//to stop Identify command for each effect
gIdentify.mCurrentEffectIdentifier = (EmberAfIdentifyEffectIdentifier)(EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_STOP_EFFECT - 0x10);
gIdentify.mTargetEffectIdentifier = (EmberAfIdentifyEffectIdentifier)(EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_STOP_EFFECT - 0x10);
gIdentify.mEffectVariant = EMBER_ZCL_IDENTIFY_EFFECT_VARIANT_DEFAULT;
// TriggerEffect finished - reset identifiers
// Use invalid value for identifiers to enable TriggerEffect command
// to stop Identify command for each effect
gIdentify.mCurrentEffectIdentifier =
(EmberAfIdentifyEffectIdentifier)(EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_STOP_EFFECT - 0x10);
gIdentify.mTargetEffectIdentifier =
(EmberAfIdentifyEffectIdentifier)(EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_STOP_EFFECT - 0x10);
gIdentify.mEffectVariant = EMBER_ZCL_IDENTIFY_EFFECT_VARIANT_DEFAULT;

RestoreLightingState();
}
RestoreLightingState();
}
}

void AppTask::OnTriggerEffect(Identify* identify)
void AppTask::OnTriggerEffect(Identify * identify)
{
//Allow overlapping TriggerEffect calls
if ((kFunction_NoneSelected != sAppTask.mFunction) && (kFunction_TriggerEffect != sAppTask.mFunction))
{
K32W_LOG("Another function is scheduled. Could not initiate Identify process!");
return;
}

sAppTask.mFunction = kFunction_TriggerEffect;
uint16_t timerDelay = 0;
// Allow overlapping TriggerEffect calls
if ((kFunction_NoneSelected != sAppTask.mFunction) && (kFunction_TriggerEffect != sAppTask.mFunction))
{
K32W_LOG("Another function is scheduled. Could not initiate Identify process!");
return;
}

ChipLogProgress(Zcl,"TriggerEffect has started.");
sAppTask.mFunction = kFunction_TriggerEffect;
uint16_t timerDelay = 0;

ChipLogProgress(Zcl, "TriggerEffect has started.");

switch (identify->mCurrentEffectIdentifier)
{
case EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_BLINK:
timerDelay = 2;
break;
timerDelay = 2;
break;

case EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_BREATHE:
timerDelay = 15;
break;
timerDelay = 15;
break;

case EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_OKAY:
timerDelay = 4;
timerDelay = 4;
break;

case EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_CHANNEL_CHANGE:
ChipLogProgress(Zcl,"Channel Change effect not supported, using effect %d",
EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_BLINK);
timerDelay = 2;
break;
ChipLogProgress(Zcl, "Channel Change effect not supported, using effect %d", EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_BLINK);
timerDelay = 2;
break;

case EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_FINISH_EFFECT:
chip::DeviceLayer::SystemLayer().CancelTimer(OnTriggerEffectComplete, identify);
Expand All @@ -798,13 +792,12 @@ void AppTask::OnTriggerEffect(Identify* identify)
ChipLogProgress(Zcl, "Invalid effect identifier.");
}

if(timerDelay)
if (timerDelay)
{
sLightLED.Set(false);
sLightLED.Blink(500);
sLightLED.Set(false);
sLightLED.Blink(500);

chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Seconds16(timerDelay), OnTriggerEffectComplete,
identify);
chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Seconds16(timerDelay), OnTriggerEffectComplete, identify);
}
}

Expand Down
10 changes: 5 additions & 5 deletions examples/lighting-app/nxp/k32w/k32w0/main/include/AppTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
#include "AppEvent.h"
#include "LightingManager.h"

#include <platform/CHIPDeviceLayer.h>
#include <app/clusters/identify-server/identify-server.h>
#include <platform/CHIPDeviceLayer.h>

#include "FreeRTOS.h"
#include "timers.h"
Expand All @@ -51,9 +51,9 @@ class AppTask
void UpdateDeviceState(void);

// Identify cluster callbacks.
static void OnIdentifyStart(Identify* identify);
static void OnIdentifyStop(Identify* identify);
static void OnTriggerEffect(Identify* identify);
static void OnIdentifyStart(Identify * identify);
static void OnIdentifyStop(Identify * identify);
static void OnTriggerEffect(Identify * identify);
static void OnTriggerEffectComplete(chip::System::Layer * systemLayer, void * appState);

private:
Expand Down Expand Up @@ -103,7 +103,7 @@ class AppTask
kFunction_FactoryReset,
kFunctionTurnOnTurnOff,
kFunction_Identify,
kFunction_TriggerEffect,
kFunction_TriggerEffect,

kFunction_Invalid
} Function;
Expand Down
2 changes: 1 addition & 1 deletion src/app/clusters/identify-server/identify-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ void MatterIdentifyClusterServerAttributeChangedCallback(const app::ConcreteAttr
/* finish identify process */
if (EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_FINISH_EFFECT == identify->mCurrentEffectIdentifier && identifyTime > 0)
{
Clusters::Identify::Attributes::IdentifyTime::Set(endpoint, 1);
Clusters::Identify::Attributes::IdentifyTime::Set(endpoint, 1);
}
/* stop identify process */
if (EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_STOP_EFFECT == identify->mCurrentEffectIdentifier && identifyTime > 0)
Expand Down

0 comments on commit 863b8b0

Please sign in to comment.