Skip to content

Commit

Permalink
add option to link App led to baseApplication to sync leds animations…
Browse files Browse the repository at this point in the history
…. More cleanup of duplicated or unused stuff
  • Loading branch information
jmartinez-silabs committed Nov 28, 2023
1 parent 02ebc69 commit c0b7f4e
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 55 deletions.
30 changes: 17 additions & 13 deletions examples/platform/silabs/BaseApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@

#include <app/server/Server.h>

#if (defined(ENABLE_WSTK_LEDS) && (defined(SL_CATALOG_SIMPLE_LED_LED1_PRESENT) || defined(SIWX_917)))
#include "LEDWidget.h"
#endif // ENABLE_WSTK_LEDS

#ifdef DISPLAY_ENABLED
#include "lcd.h"
#ifdef QR_CODE_ENABLED
Expand Down Expand Up @@ -146,8 +142,10 @@ Identify gIdentify = {

#endif // EMBER_AF_PLUGIN_IDENTIFY_SERVER
} // namespace

bool BaseApplication::sIsProvisioned = false;
bool BaseApplication::mIsFactoryResetTriggered = false;
bool BaseApplication::sIsFactoryResetTriggered = false;
LEDWidget * BaseApplication::sAppActionLed = nullptr;

#ifdef DIC_ENABLE
namespace {
Expand Down Expand Up @@ -280,7 +278,7 @@ void BaseApplication::FunctionEventHandler(AppEvent * aEvent)
{
VerifyOrReturn(aEvent->Type == AppEvent::kEventType_Timer);
// If we reached here, the button was held past FACTORY_RESET_TRIGGER_TIMEOUT,
if (!mIsFactoryResetTriggered)
if (!sIsFactoryResetTriggered)
{
StartFactoryResetSequence();
}
Expand Down Expand Up @@ -411,7 +409,8 @@ void BaseApplication::LightEventHandler()

#endif // CHIP_CONFIG_ENABLE_ICD_SERVER

#if (defined(ENABLE_WSTK_LEDS) && (defined(SL_CATALOG_SIMPLE_LED_LED1_PRESENT) || defined(SIWX_917)))
#if defined(ENABLE_WSTK_LEDS)
#if (defined(SL_CATALOG_SIMPLE_LED_LED1_PRESENT) || defined(SIWX_917))
// Update the status LED if factory reset has not been initiated.
//
// If system has "full connectivity", keep the LED On constantly.
Expand All @@ -424,13 +423,18 @@ void BaseApplication::LightEventHandler()
// the LEDs at an even rate of 100ms.
//
// Otherwise, blink the LED ON for a very short time.
if (!mIsFactoryResetTriggered)
if (!sIsFactoryResetTriggered)
{
ActivateStatusLedPatterns();
}

sStatusLED.Animate();
#endif // ENABLE_WSTK_LEDS && SL_CATALOG_SIMPLE_LED_LED1_PRESENT
#endif // SL_CATALOG_SIMPLE_LED_LED1_PRESENT
if (sAppActionLed)
{
sAppActionLed->Animate();
}
#endif // ENABLE_WSTK_LEDS
}

void BaseApplication::ButtonHandler(AppEvent * aEvent)
Expand All @@ -448,7 +452,7 @@ void BaseApplication::ButtonHandler(AppEvent * aEvent)
}
else
{
if (mIsFactoryResetTriggered)
if (sIsFactoryResetTriggered)
{
CancelFactoryResetSequence();
}
Expand Down Expand Up @@ -531,7 +535,7 @@ void BaseApplication::StartFactoryResetSequence()
// cancel, if required.
StartFunctionTimer(FACTORY_RESET_CANCEL_WINDOW_TIMEOUT);

mIsFactoryResetTriggered = true;
sIsFactoryResetTriggered = true;
#if CHIP_CONFIG_ENABLE_ICD_SERVER == 1
StartStatusLEDTimer();
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER
Expand All @@ -551,9 +555,9 @@ void BaseApplication::CancelFactoryResetSequence()
#if CHIP_CONFIG_ENABLE_ICD_SERVER == 1
StopStatusLEDTimer();
#endif
if (mIsFactoryResetTriggered)
if (sIsFactoryResetTriggered)
{
mIsFactoryResetTriggered = false;
sIsFactoryResetTriggered = false;
SILABS_LOG("Factory Reset has been Canceled");
}
}
Expand Down
21 changes: 20 additions & 1 deletion examples/platform/silabs/BaseApplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
#include <platform/CHIPDeviceEvent.h>
#include <platform/CHIPDeviceLayer.h>

#if defined(ENABLE_WSTK_LEDS)
#include "LEDWidget.h"
#endif // ENABLE_WSTK_LEDS

#ifdef EMBER_AF_PLUGIN_IDENTIFY_SERVER
#include <app/clusters/identify-server/identify-server.h>
#endif
Expand Down Expand Up @@ -71,7 +75,8 @@ class BaseApplication
BaseApplication() = default;
virtual ~BaseApplication(){};
static bool sIsProvisioned;
static bool mIsFactoryResetTriggered;
static bool sIsFactoryResetTriggered;
static LEDWidget * sAppActionLed;

