Skip to content

Commit

Permalink
[Silabs]Make changes to the window manager class so its static constr…
Browse files Browse the repository at this point in the history
…uctor do… (project-chip#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 <[email protected]>
  • Loading branch information
jmartinez-silabs and restyled-commits authored May 15, 2024
1 parent 82da364 commit 1b455b5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
5 changes: 3 additions & 2 deletions examples/window-app/silabs/include/WindowManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class WindowManager
typedef void (*Callback)(Timer & timer);

Timer(uint32_t timeoutInMs, Callback callback, void * context);
~Timer();

void Start();
void Stop();
Expand Down Expand Up @@ -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
};
26 changes: 20 additions & 6 deletions examples/window-app/silabs/src/WindowManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
{
Expand All @@ -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);

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 1b455b5

Please sign in to comment.