Skip to content

Commit 1b455b5

Browse files
[Silabs]Make changes to the window manager class so its static constructor do… (#33473)
* 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 <commits@restyled.io>
1 parent 82da364 commit 1b455b5

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

examples/window-app/silabs/include/WindowManager.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class WindowManager
4040
typedef void (*Callback)(Timer & timer);
4141

4242
Timer(uint32_t timeoutInMs, Callback callback, void * context);
43+
~Timer();
4344

4445
void Start();
4546
void Stop();
@@ -155,7 +156,7 @@ class WindowManager
155156

156157
LEDWidget mActionLED;
157158
#ifdef DISPLAY_ENABLED
158-
Timer mIconTimer;
159-
LcdIcon mIcon = LcdIcon::None;
159+
Timer * mIconTimer = nullptr;
160+
LcdIcon mIcon = LcdIcon::None;
160161
#endif
161162
};

examples/window-app/silabs/src/WindowManager.cpp

+20-6
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,15 @@ WindowManager::Timer::Timer(uint32_t timeoutInMs, Callback callback, void * cont
514514
}
515515
}
516516

517+
WindowManager::Timer::~Timer()
518+
{
519+
if (mHandler)
520+
{
521+
osTimerDelete(mHandler);
522+
mHandler = nullptr;
523+
}
524+
}
525+
517526
void WindowManager::Timer::Stop()
518527
{
519528
mIsActive = false;
@@ -538,11 +547,7 @@ WindowManager & WindowManager::Instance()
538547
return WindowManager::sWindow;
539548
}
540549

541-
#ifdef DISPLAY_ENABLED
542-
WindowManager::WindowManager() : mIconTimer(LCD_ICON_TIMEOUT, OnIconTimeout, this) {}
543-
#else
544550
WindowManager::WindowManager() {}
545-
#endif
546551

547552
void WindowManager::OnIconTimeout(WindowManager::Timer & timer)
548553
{
@@ -556,6 +561,9 @@ CHIP_ERROR WindowManager::Init()
556561
{
557562
chip::DeviceLayer::PlatformMgr().LockChipStack();
558563

564+
#ifdef DISPLAY_ENABLED
565+
mIconTimer = new Timer(LCD_ICON_TIMEOUT, OnIconTimeout, this);
566+
#endif
559567
// Timers
560568
mLongPressTimer = new Timer(LONG_PRESS_TIMEOUT, OnLongPressTimeout, this);
561569

@@ -768,13 +776,19 @@ void WindowManager::GeneralEventHandler(AppEvent * aEvent)
768776
window->UpdateLCD();
769777
break;
770778
case AppEvent::kEventType_CoverChange:
771-
window->mIconTimer.Start();
779+
if (window->mIconTimer != nullptr)
780+
{
781+
window->mIconTimer->Start();
782+
}
772783
window->mIcon = (window->GetCover().mEndpoint == 1) ? LcdIcon::One : LcdIcon::Two;
773784
window->UpdateLCD();
774785
break;
775786
case AppEvent::kEventType_TiltModeChange:
776787
ChipLogDetail(AppServer, "App control mode changed to %s", window->mTiltMode ? "Tilt" : "Lift");
777-
window->mIconTimer.Start();
788+
if (window->mIconTimer != nullptr)
789+
{
790+
window->mIconTimer->Start();
791+
}
778792
window->mIcon = window->mTiltMode ? LcdIcon::Tilt : LcdIcon::Lift;
779793
window->UpdateLCD();
780794
break;

0 commit comments

Comments
 (0)