Skip to content

Commit 085bd03

Browse files
[SL-UP] Adding app event for the LCD update (#368)
1 parent cbc98dd commit 085bd03

File tree

15 files changed

+185
-27
lines changed

15 files changed

+185
-27
lines changed

examples/air-quality-sensor-app/silabs/include/AppEvent.h

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

2020
#pragma once
2121
#include <cstdint>
22+
#ifdef DISPLAY_ENABLED
23+
#include "lcd.h"
24+
#endif
2225

2326
struct AppEvent;
2427
typedef void (*EventHandler)(AppEvent *);
@@ -28,6 +31,7 @@ struct AppEvent
2831
enum AppEventTypes
2932
{
3033
kEventType_Button = 0,
34+
kEventType_LCD,
3135
kEventType_Timer,
3236
kEventType_AirQualitySensor,
3337
kEventType_Install,
@@ -41,6 +45,12 @@ struct AppEvent
4145
{
4246
uint8_t Action;
4347
} ButtonEvent;
48+
#ifdef DISPLAY_ENABLED
49+
struct
50+
{
51+
SilabsLCD::Screen_e screen;
52+
} LCDEvent;
53+
#endif
4454
struct
4555
{
4656
void * Context;

examples/chef/silabs/include/AppEvent.h

+11
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919

2020
#pragma once
2121

22+
#ifdef DISPLAY_ENABLED
23+
#include "lcd.h"
24+
#endif
25+
2226
struct AppEvent;
2327
typedef void (*EventHandler)(AppEvent *);
2428

@@ -27,6 +31,7 @@ struct AppEvent
2731
enum AppEventTypes
2832
{
2933
kEventType_Button = 0,
34+
kEventType_LCD,
3035
kEventType_Timer,
3136
kEventType_Light,
3237
kEventType_Install,
@@ -40,6 +45,12 @@ struct AppEvent
4045
{
4146
uint8_t Action;
4247
} ButtonEvent;
48+
#ifdef DISPLAY_ENABLED
49+
struct
50+
{
51+
SilabsLCD::Screen_e screen;
52+
} LCDEvent;
53+
#endif
4354
struct
4455
{
4556
void * Context;

examples/energy-management-app/silabs/include/AppEvent.h

+11
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919

2020
#pragma once
2121

22+
#ifdef DISPLAY_ENABLED
23+
#include "lcd.h"
24+
#endif
25+
2226
struct AppEvent;
2327
typedef void (*EventHandler)(AppEvent *);
2428

@@ -27,6 +31,7 @@ struct AppEvent
2731
enum AppEventTypes
2832
{
2933
kEventType_Button = 0,
34+
kEventType_LCD,
3035
kEventType_Timer,
3136
kEventType_Install,
3237
};
@@ -39,6 +44,12 @@ struct AppEvent
3944
{
4045
uint8_t Action;
4146
} ButtonEvent;
47+
#ifdef DISPLAY_ENABLED
48+
struct
49+
{
50+
SilabsLCD::Screen_e screen;
51+
} LCDEvent;
52+
#endif
4253
struct
4354
{
4455
void * Context;

examples/light-switch-app/silabs/include/AppEvent.h

+10
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
#pragma once
2121

2222
#include <cstdint>
23+
#ifdef DISPLAY_ENABLED
24+
#include "lcd.h"
25+
#endif
2326

2427
struct AppEvent;
2528
typedef void (*EventHandler)(AppEvent *);
@@ -29,6 +32,7 @@ struct AppEvent
2932
enum AppEventTypes
3033
{
3134
kEventType_Button = 0,
35+
kEventType_LCD,
3236
kEventType_Timer,
3337
kEventType_Light,
3438
kEventType_Install,
@@ -51,6 +55,12 @@ struct AppEvent
5155
{
5256
uint8_t Action;
5357
} ButtonEvent;
58+
#ifdef DISPLAY_ENABLED
59+
struct
60+
{
61+
SilabsLCD::Screen_e screen;
62+
} LCDEvent;
63+
#endif
5464
struct
5565
{
5666
void * Context;

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

+11
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919

2020
#pragma once
2121

22+
#ifdef DISPLAY_ENABLED
23+
#include "lcd.h"
24+
#endif
25+
2226
struct AppEvent;
2327
typedef void (*EventHandler)(AppEvent *);
2428

@@ -27,6 +31,7 @@ struct AppEvent
2731
enum AppEventTypes
2832
{
2933
kEventType_Button = 0,
34+
kEventType_LCD,
3035
kEventType_Timer,
3136
kEventType_Light,
3237
kEventType_Install,
@@ -40,6 +45,12 @@ struct AppEvent
4045
{
4146
uint8_t Action;
4247
} ButtonEvent;
48+
#ifdef DISPLAY_ENABLED
49+
struct
50+
{
51+
SilabsLCD::Screen_e screen;
52+
} LCDEvent;
53+
#endif
4354
struct
4455
{
4556
void * Context;

examples/lit-icd-app/silabs/include/AppEvent.h

+11
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818

1919
#pragma once
2020

21+
#ifdef DISPLAY_ENABLED
22+
#include "lcd.h"
23+
#endif
24+
2125
struct AppEvent;
2226
typedef void (*EventHandler)(AppEvent *);
2327

@@ -26,6 +30,7 @@ struct AppEvent
2630
enum AppEventTypes
2731
{
2832
kEventType_Button = 0,
33+
kEventType_LCD,
2934
kEventType_Timer,
3035
};
3136

@@ -37,6 +42,12 @@ struct AppEvent
3742
{
3843
uint8_t Action;
3944
} ButtonEvent;
45+
#ifdef DISPLAY_ENABLED
46+
struct
47+
{
48+
SilabsLCD::Screen_e screen;
49+
} LCDEvent;
50+
#endif
4051
struct
4152
{
4253
void * Context;

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

+11
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919

2020
#pragma once
2121

22+
#ifdef DISPLAY_ENABLED
23+
#include "lcd.h"
24+
#endif
25+
2226
struct AppEvent;
2327
typedef void (*EventHandler)(AppEvent *);
2428

@@ -27,6 +31,7 @@ struct AppEvent
2731
enum AppEventTypes
2832
{
2933
kEventType_Button = 0,
34+
kEventType_LCD,
3035
kEventType_Timer,
3136
kEventType_Lock,
3237
kEventType_Install,
@@ -40,6 +45,12 @@ struct AppEvent
4045
{
4146
uint8_t Action;
4247
} ButtonEvent;
48+
#ifdef DISPLAY_ENABLED
49+
struct
50+
{
51+
SilabsLCD::Screen_e screen;
52+
} LCDEvent;
53+
#endif
4354
struct
4455
{
4556
void * Context;

examples/platform/silabs/BaseApplication.cpp

+37-23
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ void BaseApplicationDelegate::OnCommissioningWindowClosed()
251251
SilabsLCD::Screen_e screen;
252252
slLCD.GetScreen(screen);
253253
VerifyOrReturn(screen == SilabsLCD::Screen_e::QRCodeScreen);
254-
slLCD.SetScreen(SilabsLCD::Screen_e::DemoScreen);
254+
BaseApplication::PostUpdateDisplayEvent(SilabsLCD::Screen_e::DemoScreen);
255255
#endif // QR_CODE_ENABLED
256256
#endif // DISPLAY_ENABLED
257257
}
@@ -597,8 +597,6 @@ void BaseApplication::ButtonHandler(AppEvent * aEvent)
597597
// - Cycle LCD screen
598598
CancelFunctionTimer();
599599

600-
AppTask::GetAppTask().UpdateDisplay();
601-
602600
#ifdef SL_WIFI
603601
if (!ConnectivityMgr().IsWiFiStationProvisioned())
604602
#else
@@ -622,17 +620,14 @@ void BaseApplication::ButtonHandler(AppEvent * aEvent)
622620
PlatformMgr().ScheduleWork([](intptr_t) { ICDNotifier::GetInstance().NotifyNetworkActivityNotification(); });
623621
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER
624622
}
625-
}
626-
}
627-
}
628623

629-
void BaseApplication::UpdateDisplay()
630-
{
631-
OutputQrCode(false);
624+
// Print the QR Code
625+
OutputQrCode(false);
632626
#ifdef DISPLAY_ENABLED
633-
UpdateLCDStatusScreen();
634-
slLCD.CycleScreens();
635-
#endif
627+
PostUpdateDisplayEvent(SilabsLCD::Screen_e::CycleScreen);
628+
#endif // DISPLAY_ENABLED
629+
}
630+
}
636631
}
637632

638633
void BaseApplication::CancelFunctionTimer()
@@ -793,14 +788,37 @@ SilabsLCD & BaseApplication::GetLCD(void)
793788
return slLCD;
794789
}
795790

796-
void BaseApplication::UpdateLCDStatusScreen(bool withChipStackLock)
791+
void BaseApplication::PostUpdateDisplayEvent(SilabsLCD::Screen_e screen)
797792
{
798-
SilabsLCD::DisplayStatus_t status;
799-
bool enabled, attached;
800-
if (withChipStackLock)
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)
801805
{
802-
chip::DeviceLayer::PlatformMgr().LockChipStack();
806+
UpdateLCDStatusScreen();
803807
}
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+
817+
void BaseApplication::UpdateLCDStatusScreen()
818+
{
819+
SilabsLCD::DisplayStatus_t status;
820+
bool enabled, attached;
821+
chip::DeviceLayer::PlatformMgr().LockChipStack();
804822
#ifdef SL_WIFI
805823
enabled = ConnectivityMgr().IsWiFiStationEnabled();
806824
attached = ConnectivityMgr().IsWiFiStationConnected();
@@ -825,10 +843,7 @@ void BaseApplication::UpdateLCDStatusScreen(bool withChipStackLock)
825843
? SilabsLCD::ICDMode_e::SIT
826844
: SilabsLCD::ICDMode_e::LIT;
827845
#endif
828-
if (withChipStackLock)
829-
{
830-
chip::DeviceLayer::PlatformMgr().UnlockChipStack();
831-
}
846+
chip::DeviceLayer::PlatformMgr().UnlockChipStack();
832847
slLCD.SetStatus(status);
833848
}
834849
#endif
@@ -935,8 +950,7 @@ void BaseApplication::OnPlatformEvent(const ChipDeviceEvent * event, intptr_t)
935950
// Update the LCD screen with SSID and connected state
936951
if (screen == SilabsLCD::Screen_e::StatusScreen)
937952
{
938-
BaseApplication::UpdateLCDStatusScreen(false);
939-
AppTask::GetLCD().SetScreen(screen);
953+
PostUpdateDisplayEvent(SilabsLCD::Screen_e::StatusScreen);
940954
}
941955
#endif // DISPLAY_ENABLED
942956

examples/platform/silabs/BaseApplication.h

+19-4
Original file line numberDiff line numberDiff line change
@@ -127,18 +127,33 @@ class BaseApplication
127127

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

130+
#ifdef DISPLAY_ENABLED
131+
/**
132+
* @brief Return LCD object
133+
*/
134+
static SilabsLCD & GetLCD(void);
135+
136+
static void UpdateLCDStatusScreen();
137+
130138
/**
131139
* @brief Overridable function used to update display on button press
132140
*/
133141
virtual void UpdateDisplay();
134142

135-
#ifdef DISPLAY_ENABLED
136143
/**
137-
* @brief Return LCD object
144+
* @brief LCD Event processing function
145+
* Update the LCD status based on the screen
146+
*
147+
* @param aEvent post event being processed
138148
*/
139-
static SilabsLCD & GetLCD(void);
149+
static void UpdateDisplayHandler(AppEvent * aEvent);
140150

141-
static void UpdateLCDStatusScreen(bool withChipStackLock = true);
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);
142157
#endif
143158

144159
/**

examples/platform/silabs/display/lcd.h

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class SilabsLCD
3939
#ifdef QR_CODE_ENABLED
4040
QRCodeScreen,
4141
#endif
42+
CycleScreen,
4243
InvalidScreen,
4344
} Screen_e;
4445

0 commit comments

Comments
 (0)