1818 */
1919
2020#include < LcdPainter.h>
21+ #include " demo-ui-bitmaps.h"
2122
22- using namespace chip ::app::Clusters::WindowCovering;
23-
24- constexpr uint32_t sTiltIcon [] = {
25- 0xffffffff , 0xffffffff , 0xc0000003 , 0xc0000003 , 0xc0000003 , 0xc0000003 , 0xc1ffffc3 , 0xc1ffffc3 ,
26- 0xc1ffffc3 , 0xc003c003 , 0xc003c003 , 0xc003c003 , 0xc003c003 , 0xc003c003 , 0xc003c003 , 0xc003c003 ,
27- 0xc003c003 , 0xc003c003 , 0xc003c003 , 0xc003c003 , 0xc003c003 , 0xc003c003 , 0xc003c003 , 0xc003c003 ,
28- 0xc003c003 , 0xc003c003 , 0xc0000003 , 0xc0000003 , 0xc0000003 , 0xc0000003 , 0xffffffff , 0xffffffff ,
29- };
30-
31- constexpr uint32_t sLiftIcon [] = {
32- 0xffffffff , 0xffffffff , 0xc0000003 , 0xc0000003 , 0xc0000003 , 0xc0000003 , 0xc0f00003 , 0xc0f00003 ,
33- 0xc0f00003 , 0xc0f00003 , 0xc0f00003 , 0xc0f00003 , 0xc0f00003 , 0xc0f00003 , 0xc0f00003 , 0xc0f00003 ,
34- 0xc0f00003 , 0xc0f00003 , 0xc0f00003 , 0xc0f00003 , 0xc0f00003 , 0xc0f00003 , 0xc0f00003 , 0xc0ffffc3 ,
35- 0xc0ffffc3 , 0xc0ffffc3 , 0xc0000003 , 0xc0000003 , 0xc0000003 , 0xc0000003 , 0xffffffff , 0xffffffff ,
36- };
23+ #include < cstdint>
24+ #include < cstdio>
3725
38- constexpr uint32_t sOneIcon [] = {
39- 0xffffffff , 0xffffffff , 0xc0000003 , 0xc0000003 , 0xc0000003 , 0xc00fe003 , 0xc01fe003 , 0xc03fe003 ,
40- 0xc07fe003 , 0xc0fbe003 , 0xc1f3e003 , 0xc3e3e003 , 0xc003e003 , 0xc003e003 , 0xc003e003 , 0xc003e003 ,
41- 0xc003e003 , 0xc003e003 , 0xc003e003 , 0xc003e003 , 0xc003e003 , 0xc003e003 , 0xc003e003 , 0xc3ffffc3 ,
42- 0xc3ffffc3 , 0xc3ffffc3 , 0xc3ffffc3 , 0xc0000003 , 0xc0000003 , 0xc0000003 , 0xffffffff , 0xffffffff ,
43- };
44-
45- constexpr uint32_t sTwoIcon [] = {
46- 0xffffffff , 0xffffffff , 0xc0000003 , 0xc0000003 , 0xc0000003 , 0xc07ffe03 , 0xc0ffff03 , 0xc1ffff83 ,
47- 0xc3ffffc3 , 0xc3f00fc3 , 0xc3e007c3 , 0xc3e007c3 , 0xc00007c3 , 0xc00007c3 , 0xc0000fc3 , 0xc00fff83 ,
48- 0xc03fff03 , 0xc07ffe03 , 0xc0fc0003 , 0xc1f80003 , 0xc1f00003 , 0xc3e00003 , 0xc3e00003 , 0xc3ffffc3 ,
49- 0xc3ffffc3 , 0xc3ffffc3 , 0xc3ffffc3 , 0xc0000003 , 0xc0000003 , 0xc0000003 , 0xffffffff , 0xffffffff ,
50- };
26+ using namespace chip ::app::Clusters::WindowCovering;
5127
52- PixelPainter::PixelPainter (uint16_t lift, uint16_t tilt) : mLift(lift), mTilt(tilt) {}
28+ namespace {
29+ static const uint8_t sSilabsLogoSmall [] = { SILABS_LOGO_SMALL };
30+ static const uint8_t sMatterLogo [] = { MATTER_LOGO_BITMAP };
5331
54- CompositePainter::CompositePainter (uint16_t lift, uint16_t tilt, PixelPainter * painter1, PixelPainter * painter2,
55- PixelPainter * painter3) :
56- PixelPainter(lift, tilt),
57- mPainter1(painter1), mPainter2(painter2), mPainter3(painter3)
58- {}
32+ // Shared with ClearScreen: first Paint draws logos, title, and Lift/Tilt labels; percent row updates every Paint.
33+ static bool sLcdCleared = false ;
5934
60- uint8_t CompositePainter::Color ( uint32_t x, uint32_t y )
35+ static unsigned RawToWholePercent ( uint16_t raw, int openLimit, int closedLimit )
6136{
62- int8_t pixel = -1 ;
63- if (mPainter1 )
64- {
65- pixel = mPainter1 ->Color (x, y);
66- if (pixel >= 0 )
67- {
68- return pixel;
69- }
70- }
71- if (mPainter2 )
72- {
73- pixel = mPainter2 ->Color (x, y);
74- if (pixel >= 0 )
75- {
76- return pixel;
77- }
78- }
79- if (mPainter3 )
37+ const int denom = closedLimit - openLimit;
38+ if (denom == 0 )
8039 {
81- pixel = mPainter3 ->Color (x, y);
82- if (pixel >= 0 )
83- {
84- return pixel;
85- }
86- }
87- return pixel;
88- }
89-
90- uint8_t FramePainter::Color (uint32_t x, uint32_t y)
91- {
92- if (x < LCD_FRAME_SIZE || x >= (LCD_SIZE - LCD_FRAME_SIZE) || y < LCD_FRAME_SIZE || y >= (LCD_SIZE - LCD_FRAME_SIZE))
93- {
94- if (x < LCD_MARGIN_SIZE || x >= (LCD_SIZE - LCD_MARGIN_SIZE) || y < LCD_MARGIN_SIZE || y >= (LCD_SIZE - LCD_MARGIN_SIZE))
95- {
96- return 0 ;
97- }
98- else
99- {
100- return (x < (LCD_MARGIN_SIZE + LCD_BORDER_SIZE)) || (x >= (LCD_SIZE - LCD_BORDER_SIZE - LCD_MARGIN_SIZE)) ||
101- (y < (LCD_MARGIN_SIZE + LCD_BORDER_SIZE)) || (y >= (LCD_SIZE - LCD_BORDER_SIZE - LCD_MARGIN_SIZE));
102- }
40+ return 0 ;
10341 }
104- return -1 ;
105- }
106-
107- IconPainter::IconPainter (uint16_t lift, uint16_t tilt, LcdIcon icon) : PixelPainter(lift, tilt), mIcon(icon)
108- {
109- mIconSize = sizeof (sTiltIcon ) / sizeof (uint32_t );
110- mIconOffset = (LCD_SIZE - mIconSize ) / 2 ;
42+ return static_cast <unsigned >((static_cast <int >(raw) - openLimit) * 100 / denom);
11143}
44+ } // namespace
11245
113- uint8_t IconPainter::Color ( uint32_t x, uint32_t y )
46+ void LcdPainter::ClearScreen (SilabsLCD & lcd )
11447{
115- const uint32_t * icon = nullptr ;
116- switch (mIcon )
48+ if (sLcdCleared )
11749 {
118- case LcdIcon::One:
119- icon = sOneIcon ;
120- break ;
121- case LcdIcon::Two:
122- icon = sTwoIcon ;
123- break ;
124- case LcdIcon::Lift:
125- icon = sLiftIcon ;
126- break ;
127- case LcdIcon::Tilt:
128- icon = sTiltIcon ;
129- break ;
130- default :
131- return -1 ;
50+ return ;
13251 }
133- if (x >= mIconOffset && x < (mIconOffset + mIconSize ) && y >= mIconOffset && y < (mIconOffset + mIconSize ))
134- {
135- uint32_t x0 = x - mIconOffset ;
136- uint32_t y0 = y - mIconOffset ;
137- return (icon[y0] & (1 << (31 - x0))) > 0 ;
138- }
139- return -1 ;
52+ lcd.Clear ();
53+ lcd.Update ();
54+ sLcdCleared = true ;
14055}
14156
142- uint8_t VerticalShadePainter::Color ( uint32_t x, uint32_t y )
57+ void LcdPainter::Paint (SilabsLCD & lcd, Type type, uint16_t lift, uint16_t tilt, LcdIcon icon )
14358{
144- return (y % 2 ) && y < (uint32_t ) (LCD_FRAME_SIZE + mLift );
145- }
59+ (void ) type;
14660
147- uint8_t HorizontalShadePainter::Color (uint32_t x, uint32_t y)
148- {
149- return (x % 2 ) && x < (uint32_t ) (LCD_FRAME_SIZE + mLift );
150- }
61+ const bool drawStaticChrome = !sLcdCleared ;
62+ ClearScreen (lcd);
15163
152- VerticalBlindPainter::VerticalBlindPainter (uint16_t lift, uint16_t tilt) : PixelPainter(lift, tilt)
153- {
154- mBandSize = (LCD_COVER_SIZE / sBandCount );
155- }
64+ const unsigned liftPct = RawToWholePercent (lift, LIFT_OPEN_LIMIT, LIFT_CLOSED_LIMIT);
65+ const unsigned tiltPct = RawToWholePercent (tilt, TILT_OPEN_LIMIT, TILT_CLOSED_LIMIT);
15666
157- uint8_t VerticalBlindPainter::Color (uint32_t x, uint32_t y)
158- {
159- if (x % 2 )
160- {
161- return 0 ;
162- }
163- else
164- {
165- uint32_t closedCount = (mLift + 1 ) / mBandSize ;
166- uint32_t bandCount = (y - LCD_FRAME_SIZE) / mBandSize ;
167- // ChipLogProgress(Zcl, "BLIND: ccount:%u, ccount:%u", clusterId);
168- if (bandCount <= closedCount)
169- {
170- return y <= (LCD_FRAME_SIZE + mBandSize * bandCount + mTilt );
171- }
172- else
173- {
174- return 0 ;
175- }
176- }
177- }
67+ GLIB_Context_t * glibContext = static_cast <GLIB_Context_t *>(lcd.Context ());
68+ const int32_t xSize = glibContext->pDisplayGeometry ->xSize ;
17869
179- PixelPainter * LcdPainter::GetCoverPainter (Type type, uint16_t lift, uint16_t tilt)
180- {
181- switch (type)
70+ char buf[32 ];
71+ if (drawStaticChrome)
18272 {
183- case Type::kRollerShade :
184- case Type::kRollerShade2Motor :
185- case Type::kRollerShadeExterior :
186- case Type::kRollerShadeExterior2Motor :
187- return new VerticalShadePainter (lift, tilt);
188- case Type::kDrapery :
189- case Type::kAwning :
190- return new HorizontalShadePainter (lift, tilt);
191- case Type::kShutter :
192- case Type::kTiltBlindTiltOnly :
193- case Type::kTiltBlindLiftAndTilt :
194- return new VerticalBlindPainter (lift, tilt);
195- case Type::kProjectorScreen :
196- case Type::kUnknown :
197- default :
198- return new VerticalShadePainter (lift, tilt);
199- }
200-
201- return nullptr ;
202- }
73+ 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 );
20376
204- void LcdPainter::Paint (SilabsLCD & lcd, Type type, uint16_t lift, uint16_t tilt, LcdIcon icon)
205- {
206- FramePainter framePaint = FramePainter (lift, tilt);
207- IconPainter iconPaint = IconPainter (lift, tilt, icon);
208- PixelPainter * coverPaint = GetCoverPainter (type, lift, tilt);
209- CompositePainter compositePaint = CompositePainter (lift, tilt, &framePaint, &iconPaint, coverPaint);
210- void * context = lcd.Context ();
211-
212- lcd.Clear ();
213-
214- for (int i = 0 ; i < LCD_SIZE; i++)
215- {
216- for (int j = 0 ; j < LCD_SIZE; j++)
217- {
218- if (compositePaint.Color (i, j))
219- {
220- lcd.DrawPixel (context, i, j);
221- }
222- }
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 );
22379 }
80+ snprintf (buf, sizeof (buf), " %3u%% %3u%%" , liftPct, tiltPct);
81+ (void ) GLIB_drawStringOnLine (glibContext, buf, 8 , GLIB_ALIGN_CENTER, 0 , 0 , true );
22482 lcd.Update ();
225- delete coverPaint;
226- }
83+ }
0 commit comments