Skip to content

Commit 5827461

Browse files
Updated LcdPainter class
1 parent e7ccc66 commit 5827461

3 files changed

Lines changed: 51 additions & 26 deletions

File tree

examples/window-app/silabs/include/LcdPainter.h

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,24 @@ enum class LcdIcon
3333
Tilt
3434
};
3535

36+
using chip::app::Clusters::WindowCovering::Type;
37+
3638
class LcdPainter
3739
{
3840
public:
39-
static void Paint(SilabsLCD & lcd, chip::app::Clusters::WindowCovering::Type type, uint16_t lift, uint16_t tilt, LcdIcon icon);
41+
/** Binds the display used by static Paint(); call once after GetLCD().Init() (e.g. from WindowManager::Init). */
42+
explicit LcdPainter(SilabsLCD & lcd);
43+
44+
static void Paint(Type type, uint16_t lift, uint16_t tilt, LcdIcon icon);
45+
46+
LcdPainter(const LcdPainter &) = delete;
47+
LcdPainter & operator=(const LcdPainter &) = delete;
48+
LcdPainter(LcdPainter &&) = delete;
49+
LcdPainter & operator=(LcdPainter &&) = delete;
4050

4151
private:
42-
static void ClearScreen(SilabsLCD & lcd);
52+
static void ClearScreen();
53+
54+
static SilabsLCD * sLcd;
55+
static bool mLcdCleared;
4356
};

examples/window-app/silabs/src/LcdPainter.cpp

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,19 @@
1919

2020
#include "demo-ui-bitmaps.h"
2121
#include <LcdPainter.h>
22-
22+
#include <AppConfig.h>
2323
#include <cstdint>
2424
#include <cstdio>
2525

2626
using namespace chip::app::Clusters::WindowCovering;
2727

28+
SilabsLCD * LcdPainter::sLcd = nullptr;
29+
bool LcdPainter::mLcdCleared = false;
30+
2831
namespace {
2932
static const uint8_t sSilabsLogoSmall[] = { SILABS_LOGO_SMALL };
3033
static const uint8_t sMatterLogo[] = { MATTER_LOGO_BITMAP };
3134

32-
// Shared with ClearScreen: first Paint draws logos, title, and Lift/Tilt labels; percent row updates every Paint.
33-
static bool sLcdCleared = false;
34-
3535
static unsigned RawToWholePercent(uint16_t raw, int openLimit, int closedLimit)
3636
{
3737
const int denom = closedLimit - openLimit;
@@ -43,41 +43,52 @@ static unsigned RawToWholePercent(uint16_t raw, int openLimit, int closedLimit)
4343
}
4444
} // namespace
4545

46-
void LcdPainter::ClearScreen(SilabsLCD & lcd)
46+
LcdPainter::LcdPainter(SilabsLCD & lcd)
47+
{
48+
sLcd = &lcd;
49+
}
50+
51+
void LcdPainter::ClearScreen()
4752
{
48-
if (sLcdCleared)
53+
if (mLcdCleared || sLcd == nullptr)
4954
{
5055
return;
5156
}
52-
lcd.Clear();
53-
lcd.Update();
54-
sLcdCleared = true;
57+
sLcd->Clear();
58+
sLcd->Update();
59+
mLcdCleared = true;
5560
}
5661

