1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
|
#include "badge/display.h"
#include "badge/log.h"
#include <Fonts/FreeMono9pt7b.h>
#include <Fonts/FreeSansBold12pt7b.h>
// #include <GxEPD2_3C.h>
#include <GxEPD2_BW.h>
#include "badge/config.h"
#include "badge/util.h"
#if UVOK_EPAP_DISPLAY == DISPLAY_WAVESHARE_219_YBW
// HINT: Update the library code, set budy timeout to 30 or 60 seconds!
// Small color
GxEPD2_3C<GxEPD2_213_Z19c, GxEPD2_213_Z19c::HEIGHT> display(GxEPD2_213_Z19c(22, 21, 17, 16));
#elif UVOK_EPAP_DISPLAY == DISPLAY_WAVESHARE_290_BW
// larger b/w
// or T5
// GxEPD2_BW<GxEPD2_290_T5D, GxEPD2_290_T5D::HEIGHT> display(GxEPD2_290_T5D(22, 21, 17, 16));
GxEPD2_BW<GxEPD2_290_M06, GxEPD2_290_M06::HEIGHT> display(GxEPD2_290_M06(22, 21, 17, 16));
#elif UVOK_EPAP_DISPLAY == DISPLAY_ELECROW_290_BW
/*
#define SCK 12
#define MOSI 11
#define RES 47
#define DC 46
#define CS 45
#define BUSY 48
*/
GxEPD2_BW<GxEPD2_290_T94, GxEPD2_290_T94::HEIGHT> display(GxEPD2_290_T94(45, 46, 47, 48));
#else
#error "define display"
#endif
static uint8_t displayed = 0;
#include "cheebox.xbm"
#include "chleepy.xbm"
#include "hug.xbm"
#include "hungry.xbm"
#include "qr.xbm"
#include "uvok.xbm"
// #include "sneppump.xbm"
#include "snep2.xbm"
// #include "snep3.xbm"
static bool is_initial = true;
static constexpr uint8_t rotation = 3;
void de::uvok::badge::display_init(void)
{
LOG_F("Init display...\n");
#if UVOK_EPAP_DISPLAY == DISPLAY_ELECROW_290_BW
// Turn on once, let controller handle the rest, lest I want to do re-init...
pinMode(7, OUTPUT); // Set pin 7 as output mode
digitalWrite(7, HIGH); // Set pin 7 to high level to turn on the screen power
display.init(115200, true);
#else
display.init(115200, true, 2, false); // USE THIS for Waveshare boards with "clever" reset circuit, 2ms reset pulse
#endif
display.hibernate();
LOG_F("Display done.\n");
}
#define IMAGE_DATA(name, text) {name##_bits, name##_width, name##_height, text}
const struct
{
// I always thought making the struct const makes all membery const, yet I still get warnings...
const char *bits;
const int width;
const int height;
const char *text;
} imgs[] = {
#include "./images.cfg"
};
const int de::uvok::badge::image_count = (ARRAY_LENGTH(imgs));
typedef enum
{
DISPLAY_PREVIEW,
DISPLAY_FULL
} display_mode_t;
static void displayDo(display_mode_t mode)
{
if (is_initial)
{
mode = DISPLAY_FULL;
is_initial = false;
}
LOG_F("Print image %d in full mode? %d\n", displayed, mode);
display.setRotation(rotation);
display.setTextColor(GxEPD_BLACK);
display.setFont(&FreeSansBold12pt7b);
const char *display_text = imgs[displayed].text;
int16_t tbx, tby;
uint16_t tbw, tbh;
display.getTextBounds(display_text, 0, 0, &tbx, &tby, &tbw, &tbh);
constexpr int TEXT_BORDER = 10;
const uint16_t x = display.width() - tbw - TEXT_BORDER - tbx;
const uint16_t y = ((display.height() - tbh) / 2) - tby;
// re-calculate right-centered
display.getTextBounds(display_text, x, y, &tbx, &tby, &tbw, &tbh);
display.firstPage();
do
{
if (mode == DISPLAY_FULL)
{
display.setFullWindow();
display.drawXBitmap(0, 0, (unsigned char *)imgs[displayed].bits, imgs[displayed].width,
imgs[displayed].height, GxEPD_BLACK);
}
else
{
display.setPartialWindow(tbx - TEXT_BORDER, tby - TEXT_BORDER, tbw + 2 * TEXT_BORDER,
tbh + 2 * TEXT_BORDER);
}
display.fillRect(tbx - TEXT_BORDER, tby - TEXT_BORDER, tbw + 2 * TEXT_BORDER, tbh + 2 * TEXT_BORDER,
GxEPD_WHITE);
display.setCursor(x, y);
display.print(display_text);
} while (display.nextPage());
display.hibernate();
}
uint8_t de::uvok::badge::display_prev(void)
{
displayed--;
if (displayed >= image_count)
displayed = image_count - 1;
displayDo(DISPLAY_PREVIEW);
return displayed;
}
uint8_t de::uvok::badge::display_next(void)
{
displayed = (displayed + 1) % image_count;
displayDo(DISPLAY_PREVIEW);
return displayed;
}
uint8_t de::uvok::badge::display_refresh(void)
{
displayDo(DISPLAY_FULL);
return displayed;
}
void de::uvok::badge::display_direct(uint8_t num)
{
LOG_F("Display direct\n");
if (num >= image_count)
return;
displayed = num;
displayDo(DISPLAY_FULL);
}
void de::uvok::badge::display_indicator(DisplayIndicator indicator)
{
LOG_F("Set indicator to %d\n", indicator);
// no idea what do about initial state..
display.setRotation(rotation);
display.setTextColor(GxEPD_BLACK);
display.setFont(&FreeMono9pt7b);
const char *display_text = "";
switch (indicator)
{
case DisplayIndicator::Advertising:
display_text = "Adv";
break;
case DisplayIndicator::Connected:
display_text = "Conn";
break;
}
int16_t tbx, tby;
uint16_t tbw, tbh;
constexpr int TEXT_BORDER_X = 3;
constexpr int TEXT_POS_Y = 15;
// For Y, cursor means the "bottom" line?
display.getTextBounds(display_text, TEXT_BORDER_X, TEXT_POS_Y, &tbx, &tby, &tbw, &tbh);
LOG_F("GTB for %s@%d,%d returned %d, %d, %d, %d\n", display_text, (int16_t)TEXT_BORDER_X, (int16_t)TEXT_POS_Y, tbx,
tby, tbw, tbh);
// Determined by debugging
constexpr uint16_t max_width = 50;
constexpr uint16_t max_height = 18;
// right-align stuff
const uint16_t rect_x = display.width() - max_width;
display.firstPage();
do
{
if (is_initial)
{
display.setFullWindow();
display.clearScreen();
// display.drawXBitmap(0, 0, (unsigned char *)imgs[displayed].bits, imgs[displayed].width,
// imgs[displayed].height, GxEPD_BLACK);
}
else
{
display.setPartialWindow(rect_x, 0, max_width, max_height);
}
display.fillRect(rect_x, 0, max_width, max_height, GxEPD_WHITE);
display.setCursor(TEXT_BORDER_X + rect_x, TEXT_POS_Y);
display.print(display_text);
} while (display.nextPage());
display.hibernate();
}
/*
// ->
#include "output_h4x4a.xbm"
#include "output_o8x8.xbm"
*/
|