1919
2020#include " demo-ui-bitmaps.h"
2121#include < LcdPainter.h>
22-
22+ # include < AppConfig.h >
2323#include < cstdint>
2424#include < cstdio>
2525
2626using namespace chip ::app::Clusters::WindowCovering;
2727
28+ SilabsLCD * LcdPainter::sLcd = nullptr ;
29+ bool LcdPainter::mLcdCleared = false ;
30+
2831namespace {
2932static const uint8_t sSilabsLogoSmall [] = { SILABS_LOGO_SMALL };
3033static 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-
3535static 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}
0 commit comments