diff --git a/examples/window-app/silabs/include/WindowManager.h b/examples/window-app/silabs/include/WindowManager.h index 8ae75e8ed48c94..7578396c8f67f6 100644 --- a/examples/window-app/silabs/include/WindowManager.h +++ b/examples/window-app/silabs/include/WindowManager.h @@ -40,6 +40,7 @@ class WindowManager typedef void (*Callback)(Timer & timer); Timer(uint32_t timeoutInMs, Callback callback, void * context); + ~Timer(); void Start(); void Stop(); @@ -155,7 +156,7 @@ class WindowManager LEDWidget mActionLED; #ifdef DISPLAY_ENABLED - Timer mIconTimer; - LcdIcon mIcon = LcdIcon::None; + Timer * mIconTimer = nullptr; + LcdIcon mIcon = LcdIcon::None; #endif }; diff --git a/examples/window-app/silabs/src/WindowManager.cpp b/examples/window-app/silabs/src/WindowManager.cpp index 0b8639dc04e93b..8ae78b3d2e99b8 100644 --- a/examples/window-app/silabs/src/WindowManager.cpp +++ b/examples/window-app/silabs/src/WindowManager.cpp @@ -514,6 +514,15 @@ WindowManager::Timer::Timer(uint32_t timeoutInMs, Callback callback, void * cont } } +WindowManager::Timer::~Timer() +{ + if (mHandler) + { + osTimerDelete(mHandler); + mHandler = nullptr; + } +} + void WindowManager::Timer::Stop() { mIsActive = false; @@ -538,11 +547,7 @@ WindowManager & WindowManager::Instance() return WindowManager::sWindow; } -#ifdef DISPLAY_ENABLED -WindowManager::WindowManager() : mIconTimer(LCD_ICON_TIMEOUT, OnIconTimeout, this) {} -#else WindowManager::WindowManager() {} -#endif void WindowManager::OnIconTimeout(WindowManager::Timer & timer) { @@ -556,6 +561,9 @@ CHIP_ERROR WindowManager::Init() { chip::DeviceLayer::PlatformMgr().LockChipStack(); +#ifdef DISPLAY_ENABLED + mIconTimer = new Timer(LCD_ICON_TIMEOUT, OnIconTimeout, this); +#endif // Timers mLongPressTimer = new Timer(LONG_PRESS_TIMEOUT, OnLongPressTimeout, this); @@ -768,13 +776,19 @@ void WindowManager::GeneralEventHandler(AppEvent * aEvent) window->UpdateLCD(); break; case AppEvent::kEventType_CoverChange: - window->mIconTimer.Start(); + if (window->mIconTimer != nullptr) + { + window->mIconTimer->Start(); + } window->mIcon = (window->GetCover().mEndpoint == 1) ? LcdIcon::One : LcdIcon::Two; window->UpdateLCD(); break; case AppEvent::kEventType_TiltModeChange: ChipLogDetail(AppServer, "App control mode changed to %s", window->mTiltMode ? "Tilt" : "Lift"); - window->mIconTimer.Start(); + if (window->mIconTimer != nullptr) + { + window->mIconTimer->Start(); + } window->mIcon = window->mTiltMode ? LcdIcon::Tilt : LcdIcon::Lift; window->UpdateLCD(); break;