57-
void LcdPainter::Paint(SilabsLCD & lcd, Type type, uint16_t lift, uint16_t tilt, LcdIcon icon)
62+
void LcdPainter::Paint(Type type, uint16_t lift, uint16_t tilt, LcdIcon icon)
5863
{
5964
(void) type;
65+
(void) icon;
66+
67+
if (sLcd == nullptr)
68+
{
69+
return;
70+
}
6071

61-
const bool drawStaticChrome = !sLcdCleared;
62-
ClearScreen(lcd);
72+
const bool drawStaticChrome = !mLcdCleared;
73+
ClearScreen();
6374

6475
const unsigned liftPct = RawToWholePercent(lift, LIFT_OPEN_LIMIT, LIFT_CLOSED_LIMIT);
6576
const unsigned tiltPct = RawToWholePercent(tilt, TILT_OPEN_LIMIT, TILT_CLOSED_LIMIT);
6677

67-
GLIB_Context_t * glibContext = static_cast<GLIB_Context_t *>(lcd.Context());
78+
GLIB_Context_t * glibContext = static_cast<GLIB_Context_t *>(sLcd->Context());
6879
const int32_t xSize = glibContext->pDisplayGeometry->xSize;
6980

7081
char buf[32];
7182
if (drawStaticChrome)
7283
{
7384
const int32_t silabsX = (xSize - SILABS_LOGO_WIDTH) / 2;
74-
(void) GLIB_drawBitmap(glibContext, silabsX, 0, SILABS_LOGO_WIDTH, SILABS_LOGO_HEIGHT, sSilabsLogoSmall);
75-
(void) GLIB_drawBitmap(glibContext, MATTER_ICON_POSITION_X, 4, MATTER_LOGO_WIDTH, MATTER_LOGO_HEIGHT, sMatterLogo);
85+
GLIB_drawBitmap(glibContext, silabsX, 0, SILABS_LOGO_WIDTH, SILABS_LOGO_HEIGHT, sSilabsLogoSmall);
86+
GLIB_drawBitmap(glibContext, MATTER_ICON_POSITION_X, 4, MATTER_LOGO_WIDTH, MATTER_LOGO_HEIGHT, sMatterLogo);
7687

77-
(void) GLIB_drawStringOnLine(glibContext, "Window App", 4, GLIB_ALIGN_CENTER, 0, 0, true);
78-
(void) GLIB_drawStringOnLine(glibContext, "Lift Tilt", 6, GLIB_ALIGN_CENTER, 0, 0, true);
88+
GLIB_drawStringOnLine(glibContext, "Window App", 4, GLIB_ALIGN_CENTER, 0, 0, true);
89+
GLIB_drawStringOnLine(glibContext, "Lift Tilt", 6, GLIB_ALIGN_CENTER, 0, 0, true);
7990
}
8091
snprintf(buf, sizeof(buf), "%3u%% %3u%%", liftPct, tiltPct);
81-
(void) GLIB_drawStringOnLine(glibContext, buf, 8, GLIB_ALIGN_CENTER, 0, 0, true);
82-
lcd.Update();
92+
GLIB_drawStringOnLine(glibContext, buf, 8, GLIB_ALIGN_CENTER, 0, 0, true);
93+
sLcd->Update();
8394
}

examples/window-app/silabs/src/WindowManager.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,6 @@
4141
#include <platform/silabs/wifi/WifiInterface.h>
4242
#endif
4343

44-
#ifdef DISPLAY_ENABLED
45-
#include <LcdPainter.h>
46-
#endif
47-
4844
#include <platform/silabs/platformAbstraction/SilabsPlatform.h>
4945

5046
#define LCD_ICON_TIMEOUT 1000
@@ -606,6 +602,11 @@ CHIP_ERROR WindowManager::Init()
606602
mActionLED.Init(APP_ACTION_LED);
607603
AppTask::GetAppTask().LinkAppLed(&mActionLED);
608604

605+
#ifdef DISPLAY_ENABLED
606+
// Binds SilabsLCD for LcdPainter::Paint; runs once after GetLCD().Init() in BaseInit().
607+
static LcdPainter sLcdRegistration(AppTask::GetAppTask().GetLCD());
608+
#endif
609+
609610
chip::DeviceLayer::PlatformMgr().UnlockChipStack();
610611

611612
return CHIP_NO_ERROR;
@@ -686,7 +687,7 @@ void WindowManager::UpdateLCD()
686687

687688
if (!tilt.IsNull() && !lift.IsNull())
688689
{
689-
LcdPainter::Paint(AppTask::GetAppTask().GetLCD(), type, lift.Value(), tilt.Value(), mIcon);
690+
LcdPainter::Paint(type, lift.Value(), tilt.Value(), mIcon);
690691
}
691692
}
692693
}

0 commit comments

Comments
 (0)