Skip to content

Commit c9ec64f

Browse files
committed
updating the PR based on comments
1 parent ab88b33 commit c9ec64f

File tree

4 files changed

+50
-38
lines changed

4 files changed

+50
-38
lines changed

examples/lighting-app/silabs/include/AppEvent.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919

2020
#pragma once
2121

22+
#ifdef DISPLAY_ENABLED
23+
#include "lcd.h"
24+
#endif
2225
struct AppEvent;
2326
typedef void (*EventHandler)(AppEvent *);
2427

@@ -44,7 +47,7 @@ struct AppEvent
4447
#ifdef DISPLAY_ENABLED
4548
struct
4649
{
47-
void * screen;
50+
SilabsLCD::Screen_e screen;
4851
} LCDEvent;
4952
#endif
5053
struct

examples/platform/silabs/BaseApplication.cpp

+33-31
Original file line numberDiff line numberDiff line change
@@ -251,11 +251,7 @@ void BaseApplicationDelegate::OnCommissioningWindowClosed()
251251
SilabsLCD::Screen_e screen;
252252
slLCD.GetScreen(screen);
253253
VerifyOrReturn(screen == SilabsLCD::Screen_e::QRCodeScreen);
254-
AppEvent event;
255-
event.Type = AppEvent::kEventType_LCD;
256-
event.LCDEvent.screen = reinterpret_cast<void *>(static_cast<uintptr_t>(SilabsLCD::Screen_e::DemoScreen));
257-
event.Handler = AppTask::GetAppTask().UpdateDisplayHandler;
258-
BaseApplication::PostEvent(&event);
254+
BaseApplication::PostUpdateDisplayEvent(SilabsLCD::Screen_e::DemoScreen);
259255
#endif // QR_CODE_ENABLED
260256
#endif // DISPLAY_ENABLED
261257
}
@@ -625,31 +621,15 @@ void BaseApplication::ButtonHandler(AppEvent * aEvent)
625621
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER
626622
}
627623

628-
AppEvent event;
629-
event.Type = AppEvent::kEventType_LCD;
630-
event.LCDEvent.screen = reinterpret_cast<void *>(static_cast<uintptr_t>(SilabsLCD::Screen_e::CycleScreen));
631-
event.Handler = AppTask::GetAppTask().UpdateDisplayHandler;
632-
PostEvent(&event);
624+
// Print the QR Code
625+
OutputQrCode(false);
626+
#ifdef DISPLAY_ENABLED
627+
PostUpdateDisplayEvent(SilabsLCD::Screen_e::CycleScreen);
628+
#endif // DISPLAY_ENABLED
633629
}
634630
}
635631
}
636632

637-
void BaseApplication::UpdateDisplayHandler(AppEvent * aEvent)
638-
{
639-
VerifyOrReturn(aEvent->Type == AppEvent::kEventType_LCD);
640-
SilabsLCD::Screen_e screen = static_cast<SilabsLCD::Screen_e>(reinterpret_cast<uintptr_t>(aEvent->LCDEvent.screen));
641-
(screen == SilabsLCD::Screen_e::CycleScreen) ? AppTask::GetAppTask().UpdateDisplay() : AppTask::GetLCD().SetScreen(screen);
642-
}
643-
644-
void BaseApplication::UpdateDisplay()
645-
{
646-
OutputQrCode(false);
647-
#ifdef DISPLAY_ENABLED
648-
UpdateLCDStatusScreen();
649-
slLCD.CycleScreens();
650-
#endif
651-
}
652-
653633
void BaseApplication::CancelFunctionTimer()
654634
{
655635
if (osTimerStop(sFunctionTimer) == osError)
@@ -808,6 +788,32 @@ SilabsLCD & BaseApplication::GetLCD(void)
808788
return slLCD;
809789
}
810790

791+
void BaseApplication::PostUpdateDisplayEvent(SilabsLCD::Screen_e screen)
792+
{
793+
AppEvent event;
794+
event.Type = AppEvent::kEventType_LCD;
795+
event.LCDEvent.screen = screen;
796+
event.Handler = AppTask::GetAppTask().UpdateDisplayHandler;
797+
BaseApplication::PostEvent(&event);
798+
}
799+
800+
void BaseApplication::UpdateDisplayHandler(AppEvent * aEvent)
801+
{
802+
VerifyOrReturn(aEvent->Type == AppEvent::kEventType_LCD);
803+
SilabsLCD::Screen_e screen = aEvent->LCDEvent.screen;
804+
if (screen == SilabsLCD::Screen_e::StatusScreen)
805+
{
806+
UpdateLCDStatusScreen();
807+
}
808+
(screen == SilabsLCD::Screen_e::CycleScreen) ? AppTask::GetAppTask().UpdateDisplay() : AppTask::GetLCD().SetScreen(screen);
809+
}
810+
811+
void BaseApplication::UpdateDisplay()
812+
{
813+
UpdateLCDStatusScreen();
814+
slLCD.CycleScreens();
815+
}
816+
811817
void BaseApplication::UpdateLCDStatusScreen()
812818
{
813819
SilabsLCD::DisplayStatus_t status;
@@ -944,11 +950,7 @@ void BaseApplication::OnPlatformEvent(const ChipDeviceEvent * event, intptr_t)
944950
// Update the LCD screen with SSID and connected state
945951
if (screen == SilabsLCD::Screen_e::StatusScreen)
946952
{
947-
AppEvent event;
948-
event.Type = AppEvent::kEventType_LCD;
949-
event.LCDEvent.screen = reinterpret_cast<void *>(static_cast<uintptr_t>(SilabsLCD::Screen_e::StatusScreen));
950-
event.Handler = AppTask::GetAppTask().UpdateDisplayHandler;
951-
PostEvent(&event);
953+
PostUpdateDisplayEvent(SilabsLCD::Screen_e::StatusScreen);
952954
}
953955
#endif // DISPLAY_ENABLED
954956

examples/platform/silabs/BaseApplication.h

+12-5
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,6 @@ class BaseApplication
127127

128128
static void PostEvent(const AppEvent * event);
129129

130-
/**
131-
* @brief Overridable function used to update display on button press
132-
*/
133-
virtual void UpdateDisplay();
134-
135130
#ifdef DISPLAY_ENABLED
136131
/**
137132
* @brief Return LCD object
@@ -140,13 +135,25 @@ class BaseApplication
140135

141136
static void UpdateLCDStatusScreen();
142137

138+
/**
139+
* @brief Overridable function used to update display on button press
140+
*/
141+
virtual void UpdateDisplay();
142+
143143
/**
144144
* @brief LCD Event processing function
145145
* Update the LCD status based on the screen
146146
*
147147
* @param aEvent post event being processed
148148
*/
149149
static void UpdateDisplayHandler(AppEvent * aEvent);
150+
151+
/**
152+
* @brief Post an event to update the display screen
153+
*
154+
* @param screen The screen to be displayed
155+
*/
156+
static void PostUpdateDisplayEvent(SilabsLCD::Screen_e screen);
150157
#endif
151158

152159
/**

examples/platform/silabs/display/lcd.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ class SilabsLCD
3939
#ifdef QR_CODE_ENABLED
4040
QRCodeScreen,
4141
#endif
42-
InvalidScreen,
4342
CycleScreen,
43+
InvalidScreen,
4444
} Screen_e;
4545

4646
typedef enum icdMode

0 commit comments

Comments
 (0)