Skip to content

Commit 0e2a0ae

Browse files
committed
add ImageIcon, docs, and example
1 parent 654d773 commit 0e2a0ae

File tree

6 files changed

+151
-3
lines changed

6 files changed

+151
-3
lines changed

src/Screens/ImageScreen.h

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#pragma once
2+
3+
#include "Adafruit_GFX.h"
4+
#include "Screen.h"
5+
6+
class ImageScreen : public Screen {
7+
protected:
8+
const uint8_t *bitmap;
9+
const uint8_t width, height;
10+
const char *label;
11+
const GFXfont *font;
12+
13+
public:
14+
ImageScreen(const uint8_t b[], const uint8_t w, const uint8_t h, const char *l,
15+
const GFXfont *f, uint16_t bg = GxEPD_WHITE)
16+
: Screen(bg), bitmap(b), width(w), height(h), label(l), font(f) {}
17+
void show() override {
18+
const uint16_t fgColor =
19+
(bgColor == GxEPD_WHITE ? GxEPD_BLACK : GxEPD_WHITE);
20+
Watchy::display.setFont(font);
21+
int16_t x1, y1;
22+
uint16_t w, h;
23+
Watchy::display.getTextBounds(label, 0, 0, &x1, &y1, &w, &h);
24+
Watchy::display.fillScreen(bgColor);
25+
// even space between top<->icon<->label<->bottom
26+
int space = (DISPLAY_HEIGHT - (height + h)) / 3;
27+
Watchy::display.drawBitmap((DISPLAY_WIDTH - width) / 2, space, bitmap, width, height, fgColor);
28+
// want y1+h to be space above DISPLAY_HEIGHT
29+
Watchy::display.setCursor((DISPLAY_WIDTH - w) / 2, (DISPLAY_HEIGHT - space - (y1 + h)));
30+
Watchy::display.print(label);
31+
}
32+
};

src/Screens/icons.cpp

+78-1
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,81 @@ const uint8_t bitmap_wifi[] = {
124124
75, 22, 74, 22, 75, 20, 77, 18, 79, 16, 81, 14, 83, 12, 85, 10,
125125
87, 8, 89, 6, 91, 4, 93, 2, 255, 0, 255, 0, 255, 0, 255, 0,
126126
255, 0, 255, 0, 149};
127-
const rle rle_wifi = {96, 96, bitmap_wifi};
127+
const rle rle_wifi = {96, 96, bitmap_wifi};
128+
129+
// 'cloud', 96x96px
130+
// this is why we compress bitmaps, it's here just to demo ImageScreen
131+
const uint8_t cloud [] = {
132+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
133+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
134+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
135+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
136+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
137+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
138+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
139+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
140+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
141+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
142+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
143+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
144+
0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
145+
0x01, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xf0,
146+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00,
147+
0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
148+
0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xff, 0xff, 0xff, 0xff,
149+
0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x00,
150+
0x00, 0x00, 0x00, 0x1f, 0xff, 0xe0, 0x07, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f,
151+
0xff, 0x80, 0x01, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0xfc, 0x00, 0x00, 0x3f,
152+
0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xf0, 0x00, 0x00, 0x0f, 0xff, 0x00, 0x00, 0x00,
153+
0x00, 0x00, 0x00, 0xff, 0xe0, 0x00, 0x00, 0x07, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xff,
154+
0xc0, 0x00, 0x00, 0x03, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x03, 0xff, 0x00, 0x00, 0x00, 0x00,
155+
0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x03, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xc0, 0x00, 0x00,
156+
0x00, 0x00, 0x1f, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x7f, 0xe0, 0x00, 0x00, 0x00, 0x00, 0xff, 0xfc,
157+
0x00, 0x00, 0x00, 0x00, 0x3f, 0xe0, 0x00, 0x00, 0x00, 0x07, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x00,
158+
0x1f, 0xf0, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xf0, 0x00, 0x00,
159+
0x00, 0x3f, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xf0, 0x00, 0x00, 0x00, 0x7f, 0xff, 0xf0,
160+
0x00, 0x00, 0x00, 0x00, 0x0f, 0xf0, 0x00, 0x00, 0x00, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00,
161+
0x0f, 0xf8, 0x00, 0x00, 0x01, 0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x07, 0xfc, 0x00, 0x00,
162+
0x03, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xff, 0x80, 0x00, 0x07, 0xff, 0xc0, 0x00,
163+
0x00, 0x00, 0x00, 0x00, 0x03, 0xff, 0xe0, 0x00, 0x0f, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
164+
0x03, 0xff, 0xfc, 0x00, 0x0f, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xff, 0xfe, 0x00,
165+
0x1f, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0x00, 0x3f, 0xf0, 0x00, 0x00,
166+
0x00, 0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0xc0, 0x3f, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
167+
0x03, 0xff, 0xff, 0xe0, 0x3f, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xff, 0xff, 0xf0,
168+
0x7f, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xf0, 0xff, 0xc0, 0x00, 0x00,
169+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0xf8, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
170+
0x00, 0x00, 0x1f, 0xfc, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xfc,
171+
0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xfc, 0xff, 0x00, 0x00, 0x00,
172+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xfe, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
173+
0x00, 0x00, 0x03, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xff,
174+
0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00,
175+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
176+
0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff,
177+
0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x80, 0x00, 0x00,
178+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x7f, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
179+
0x00, 0x00, 0x00, 0xff, 0x7f, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff,
180+
0x3f, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xff, 0x3f, 0xe0, 0x00, 0x00,
181+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xff, 0x3f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
182+
0x00, 0x00, 0x03, 0xfe, 0x1f, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xfc,
183+
0x0f, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xfc, 0x0f, 0xfe, 0x00, 0x00,
184+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xfc, 0x07, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00,
185+
0x00, 0x00, 0x7f, 0xf8, 0x03, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xf0,
186+
0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0xff, 0xff, 0xff,
187+
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
188+
0xff, 0xff, 0xff, 0xc0, 0x00, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80,
189+
0x00, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x07, 0xff, 0xff,
190+
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
191+
0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00,
192+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
193+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
194+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
195+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
196+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
197+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
198+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
199+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
200+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
201+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
202+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
203+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
204+
};

