Skip to content

Commit ce466e4

Browse files
Updated LCD UI for text based updates
1 parent e7f323d commit ce466e4

3 files changed

Lines changed: 43 additions & 254 deletions

File tree

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

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

36-
class PixelPainter
37-
{
38-
public:
39-
PixelPainter(uint16_t lift, uint16_t tilt);
40-
virtual ~PixelPainter() = default;
41-
virtual uint8_t Color(uint32_t x, uint32_t y) = 0;
42-
43-
protected:
44-
uint16_t mLift;
45-
uint16_t mTilt;
46-
};
47-
48-
class CompositePainter : public PixelPainter
49-
{
50-
public:
51-
CompositePainter(uint16_t lift, uint16_t tilt, PixelPainter * painter1, PixelPainter * painter2, PixelPainter * painter3);
52-
uint8_t Color(uint32_t x, uint32_t y);
53-
54-
private:
55-
PixelPainter * mPainter1;
56-
PixelPainter * mPainter2;
57-
PixelPainter * mPainter3;
58-
};
59-
60-
class FramePainter : public PixelPainter
61-
{
62-
using PixelPainter::PixelPainter;
63-
uint8_t Color(uint32_t x, uint32_t y);
64-
};
65-
66-
class IconPainter : public PixelPainter
67-
{
68-
public:
69-
IconPainter(uint16_t lift, uint16_t tilt, LcdIcon icon);
70-
uint8_t Color(uint32_t x, uint32_t y);
71-
72-
private:
73-
uint8_t mIconSize;
74-
uint8_t mIconOffset;
75-
LcdIcon mIcon;
76-
};
77-
78-
class VerticalShadePainter : public PixelPainter
79-
{
80-
public:
81-
using PixelPainter::PixelPainter;
82-
uint8_t Color(uint32_t x, uint32_t y);
83-
};
84-
85-
class HorizontalShadePainter : public PixelPainter
86-
{
87-
public:
88-
using PixelPainter::PixelPainter;
89-
uint8_t Color(uint32_t x, uint32_t y);
90-
};
91-
92-
class VerticalBlindPainter : public PixelPainter
93-
{
94-
public:
95-
VerticalBlindPainter(uint16_t lift, uint16_t tilt);
96-
uint8_t Color(uint32_t x, uint32_t y);
97-
98-
private:
99-
constexpr static uint8_t sBandCount = 12;
100-
uint8_t mBandSize;
101-
};
102-
10336
class LcdPainter
10437
{
10538
public:
10639
static void Paint(SilabsLCD & lcd, chip::app::Clusters::WindowCovering::Type type, uint16_t lift, uint16_t tilt, LcdIcon icon);
107-
10840
private:
109-
static PixelPainter * GetCoverPainter(chip::app::Clusters::WindowCovering::Type type, uint16_t lift, uint16_t tilt);
110-
};
41+
static void ClearScreen(SilabsLCD & lcd);
42+
};

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

Lines changed: 39 additions & 182 deletions
Original file line numberDiff line numberDiff line change
@@ -18,209 +18,66 @@
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+
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ void WindowManager::Cover::Init(chip::EndpointId endpoint)
286286
ModeSet(endpoint, mode);
287287

288288
// Attribute: Id 27 SafetyStatus (Optional)
289-
chip::BitFlags<SafetyStatus> safetyStatus(0x00); // 0 is no issues;
289+
chip::BitFlags<SafetyStatus> safetyStatus(0x00); // 0 is no issues;
290290
}
291291

292292
void WindowManager::Cover::ScheduleControlAction(ControlAction action, bool setNewTarget)
@@ -676,7 +676,7 @@ void WindowManager::UpdateLCD()
676676
Cover & cover = GetCover();
677677
chip::app::DataModel::Nullable<uint16_t> lift;
678678
chip::app::DataModel::Nullable<uint16_t> tilt;
679-
679+
680680
chip::DeviceLayer::PlatformMgr().LockChipStack();
681681
Type type = TypeGet(cover.mEndpoint);
682682

0 commit comments

Comments
 (0)