Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SL-UP] Adding app event for the LCD update #368

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions examples/lighting-app/silabs/include/AppEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ struct AppEvent
enum AppEventTypes
{
kEventType_Button = 0,
kEventType_LCD,
kEventType_Timer,
kEventType_Light,
kEventType_Install,
Expand All @@ -40,6 +41,12 @@ struct AppEvent
{
uint8_t Action;
} ButtonEvent;
#ifdef DISPLAY_ENABLED
struct
{
void * screen;
} LCDEvent;
#endif
struct
{
void * Context;
Expand Down
40 changes: 26 additions & 14 deletions examples/platform/silabs/BaseApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,11 @@ void BaseApplicationDelegate::OnCommissioningWindowClosed()
SilabsLCD::Screen_e screen;
slLCD.GetScreen(screen);
VerifyOrReturn(screen == SilabsLCD::Screen_e::QRCodeScreen);
slLCD.SetScreen(SilabsLCD::Screen_e::DemoScreen);
AppEvent event;
event.Type = AppEvent::kEventType_LCD;
event.LCDEvent.screen = reinterpret_cast<void *>(static_cast<uintptr_t>(SilabsLCD::Screen_e::DemoScreen));
event.Handler = AppTask::GetAppTask().UpdateDisplayHandler;
BaseApplication::PostEvent(&event);
#endif // QR_CODE_ENABLED
#endif // DISPLAY_ENABLED
}
Expand Down Expand Up @@ -597,8 +601,6 @@ void BaseApplication::ButtonHandler(AppEvent * aEvent)
// - Cycle LCD screen
CancelFunctionTimer();

AppTask::GetAppTask().UpdateDisplay();

#ifdef SL_WIFI
if (!ConnectivityMgr().IsWiFiStationProvisioned())
#else
Expand All @@ -622,10 +624,23 @@ void BaseApplication::ButtonHandler(AppEvent * aEvent)
PlatformMgr().ScheduleWork([](intptr_t) { ICDNotifier::GetInstance().NotifyNetworkActivityNotification(); });
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER
}

AppEvent event;
event.Type = AppEvent::kEventType_LCD;
event.LCDEvent.screen = reinterpret_cast<void *>(static_cast<uintptr_t>(SilabsLCD::Screen_e::CycleScreen));
event.Handler = AppTask::GetAppTask().UpdateDisplayHandler;
PostEvent(&event);
}
}
}

void BaseApplication::UpdateDisplayHandler(AppEvent * aEvent)
{
VerifyOrReturn(aEvent->Type == AppEvent::kEventType_LCD);
SilabsLCD::Screen_e screen = static_cast<SilabsLCD::Screen_e>(reinterpret_cast<uintptr_t>(aEvent->LCDEvent.screen));
(screen == SilabsLCD::Screen_e::CycleScreen) ? AppTask::GetAppTask().UpdateDisplay() : AppTask::GetLCD().SetScreen(screen);
}

void BaseApplication::UpdateDisplay()
{
OutputQrCode(false);
Expand Down Expand Up @@ -793,14 +808,11 @@ SilabsLCD & BaseApplication::GetLCD(void)
return slLCD;
}

void BaseApplication::UpdateLCDStatusScreen(bool withChipStackLock)
void BaseApplication::UpdateLCDStatusScreen()
{
SilabsLCD::DisplayStatus_t status;
bool enabled, attached;
if (withChipStackLock)
{
chip::DeviceLayer::PlatformMgr().LockChipStack();
}
chip::DeviceLayer::PlatformMgr().LockChipStack();
#ifdef SL_WIFI
enabled = ConnectivityMgr().IsWiFiStationEnabled();
attached = ConnectivityMgr().IsWiFiStationConnected();
Expand All @@ -825,10 +837,7 @@ void BaseApplication::UpdateLCDStatusScreen(bool withChipStackLock)
? SilabsLCD::ICDMode_e::SIT
: SilabsLCD::ICDMode_e::LIT;
#endif
if (withChipStackLock)
{
chip::DeviceLayer::PlatformMgr().UnlockChipStack();
}
chip::DeviceLayer::PlatformMgr().UnlockChipStack();
slLCD.SetStatus(status);
}
#endif
Expand Down Expand Up @@ -935,8 +944,11 @@ void BaseApplication::OnPlatformEvent(const ChipDeviceEvent * event, intptr_t)
// Update the LCD screen with SSID and connected state
if (screen == SilabsLCD::Screen_e::StatusScreen)
{
BaseApplication::UpdateLCDStatusScreen(false);
AppTask::GetLCD().SetScreen(screen);
AppEvent event;
event.Type = AppEvent::kEventType_LCD;
event.LCDEvent.screen = reinterpret_cast<void *>(static_cast<uintptr_t>(SilabsLCD::Screen_e::StatusScreen));
event.Handler = AppTask::GetAppTask().UpdateDisplayHandler;
PostEvent(&event);
}
#endif // DISPLAY_ENABLED

Expand Down
10 changes: 9 additions & 1 deletion examples/platform/silabs/BaseApplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,15 @@ class BaseApplication
*/
static SilabsLCD & GetLCD(void);

static void UpdateLCDStatusScreen(bool withChipStackLock = true);
static void UpdateLCDStatusScreen();

/**
* @brief LCD Event processing function
* Update the LCD status based on the screen
*
* @param aEvent post event being processed
*/
static void UpdateDisplayHandler(AppEvent * aEvent);
#endif

/**
Expand Down
1 change: 1 addition & 0 deletions examples/platform/silabs/display/lcd.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class SilabsLCD
QRCodeScreen,
#endif
InvalidScreen,
CycleScreen,
} Screen_e;

typedef enum icdMode
Expand Down
Loading