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 all 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
10 changes: 10 additions & 0 deletions examples/air-quality-sensor-app/silabs/include/AppEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@

#pragma once
#include <cstdint>
#ifdef DISPLAY_ENABLED
#include "lcd.h"
#endif

struct AppEvent;
typedef void (*EventHandler)(AppEvent *);
Expand All @@ -28,6 +31,7 @@ struct AppEvent
enum AppEventTypes
{
kEventType_Button = 0,
kEventType_LCD,
kEventType_Timer,
kEventType_AirQualitySensor,
kEventType_Install,
Expand All @@ -41,6 +45,12 @@ struct AppEvent
{
uint8_t Action;
} ButtonEvent;
#ifdef DISPLAY_ENABLED
struct
{
SilabsLCD::Screen_e screen;
} LCDEvent;
#endif
struct
{
void * Context;
Expand Down
11 changes: 11 additions & 0 deletions examples/chef/silabs/include/AppEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@

#pragma once

#ifdef DISPLAY_ENABLED
#include "lcd.h"
#endif

struct AppEvent;
typedef void (*EventHandler)(AppEvent *);

Expand All @@ -27,6 +31,7 @@ struct AppEvent
enum AppEventTypes
{
kEventType_Button = 0,
kEventType_LCD,
kEventType_Timer,
kEventType_Light,
kEventType_Install,
Expand All @@ -40,6 +45,12 @@ struct AppEvent
{
uint8_t Action;
} ButtonEvent;
#ifdef DISPLAY_ENABLED
struct
{
SilabsLCD::Screen_e screen;
} LCDEvent;
#endif
struct
{
void * Context;
Expand Down
11 changes: 11 additions & 0 deletions examples/energy-management-app/silabs/include/AppEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@

#pragma once

#ifdef DISPLAY_ENABLED
#include "lcd.h"
#endif

struct AppEvent;
typedef void (*EventHandler)(AppEvent *);

Expand All @@ -27,6 +31,7 @@ struct AppEvent
enum AppEventTypes
{
kEventType_Button = 0,
kEventType_LCD,
kEventType_Timer,
kEventType_Install,
};
Expand All @@ -39,6 +44,12 @@ struct AppEvent
{
uint8_t Action;
} ButtonEvent;
#ifdef DISPLAY_ENABLED
struct
{
SilabsLCD::Screen_e screen;
} LCDEvent;
#endif
struct
{
void * Context;
Expand Down
10 changes: 10 additions & 0 deletions examples/light-switch-app/silabs/include/AppEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
#pragma once

#include <cstdint>
#ifdef DISPLAY_ENABLED
#include "lcd.h"
#endif

struct AppEvent;
typedef void (*EventHandler)(AppEvent *);
Expand All @@ -29,6 +32,7 @@ struct AppEvent
enum AppEventTypes
{
kEventType_Button = 0,
kEventType_LCD,
kEventType_Timer,
kEventType_Light,
kEventType_Install,
Expand All @@ -51,6 +55,12 @@ struct AppEvent
{
uint8_t Action;
} ButtonEvent;
#ifdef DISPLAY_ENABLED
struct
{
SilabsLCD::Screen_e screen;
} LCDEvent;
#endif
struct
{
void * Context;
Expand Down
11 changes: 11 additions & 0 deletions examples/lighting-app/silabs/include/AppEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@

#pragma once

#ifdef DISPLAY_ENABLED
#include "lcd.h"
#endif

struct AppEvent;
typedef void (*EventHandler)(AppEvent *);

Expand All @@ -27,6 +31,7 @@ struct AppEvent
enum AppEventTypes
{
kEventType_Button = 0,
kEventType_LCD,
kEventType_Timer,
kEventType_Light,
kEventType_Install,
Expand All @@ -40,6 +45,12 @@ struct AppEvent
{
uint8_t Action;
} ButtonEvent;
#ifdef DISPLAY_ENABLED
struct
{
SilabsLCD::Screen_e screen;
} LCDEvent;
#endif
struct
{
void * Context;
Expand Down
11 changes: 11 additions & 0 deletions examples/lit-icd-app/silabs/include/AppEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@

#pragma once

#ifdef DISPLAY_ENABLED
#include "lcd.h"
#endif

struct AppEvent;
typedef void (*EventHandler)(AppEvent *);

Expand All @@ -26,6 +30,7 @@ struct AppEvent
enum AppEventTypes
{
kEventType_Button = 0,
kEventType_LCD,
kEventType_Timer,
};

Expand All @@ -37,6 +42,12 @@ struct AppEvent
{
uint8_t Action;
} ButtonEvent;
#ifdef DISPLAY_ENABLED
struct
{
SilabsLCD::Screen_e screen;
} LCDEvent;
#endif
struct
{
void * Context;
Expand Down
11 changes: 11 additions & 0 deletions examples/lock-app/silabs/include/AppEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@

#pragma once

#ifdef DISPLAY_ENABLED
#include "lcd.h"
#endif

struct AppEvent;
typedef void (*EventHandler)(AppEvent *);

Expand All @@ -27,6 +31,7 @@ struct AppEvent
enum AppEventTypes
{
kEventType_Button = 0,
kEventType_LCD,
kEventType_Timer,
kEventType_Lock,
kEventType_Install,
Expand All @@ -40,6 +45,12 @@ struct AppEvent
{
uint8_t Action;
} ButtonEvent;
#ifdef DISPLAY_ENABLED
struct
{
SilabsLCD::Screen_e screen;
} LCDEvent;
#endif
struct
{
void * Context;
Expand Down
60 changes: 37 additions & 23 deletions examples/platform/silabs/BaseApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ void BaseApplicationDelegate::OnCommissioningWindowClosed()
SilabsLCD::Screen_e screen;
slLCD.GetScreen(screen);
VerifyOrReturn(screen == SilabsLCD::Screen_e::QRCodeScreen);
slLCD.SetScreen(SilabsLCD::Screen_e::DemoScreen);
BaseApplication::PostUpdateDisplayEvent(SilabsLCD::Screen_e::DemoScreen);
#endif // QR_CODE_ENABLED
#endif // DISPLAY_ENABLED
}
Expand Down Expand Up @@ -597,8 +597,6 @@ void BaseApplication::ButtonHandler(AppEvent * aEvent)
// - Cycle LCD screen
CancelFunctionTimer();

AppTask::GetAppTask().UpdateDisplay();

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

void BaseApplication::UpdateDisplay()
{
OutputQrCode(false);
// Print the QR Code
OutputQrCode(false);
#ifdef DISPLAY_ENABLED
UpdateLCDStatusScreen();
slLCD.CycleScreens();
#endif
PostUpdateDisplayEvent(SilabsLCD::Screen_e::CycleScreen);
#endif // DISPLAY_ENABLED
}
}
}

void BaseApplication::CancelFunctionTimer()
Expand Down Expand Up @@ -793,14 +788,37 @@ SilabsLCD & BaseApplication::GetLCD(void)
return slLCD;
}

void BaseApplication::UpdateLCDStatusScreen(bool withChipStackLock)
void BaseApplication::PostUpdateDisplayEvent(SilabsLCD::Screen_e screen)
{
SilabsLCD::DisplayStatus_t status;
bool enabled, attached;
if (withChipStackLock)
AppEvent event;
event.Type = AppEvent::kEventType_LCD;
event.LCDEvent.screen = screen;
event.Handler = AppTask::GetAppTask().UpdateDisplayHandler;
BaseApplication::PostEvent(&event);
}

void BaseApplication::UpdateDisplayHandler(AppEvent * aEvent)
{
VerifyOrReturn(aEvent->Type == AppEvent::kEventType_LCD);
SilabsLCD::Screen_e screen = aEvent->LCDEvent.screen;
if (screen == SilabsLCD::Screen_e::StatusScreen)
{
chip::DeviceLayer::PlatformMgr().LockChipStack();
UpdateLCDStatusScreen();
}
(screen == SilabsLCD::Screen_e::CycleScreen) ? AppTask::GetAppTask().UpdateDisplay() : AppTask::GetLCD().SetScreen(screen);
}

void BaseApplication::UpdateDisplay()
{
UpdateLCDStatusScreen();
slLCD.CycleScreens();
}

void BaseApplication::UpdateLCDStatusScreen()
{
SilabsLCD::DisplayStatus_t status;
bool enabled, attached;
chip::DeviceLayer::PlatformMgr().LockChipStack();
#ifdef SL_WIFI
enabled = ConnectivityMgr().IsWiFiStationEnabled();
attached = ConnectivityMgr().IsWiFiStationConnected();
Expand All @@ -825,10 +843,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 +950,7 @@ 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);
PostUpdateDisplayEvent(SilabsLCD::Screen_e::StatusScreen);
}
#endif // DISPLAY_ENABLED

Expand Down
23 changes: 19 additions & 4 deletions examples/platform/silabs/BaseApplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,18 +127,33 @@ class BaseApplication

static void PostEvent(const AppEvent * event);

#ifdef DISPLAY_ENABLED
/**
* @brief Return LCD object
*/
static SilabsLCD & GetLCD(void);

static void UpdateLCDStatusScreen();

/**
* @brief Overridable function used to update display on button press
*/
virtual void UpdateDisplay();

#ifdef DISPLAY_ENABLED
/**
* @brief Return LCD object
* @brief LCD Event processing function
* Update the LCD status based on the screen
*
* @param aEvent post event being processed
*/
static SilabsLCD & GetLCD(void);
static void UpdateDisplayHandler(AppEvent * aEvent);

static void UpdateLCDStatusScreen(bool withChipStackLock = true);
/**
* @brief Post an event to update the display screen
*
* @param screen The screen to be displayed
*/
static void PostUpdateDisplayEvent(SilabsLCD::Screen_e screen);
#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 @@ -39,6 +39,7 @@ class SilabsLCD
#ifdef QR_CODE_ENABLED
QRCodeScreen,
#endif
CycleScreen,
InvalidScreen,
} Screen_e;

Expand Down
Loading
Loading