-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdigameDisplay.h
207 lines (173 loc) · 6.21 KB
/
digameDisplay.h
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
/* Functions for using the Adafruit 1.54" Monochrome eInk Display.
*
* See: https://www.adafruit.com/product/4196
*
* I'm using an ESP32 WROOM DevKit V4.0 as my microcontroller.
*
*/
#ifndef __DIGAME_DISPLAY_H__
#define __DIGAME_DISPLAY_H__
// base class GxEPD2_GFX can be used to pass references or pointers to the display instance as parameter, uses ~1.2k more code
// enable or disable GxEPD2_GFX base class
#define ENABLE_GxEPD2_GFX 0
/* Here we are making use of Jean-Marc Zingg's nifty GxEPD2 library.
* https://github.com/ZinggJM/GxEPD2
* His header files, used for display selection are included for reference.
*/
#include <GxEPD2_BW.h>
// Our pinouts to the Adafruit display. Your values may differ!
#define EPD_DC 5 // can be any pin, but required!
#define EPD_CS 26 // can be any pin, but required!
#define EPD_BUSY 2 // can set to -1 to not use a pin (will wait a fixed delay)
#define SRAM_CS 27 // can set to -1 to not use a pin (uses a lot of RAM!)
#define SD_CS 14 // SD card chip select (The Adafruit 1.54" dispay includes an SD card breakout.)
#define EPD_RESET 0 // can set to -1 and share with chip Reset (can't deep sleep)
/* You could edit the GxEPD2_display_selection.h header to pick the display you want and then include it, but I just
* grabbed the constructor we need from GxEPD2_display_selection and copied here.
*/
//#include "GxEPD2_display_selection.h"
GxEPD2_BW<GxEPD2_154, GxEPD2_154::HEIGHT> display(GxEPD2_154(/*C=5*/ EPD_CS, /*DC=*/ EPD_DC, /*RST=*/ EPD_RESET, /*BUSY=*/ EPD_BUSY)); // GDEH0154D67
void initDisplay();
void displaySplash();
void displayInitializing();
void displayCount(double c);
void showValue(double v);
//******************************************************************************************
void initDisplay()
{
display.setRotation(0);
//display.setFont(&FreeMonoBold9pt7b);
display.setTextColor(GxEPD_BLACK);
int16_t tbx, tby; uint16_t tbw, tbh;
display.getTextBounds("Initializing...", 0, 0, &tbx, &tby, &tbw, &tbh);
// center bounding box by transposition of origin:
uint16_t x = ((display.width() - tbw) / 2) - tbx;
uint16_t y = ((display.height() - tbh) / 2) - tby;
display.setFullWindow();
display.firstPage();
do
{
display.fillScreen(GxEPD_WHITE);
display.setCursor(x, y);
display.print("Initializing...");
}
while (display.nextPage());
//Serial.println("helloWorld done");
return;
}
//******************************************************************************************
#if defined(ESP8266) || defined(ESP32)
#include <StreamString.h>
#define PrintString StreamString
#else
class PrintString : public Print, public String
{
public:
size_t write(uint8_t data) override
{
return concat(char(data));
};
};
#endif
//******************************************************************************************
// Print a string on the display, centered, at a particular y value.
void centerPrint(String s, uint16_t y){
int16_t tx, ty;
uint16_t tw, th;
display.getTextBounds(s, 0, 0, &tx, &ty, &tw, &th);
uint16_t utx = ((display.width() - tw) / 2) - tx;
uint16_t uty = y; //((display.height() - th) / 2) - ty;
display.setCursor(utx, uty);
display.print(s);
}
void displayCopyright(){
display.setTextSize(1);
centerPrint("Copyright 2021, Digame Systems.", 180);
centerPrint("All rights reserved.", 190);
}
//******************************************************************************************
void displaySplashScreen(){
display.fillScreen(GxEPD_WHITE);
display.setTextColor(GxEPD_BLACK);
display.setTextSize(3);
centerPrint("eInk Test", 10);
display.setTextSize(2);
centerPrint("Adafruit 1.54\"", 60);
centerPrint("Mono Display", 80);
centerPrint("200x200 pix", 100);
centerPrint("Partial", 120);
centerPrint("Update", 140);
display.setTextSize(1);
displayCopyright();
display.display();
display.fillScreen(GxEPD_WHITE);
}
//******************************************************************************************
void displayInitializingScreen(){
display.setTextColor(GxEPD_BLACK);
display.setTextSize(3);
centerPrint("INITIALIZE", 10);
display.setTextSize(2);
centerPrint("...", 60);
centerPrint("Configuring", 80);
centerPrint("System", 100);
centerPrint("Components", 120);
centerPrint("...", 140);
displayCopyright();
display.display();
display.fillScreen(GxEPD_WHITE);
}
//******************************************************************************************
void displayStatusScreen(String s){
display.setTextColor(GxEPD_BLACK);
display.setTextSize(3);
centerPrint("STATUS", 10);
display.setTextSize(2);
display.setCursor(0, 60);
display.print(s);
display.setTextSize(1);
displayCopyright();
display.display();
display.fillScreen(GxEPD_WHITE);
}
//******************************************************************************************
void displayCountScreen(double v)
{
int digits = 0;
display.fillScreen(GxEPD_WHITE);
display.setTextColor(GxEPD_BLACK);
PrintString valueString;
valueString.print(v, digits);
display.setTextSize(3);
centerPrint("COUNTS", 10);
displayCopyright();
display.display();
}
//******************************************************************************************
// Use the updatePartial function to show the value in the center of the screen without
// a big refresh. - Faster and no flicker!
void showValue(double v)
{
int digits = 0;
display.setTextSize(5);
display.setTextColor(GxEPD_BLACK);
PrintString valueString;
valueString.print(v, digits);
int16_t tbx, tby; uint16_t tbw, tbh;
display.getTextBounds(valueString, 0, 0, &tbx, &tby, &tbw, &tbh);
uint16_t x = ((display.width() - tbw) / 2) - tbx;
uint16_t y = ((display.height() - tbh) / 2) - tby; //+ tbh / 2; // y is base line!
// show what happens, if we use the bounding box for partial window
uint16_t wx = (display.width() - tbw) / 2;
uint16_t wy = (display.height()- tbh) / 2; // / 2;
display.setPartialWindow(wx, wy, tbw, tbh);
display.firstPage();
do
{
display.fillScreen(GxEPD_WHITE);
display.setCursor(x, y);
display.print(valueString);
}
while (display.nextPage());
}
#endif //__DIGAME_DISPLAY_H__