Skip to content

Commit b1c263a

Browse files
author
lewis he
committed
Update TBlock eink example
1 parent 7a8b7e4 commit b1c263a

File tree

1 file changed

+55
-82
lines changed

1 file changed

+55
-82
lines changed

examples/T-Block/Epaper_BL/Epaper_BL.ino

Lines changed: 55 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -7,43 +7,38 @@
77
// This code is only suitable for T-Block
88
99
cd ~/Arduino/libraries
10-
git clone https://github.com/ZinggJM/GxEPD2.git
10+
git clone https://github.com/ZinggJM/GxEPD.git
1111
git clone https://github.com/olikraus/U8g2_for_Adafruit_GFX.git
12-
git clone https://github.com/adafruit/Adafruit-GFX-Library.git
1312
13+
1.cd ~/Arduino/libraries/U8g2_for_Adafruit_GFX/src/
14+
2.Edit GxFont_GFX.h
15+
3.Uncomment #include <U8g2_for_Adafruit_GFX.h> to use U8G2 font
1416
15-
// Delete the Fonts folder because it conflicts with TWatch
16-
rm -rf ./Adafruit-GFX-Library/Fonts
17-
18-
* * */
17+
*/
1918

2019

2120
#include "config.h"
2221

2322
extern const unsigned char logoIcon[280];
2423

25-
/******************************************************************
26-
* GXEPD2
27-
* ***************************************************************/
28-
// base class GxEPD2_GFX can be used to pass references or pointers to the display instance as parameter, uses ~1.2k more code
29-
// enable or disable GxEPD2_GFX base class
30-
#define ENABLE_GxEPD2_GFX 0
24+
#include <GxEPD.h>
25+
#include <GxGDEH0154D67/GxGDEH0154D67.h> // 1.54" b/w
26+
#include <GxIO/GxIO_SPI/GxIO_SPI.h>
27+
#include <GxIO/GxIO.h>
3128

32-
#include <GxEPD2_BW.h>
33-
#include <GxEPD2_3C.h>
34-
#include <U8g2_for_Adafruit_GFX.h>
3529

3630
#define INK_BUSY 34
3731
#define INK_RESET 27
3832
#define INK_DC 19
3933
#define INK_SS 5
4034
#define INK_MOSI 23
41-
#define INK_MISO 19 //eink no use
35+
#define INK_MISO 26 //eink no use
4236
#define INK_CLK 18
4337

4438
#define DEFAULT_BRIGHTNESS 45
4539

46-
GxEPD2_BW<GxEPD2_154_D67, GxEPD2_154_D67::HEIGHT> display(GxEPD2_154_D67(INK_SS, INK_DC, INK_RESET, INK_BUSY)); // GDEH0154D67
40+
GxIO_Class io(SPI, INK_SS, INK_DC, INK_RESET);
41+
GxEPD_Class display(io, INK_RESET, INK_BUSY);
4742

4843
U8G2_FOR_ADAFRUIT_GFX u8g2Fonts;
4944
TTGOClass *twatch = nullptr;
@@ -86,20 +81,14 @@ void mainPage(bool fullScreen)
8681
static int16_t getX, getY;
8782
static uint16_t getW, getH;
8883
char buff[64] = "00:00";
89-
bool reverse = false;
9084
const char *weekChars[] = { "", "", "", "", "", "", ""};
9185

9286
if (lastSeupCount != seupCount) {
9387
lastSeupCount = seupCount;
9488
u8g2Fonts.setFont(u8g2_font_wqy16_t_gb2312a); // select u8g2 font from here: https://github.com/olikraus/u8g2/wiki/fntlistall
95-
display.setPartialWindow(getX - getW, getY - getH + 1, getW + 1, getH + 1);
96-
display.firstPage();
97-
do {
98-
snprintf(buff, sizeof(buff), "%u 步", seupCount);
99-
u8g2Fonts.setCursor(getX - getW, getY);
100-
u8g2Fonts.print(buff);
101-
102-
} while (display.nextPage());
89+
snprintf(buff, sizeof(buff), "%u 步", seupCount);
90+
u8g2Fonts.setCursor(getX - getW, getY);
91+
u8g2Fonts.print(buff);
10392
}
10493