src/Screens/icons.h

+1
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ extern const rle rle_orientation;
77
extern const rle rle_settings;
88
extern const rle rle_steps;
99
extern const rle rle_wifi;
10+
extern const uint8_t cloud[];

src/Screens/main.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "OptimaLTStd22pt7b.h"
44
#include "GetWeatherScreen.h"
55
#include "IconScreen.h"
6+
#include "ImageScreen.h"
67
#include "MenuScreen.h"
78
#include "SetLocationScreen.h"
89
#include "SetTimeScreen.h"
@@ -38,21 +39,22 @@ MenuItem menuItems[] = {{"Set Time", &setTimeScreen},
3839
MenuScreen menu(menuItems, sizeof(menuItems) / sizeof(menuItems[0]));
3940

4041
TimeScreen timeScreen;
41-
WeatherScreen weather;
42+
WeatherScreen weatherScreen;
4243
IconScreen battery(&rle_battery, "battery", OptimaLTStd22pt7b);
4344
IconScreen steps(&rle_steps, "steps", OptimaLTStd22pt7b);
4445
IconScreen orientation(&rle_orientation, "orientation", OptimaLTStd22pt7b);
4546
IconScreen bluetooth(&rle_bluetooth, "bluetooth", OptimaLTStd22pt7b);
4647
IconScreen wifi(&rle_wifi, "wifi", OptimaLTStd22pt7b);
4748
IconScreen settings(&rle_settings, "settings", OptimaLTStd22pt7b);
49+
ImageScreen weather(cloud, 96, 96, "weather", OptimaLTStd22pt7b);
4850
ShowBatteryScreen showBattery;
4951
ShowBluetoothScreen showBluetooth;
5052
ShowOrientationScreen showOrientation;
5153
ShowStepsScreen showSteps;
5254
ShowWifiScreen showWifi;
5355

5456
CarouselItem carouselItems[] = {{&timeScreen, nullptr},
55-
{&weather, nullptr},
57+
{&weather, &weatherScreen},
5658
{&battery, &showBattery},
5759
{&steps, &showSteps},
5860
{&orientation, &showOrientation},

src/Screens/rle.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
#include "Adafruit_GFX.h"
44
#include "GxEPD2.h"
55

6+
// this implements a simple RLE encoding. It expects an Adafruit GFX drawable,
7+
// the position to draw the image at, a pointer to a rle struct, and the color
8+
// of the image.
9+
610
// does no sanity checking, length of bitmap, size of gfx
711
void drawRLEBitmap(Adafruit_GFX &gfx, int16_t x, int16_t y, const rle *r,
812
uint16_t color) {

src/Screens/rle.h

+32
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,38 @@
22

33
#include "Adafruit_GFX.h"
44

5+
// represents a simple rle encoded image. w and h are the width and height of
6+
// the image (max 255 x 255) and bitmap represents runs of bits. The first
7+
// uint8_t is a count of transparent bits, then a count of non-transparent
8+
// bits, then transparent, and so on. The bits are recorded as one long stream
9+
// of bits concatenated together in row order.
10+
11+
// a 10 x 10 image of a square:
12+
//
13+
// . . . . . . . . . .
14+
// . . . . . . . . . .
15+
// . . X X X X X X . .
16+
// . . X X X X X X . .
17+
// . . X X X X X X . .
18+
// . . X X X X X X . .
19+
// . . X X X X X X . .
20+
// . . X X X X X X . .
21+
// . . X X X X X X . .
22+
// . . X X X X X X . .
23+
// . . . . . . . . . .
24+
// . . . . . . . . . .
25+
//
26+
// turns into
27+
//
28+
// ......................XXXXXX....XXXXXX....XXXXXX....XXXXXX....XXXXXX....XXXXXX....XXXXXX....XXXXXX......................
29+
//
30+
// and would be represented as { 10, 10, &{22,6,4,6,4,6,4,6,4,6,4,6,4,6,4,6,22} }
31+
32+
// this is only useful if most of the runs are longer than 8 bits - so simple
33+
// solid figures compress best
34+
35+
// there's a PNG to RLE converter in go at https://github.com/charles-haynes/png2rle
36+
537
typedef struct {
638
const uint8_t w, h;
739
const uint8_t *bitmap;

0 commit comments

Comments
 (0)