From 1b455b5c3c826f78b6278b3bb1faa02ad1ac301d Mon Sep 17 00:00:00 2001 From: Junior Martinez <67972863+jmartinez-silabs@users.noreply.github.com> Date: Wed, 15 May 2024 16:06:45 -0400 Subject: [PATCH] =?UTF-8?q?[Silabs]Make=20changes=20to=20the=20window=20ma?= =?UTF-8?q?nager=20class=20so=20its=20static=20constructor=20do=E2=80=A6?= =?UTF-8?q?=20(#33473)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Make changes to the window manager class so its static constructor do not call a dynamic allocation before code entry. Limitation with sl memory manager * Restyled by clang-format * implement a destructor for the Timer object to delete the allocated timer --------- Co-authored-by: Restyled.io --- .../window-app/silabs/include/WindowManager.h | 5 ++-- .../window-app/silabs/src/WindowManager.cpp | 26 ++++++++++++++----- 2 files changed, 23 insertions(+), 8 deletions(-) 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;