10594
RTC_Date d = rtc->getDateTime();
@@ -120,77 +109,62 @@ void mainPage(bool fullScreen)
120109
if (fullScreen) {
121110
lastX = 25;
122111
lastY = 100;
123-
display.setFullWindow();
124-
display.firstPage();
125-
do {
126-
display.drawBitmap(5, 5, logoIcon, 75, 28, GxEPD_BLACK);
112+
display.drawBitmap(5, 5, logoIcon, 75, 28, GxEPD_BLACK);
127113

128-
//BATTERY ICON
129-
u8g2Fonts.setFont(u8g2_font_battery19_tn);
130-
u8g2Fonts.setCursor(175, 20); // start writing at this position
131-
u8g2Fonts.setFontDirection(3); // left to right (this is default)
132-
u8g2Fonts.print(4);
133-
u8g2Fonts.setFontDirection(0); // left to right (this is default)
114+
//BATTERY ICON
115+
u8g2Fonts.setFont(u8g2_font_battery19_tn);
116+
u8g2Fonts.setCursor(175, 20); // start writing at this position
117+
u8g2Fonts.setFontDirection(3); // left to right (this is default)
118+
u8g2Fonts.print(4);
119+
u8g2Fonts.setFontDirection(0); // left to right (this is default)
134120

135121

136-
display.drawFastHLine(10, 40, display.width() - 20, GxEPD_BLACK);
137-
display.drawFastHLine(10, 150, display.width() - 20, GxEPD_BLACK);
122+
display.drawFastHLine(10, 40, display.width() - 20, GxEPD_BLACK);
123+
display.drawFastHLine(10, 150, display.width() - 20, GxEPD_BLACK);
138124

139-
u8g2Fonts.setFont(u8g2_font_inr38_mn ); // select u8g2 font from here: https://github.com/olikraus/u8g2/wiki/fntlistall
125+
u8g2Fonts.setFont(u8g2_font_inr38_mn ); // select u8g2 font from here: https://github.com/olikraus/u8g2/wiki/fntlistall
140126

141-
u8g2Fonts.setCursor(lastX, lastY); // start writing at this position
142-
u8g2Fonts.print(buff);
127+
u8g2Fonts.setCursor(lastX, lastY); // start writing at this position
128+
u8g2Fonts.print(buff);
143129

144-
/* calculate the size of the box into which the text will fit */
145-
lastH = u8g2Fonts.getFontAscent() - u8g2Fonts.getFontDescent();
146-
lastW = u8g2Fonts.getUTF8Width(buff);
130+
/* calculate the size of the box into which the text will fit */
131+
lastH = u8g2Fonts.getFontAscent() - u8g2Fonts.getFontDescent();
132+
lastW = u8g2Fonts.getUTF8Width(buff);
147133

148-
u8g2Fonts.setFont(u8g2_font_wqy16_t_gb2312a); // select u8g2 font from here: https://github.com/olikraus/u8g2/wiki/fntlistall
134+
u8g2Fonts.setFont(u8g2_font_wqy16_t_gb2312a); // select u8g2 font from here: https://github.com/olikraus/u8g2/wiki/fntlistall
149135

150-
snprintf(buff, sizeof(buff), "星期%s", weekChars[lastWeek]);
136+
snprintf(buff, sizeof(buff), "星期%s", weekChars[lastWeek]);
151137

152-
tbh = u8g2Fonts.getFontAscent() - u8g2Fonts.getFontDescent();
153-
tbw = u8g2Fonts.getUTF8Width(buff);
138+
tbh = u8g2Fonts.getFontAscent() - u8g2Fonts.getFontDescent();
139+
tbw = u8g2Fonts.getUTF8Width(buff);
154140

155-
int16_t x, y;
156-
x = ((display.width() - tbw) / 2) ;
157-
y = ((display.height() - tbh) / 2) + 40 ;
141+
int16_t x, y;
142+
x = ((display.width() - tbw) / 2) ;
143+
y = ((display.height() - tbh) / 2) + 40 ;
158144

159-
u8g2Fonts.setCursor(x, y);
160-
u8g2Fonts.print(buff);
161-
u8g2Fonts.setCursor(20, y + 50);
145+
u8g2Fonts.setCursor(x, y);
146+
u8g2Fonts.print(buff);
147+
u8g2Fonts.setCursor(20, y + 50);
162148

163-
u8g2Fonts.print("你今天已经走了:");
164-
u8g2Fonts.print("1000步");
149+
u8g2Fonts.print("你今天已经走了:");
150+
u8g2Fonts.print("1000步");
165151

166-
getX = u8g2Fonts.getCursorX();
167-
getY = u8g2Fonts.getCursorY();
168-
getH = u8g2Fonts.getFontAscent() - u8g2Fonts.getFontDescent();
169-
getW = u8g2Fonts.getUTF8Width("1000步");
152+
getX = u8g2Fonts.getCursorX();
153+
getY = u8g2Fonts.getCursorY();
154+
getH = u8g2Fonts.getFontAscent() - u8g2Fonts.getFontDescent();
155+
getW = u8g2Fonts.getUTF8Width("1000步");
156+
display.update();
170157

171-
} while (display.nextPage());
172158

173159
} else {
174160
u8g2Fonts.setFont(u8g2_font_inr38_mn); // select u8g2 font from here: https://github.com/olikraus/u8g2/wiki/fntlistall
175-
display.setPartialWindow(lastX, lastY - u8g2Fonts.getFontAscent() - 3, lastW, lastH);
176-
display.firstPage();
177-
do {
178-
179-
if (reverse) {
180-
display.fillScreen(GxEPD_BLACK);
181-
display.setTextColor(GxEPD_WHITE);
182-
183-
} else {
184-
display.fillScreen(GxEPD_WHITE);
185-
display.setTextColor(GxEPD_BLACK);
186-
}
187-
188-
189-
lastW = u8g2Fonts.getUTF8Width(buff);
190-
191-
u8g2Fonts.setCursor(lastX, lastY);
192-
u8g2Fonts.print(buff);
193-
} while (display.nextPage());
161+
display.fillRect(lastX, lastY - u8g2Fonts.getFontAscent() - 3, lastW, lastH, GxEPD_WHITE);
162+
display.fillScreen(GxEPD_WHITE);
163+
display.setTextColor(GxEPD_BLACK);
164+
lastW = u8g2Fonts.getUTF8Width(buff);
165+
u8g2Fonts.setCursor(lastX, lastY);
166+
u8g2Fonts.print(buff);
167+
display.updateWindow(lastX, lastY - u8g2Fonts.getFontAscent() - 3, lastW, lastH, false);
194168
}
195169
}
196170

@@ -234,8 +208,6 @@ void setup()
234208

235209
btn->setPressedHandler([]() {
236210

237-
display.powerOff();
238-
239211
delay(2000);
240212

241213
esp_sleep_enable_ext1_wakeup(GPIO_SEL_36, ESP_EXT1_WAKEUP_ALL_LOW);
@@ -252,6 +224,7 @@ void setup()
252224
// Initialize the interface
253225
mainPage(true);
254226

227+
255228
// Reduce CPU frequency
256229
setCpuFrequencyMhz(40);
257230

0 commit comments

Comments
 (0)