/**
* @brief Create AppTask task and Event Queue
Expand All @@ -81,6 +86,20 @@ class BaseApplication
*/
CHIP_ERROR StartAppTask(TaskFunction_t taskFunction);

/**
* @brief Links the application specific led to the baseApplication context
* in order to synchronize both LED animations.
* Some apps may not have an application led or no animation patterns.
*
* @param appLed Pointer to the configure LEDWidget for the application defined LED
*/
void LinkAppLed(LEDWidget * appLed) { sAppActionLed = appLed; }

/**
* @brief Remove the app Led linkage form the baseApplication context
*/
void UnlinkAppLed() { sAppActionLed = nullptr; }

/**
* @brief PostEvent function that add event to AppTask queue for processing
*
Expand Down
29 changes: 0 additions & 29 deletions examples/window-app/silabs/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@

#include "WindowManager.h"

#include "LEDWidget.h"

#include <app/clusters/on-off-server/on-off-server.h>
#include <app/server/OnboardingCodesUtil.h>
#include <app/server/Server.h>
Expand All @@ -39,20 +37,10 @@

#include <lib/support/CodeUtils.h>

#if !defined(BRD2704A)
#define LIGHT_LED 1
#else
#define LIGHT_LED 0
#endif

using namespace chip;
using namespace ::chip::DeviceLayer;
using namespace ::chip::DeviceLayer::Silabs;

namespace {
LEDWidget sLightLED;
}

using namespace chip::TLV;
using namespace ::chip::DeviceLayer;

Expand Down Expand Up @@ -82,23 +70,6 @@ CHIP_ERROR AppTask::Init()
appError(err);
}

sLightLED.Init(LIGHT_LED);

// Update the LCD with the Stored value. Show QR Code if not provisioned
#ifdef DISPLAY_ENABLED

#ifdef QR_CODE_ENABLED
#ifdef SL_WIFI
if (!ConnectivityMgr().IsWiFiStationProvisioned())
#else
if (!ConnectivityMgr().IsThreadProvisioned())
#endif /* !SL_WIFI */
{
GetLCD().ShowQRCode(true);
}
#endif // QR_CODE_ENABLED
#endif

return err;
}

Expand Down
14 changes: 2 additions & 12 deletions examples/window-app/silabs/src/WindowManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@

#ifdef DISPLAY_ENABLED
#include <LcdPainter.h>
SilabsLCD slLCD;
#endif

#include <platform/silabs/platformAbstraction/SilabsPlatform.h>
Expand Down Expand Up @@ -602,8 +601,6 @@ CHIP_ERROR WindowManager::Init()
{
chip::DeviceLayer::PlatformMgr().LockChipStack();

ConfigurationMgr().LogDeviceConfig();

// Timers
mLongPressTimer = new Timer(LONG_PRESS_TIMEOUT, OnLongPressTimeout, this);

Expand All @@ -614,10 +611,7 @@ CHIP_ERROR WindowManager::Init()
// Initialize LEDs
LEDWidget::InitGpio();
mActionLED.Init(APP_ACTION_LED);

#ifdef DISPLAY_ENABLED
slLCD.Init();
#endif
AppTask::GetAppTask().LinkAppLed(&mActionLED);

chip::DeviceLayer::PlatformMgr().UnlockChipStack();

Expand All @@ -637,13 +631,11 @@ void WindowManager::UpdateLED()
Cover & cover = GetCover();
if (mResetWarning)
{
SILABS_LOG("---- UPDATE ACTION LED mResetWarning")
mActionLED.Set(false);
mActionLED.Blink(500);
}
else
{
SILABS_LOG("******* UPDATE ACTION LED NORMAL")
// Action LED
NPercent100ths current;
LimitStatus liftLimit = LimitStatus::Intermediate;
Expand All @@ -664,12 +656,10 @@ void WindowManager::UpdateLED()
}
else if (LimitStatus::IsUpOrOpen == liftLimit)
{
SILABS_LOG("---- UPDATE ACTION LED IsUpOrOpen")
mActionLED.Set(true);
}
else if (LimitStatus::IsDownOrClose == liftLimit)
{
SILABS_LOG("---- UPDATE ACTION LED IsDownOrClose")
mActionLED.Set(false);
}
else
Expand Down Expand Up @@ -698,7 +688,7 @@ void WindowManager::UpdateLCD()

if (!tilt.IsNull() && !lift.IsNull())
{
LcdPainter::Paint(slLCD, type, lift.Value(), tilt.Value(), mIcon);
LcdPainter::Paint(AppTask::GetAppTask().GetLCD(), type, lift.Value(), tilt.Value(), mIcon);
}
}
#endif // DISPLAY_ENABLED
Expand Down

0 comments on commit c0b7f4e

Please sign in to comment.