Update epaper example

This commit is contained in:
lewishe
2023-06-01 17:30:24 +08:00
parent a0442c813b
commit 3f2a7a5e8b
2 changed files with 27 additions and 36 deletions

View File

@@ -1,6 +1,6 @@
/*
* Based on the test code written by GxEPD2 / U8g2_for_Adafruit_GFX
* https://github.com/ZinggJM/GxEPD2
* Based on the test code written by GxEPD / U8g2_for_Adafruit_GFX
* https://github.com/ZinggJM/GxEPD
* https://github.com/olikraus/U8g2_for_Adafruit_GFX
*
*/
@@ -12,6 +12,7 @@ extern const unsigned char logoIcon[280];
U8G2_FOR_ADAFRUIT_GFX u8g2Fonts;
TTGOClass *twatch = nullptr;
GxEPD_Class *ePaper = nullptr;
PCF8563_Class *rtc = nullptr;
AXP20X_Class *power = nullptr;
Button2 *btn = nullptr;
@@ -24,7 +25,7 @@ int16_t x, y;
void setupDisplay()
{
u8g2Fonts.begin(twatch->display); // connect u8g2 procedures to Adafruit GFX
u8g2Fonts.begin(*ePaper); // connect u8g2 procedures to Adafruit GFX
u8g2Fonts.setFontMode(1); // use u8g2 transparent mode (this is default)
u8g2Fonts.setFontDirection(0); // left to right (this is default)
u8g2Fonts.setForegroundColor(GxEPD_BLACK); // apply Adafruit GFX color
@@ -72,12 +73,7 @@ void mainPage(bool fullScreen)
if (fullScreen) {
lastX = 25;
lastY = 100;
twatch->display.setFullWindow();
twatch->display.fillScreen(GxEPD_WHITE);
twatch->display.drawBitmap(5, 5, logoIcon, 75, 28, GxEPD_BLACK);
ePaper->drawBitmap(5, 5, logoIcon, 75, 28, GxEPD_BLACK);
//BATTERY ICON
u8g2Fonts.setFont(u8g2_font_battery19_tn);
@@ -86,10 +82,12 @@ void mainPage(bool fullScreen)
u8g2Fonts.print(4);
u8g2Fonts.setFontDirection(0); // left to right (this is default)
twatch->display.drawFastHLine(10, 40, twatch->display.width() - 20, GxEPD_BLACK);
twatch->display.drawFastHLine(10, 150, twatch->display.width() - 20, GxEPD_BLACK);
ePaper->drawFastHLine(10, 40, ePaper->width() - 20, GxEPD_BLACK);
ePaper->drawFastHLine(10, 150, ePaper->width() - 20, GxEPD_BLACK);
u8g2Fonts.setFont(u8g2_font_inr38_mn ); // select u8g2 font from here: https://github.com/olikraus/u8g2/wiki/fntlistall
u8g2Fonts.setCursor(lastX, lastY); // start writing at this position
u8g2Fonts.print(buff);
@@ -105,8 +103,8 @@ void mainPage(bool fullScreen)
tbw = u8g2Fonts.getUTF8Width(buff);
int16_t x, y;
x = ((twatch->display.width() - tbw) / 2) ;
y = ((twatch->display.height() - tbh) / 2) + 40 ;
x = ((ePaper->width() - tbw) / 2) ;
y = ((ePaper->height() - tbh) / 2) + 40 ;
u8g2Fonts.setCursor(x, y);
u8g2Fonts.print(buff);
@@ -119,24 +117,18 @@ void mainPage(bool fullScreen)
getY = u8g2Fonts.getCursorY();
getH = u8g2Fonts.getFontAscent() - u8g2Fonts.getFontDescent();
getW = u8g2Fonts.getUTF8Width("1000步");
twatch->display.nextPage();
ePaper->update();
} else {
u8g2Fonts.setFont(u8g2_font_inr38_mn); // select u8g2 font from here: https://github.com/olikraus/u8g2/wiki/fntlistall
twatch->display.setPartialWindow(lastX, lastY - u8g2Fonts.getFontAscent() - 3, lastW, lastH);
twatch->display.firstPage();
do {
twatch->display.fillRect(lastX, lastY - u8g2Fonts.getFontAscent() - 3, lastW, lastH, GxEPD_WHITE);
twatch->display.fillScreen(GxEPD_WHITE);
twatch->display.setTextColor(GxEPD_BLACK);
lastW = u8g2Fonts.getUTF8Width(buff);
u8g2Fonts.setCursor(lastX, lastY);
u8g2Fonts.print(buff);
} while (twatch->display.nextPage());
ePaper->fillRect(lastX, lastY - u8g2Fonts.getFontAscent() - 3, lastW, lastH, GxEPD_WHITE);
ePaper->fillScreen(GxEPD_WHITE);
ePaper->setTextColor(GxEPD_BLACK);
lastW = u8g2Fonts.getUTF8Width(buff);
u8g2Fonts.setCursor(lastX, lastY);
u8g2Fonts.print(buff);
ePaper->updateWindow(lastX, lastY - u8g2Fonts.getFontAscent() - 3, lastW, lastH, false);
}
}
@@ -157,6 +149,7 @@ void setup()
btn = twatch->button;
ePaper = twatch->ePaper;
// Use compile time as RTC input time
rtc->check();
@@ -182,11 +175,10 @@ void setup()
touch_vaild = !touch_vaild;
if (touch_vaild) {
twatch->display.clearScreen();
twatch->display.refresh(false);
ePaper->fillScreen( GxEPD_WHITE);
ePaper->update();
} else {
twatch->display.clearScreen();
twatch->display.refresh(false);
ePaper->fillScreen( GxEPD_WHITE);
mainPage(true);
}
});
@@ -229,8 +221,8 @@ void loop()
btn->loop();
if (twatch->getTouch(x, y)) {
Serial.printf("X:%d Y:%d\n", x, y);
twatch->display.fillCircle(x, y, 5, GxEPD_BLACK);
twatch->display.display();
ePaper->fillCircle(x, y, 5, GxEPD_BLACK);
ePaper->update();
}
}

View File

@@ -1,6 +1,6 @@
// => Hardware select
#define LILYGO_WATCH_BLOCK // To use T-Watch Block , please uncomment this line
// #define LILYGO_WATCH_BLOCK_V1 // To use T-Watch Block V1 , please uncomment this line
// #define LILYGO_WATCH_BLOCK // To use T-Watch Block , please uncomment this line
#define LILYGO_WATCH_BLOCK_V1 // To use T-Watch Block V1 , please uncomment this line
//NOT SUPPORT ...
// #define LILYGO_WATCH_2020_V1
@@ -10,7 +10,6 @@
// => Function select
#define LILYGO_EINK_GDEH0154D67_TP //It is electronic paper with backlight
#include <LilyGoWatch.h>