LilyGo-LoRa-Series/lib/GxEPD/examples/GxEPD_Example/GxEPD_Example.ino
2024-01-16 15:42:50 +08:00

287 lines
8.4 KiB
C++

/*
LilyGo Ink Screen Series Test
- Created by Lewis he
*/
// According to the board, cancel the corresponding macro definition
// #define LILYGO_T5_V213
// #define LILYGO_T5_V22
// #define LILYGO_T5_V24
// #define LILYGO_T5_V28
// #define LILYGO_T5_V102
// #define LILYGO_T5_V266
// #define LILYGO_EPD_DISPLAY_102 //Depend https://github.com/adafruit/Adafruit_NeoPixel
// #define LILYGO_EPD_DISPLAY_154
#include <boards.h>
#include <GxEPD.h>
#include <SD.h>
#include <FS.h>
#if defined(LILYGO_T5_V102) || defined(LILYGO_EPD_DISPLAY_102)
#include <GxGDGDEW0102T4/GxGDGDEW0102T4.h> //1.02" b/w
#include <Adafruit_NeoPixel.h> //Depend https://github.com/adafruit/Adafruit_NeoPixel
#elif defined(LILYGO_T5_V266)
#include <GxDEPG0266BN/GxDEPG0266BN.h> // 2.66" b/w form DKE GROUP
#elif defined(LILYGO_T5_V213)
#include <GxDEPG0213BN/GxDEPG0213BN.h> // 2.13" b/w form DKE GROUP
#else
// #include <GxDEPG0097BW/GxDEPG0097BW.h> // 0.97" b/w form DKE GROUP
// #include <GxGDGDEW0102T4/GxGDGDEW0102T4.h> //1.02" b/w
// #include <GxGDEW0154Z04/GxGDEW0154Z04.h> // 1.54" b/w/r 200x200
// #include <GxGDEW0154Z17/GxGDEW0154Z17.h> // 1.54" b/w/r 152x152
// #include <GxGDEH0154D67/GxGDEH0154D67.h> // 1.54" b/w
// #include <GxDEPG0150BN/GxDEPG0150BN.h> // 1.51" b/w form DKE GROUP
// #include <GxDEPG0266BN/GxDEPG0266BN.h> // 2.66" b/w form DKE GROUP
// #include <GxDEPG0290R/GxDEPG0290R.h> // 2.9" b/w/r form DKE GROUP
// #include <GxDEPG0290B/GxDEPG0290B.h> // 2.9" b/w form DKE GROUP
// #include <GxGDEW029Z10/GxGDEW029Z10.h> // 2.9" b/w/r form GoodDisplay
// #include <GxGDEW0213Z16/GxGDEW0213Z16.h> // 2.13" b/w/r form GoodDisplay
// #include <GxGDE0213B1/GxGDE0213B1.h> // 2.13" b/w old panel , form GoodDisplay
// #include <GxGDEH0213B72/GxGDEH0213B72.h> // 2.13" b/w old panel , form GoodDisplay
// #include <GxGDEH0213B73/GxGDEH0213B73.h> // 2.13" b/w old panel , form GoodDisplay
// #include <GxGDEM0213B74/GxGDEM0213B74.h> // 2.13" b/w form GoodDisplay 4-color
// #include <GxGDEW0213M21/GxGDEW0213M21.h> // 2.13" b/w Ultra wide temperature , form GoodDisplay
// #include <GxDEPG0213BN/GxDEPG0213BN.h> // 2.13" b/w form DKE GROUP
// #include <GxGDEW027W3/GxGDEW027W3.h> // 2.7" b/w form GoodDisplay
// #include <GxGDEW027C44/GxGDEW027C44.h> // 2.7" b/w/r form GoodDisplay
// #include <GxGDEH029A1/GxGDEH029A1.h> // 2.9" b/w form GoodDisplay
// #include <GxDEPG0750BN/GxDEPG0750BN.h> // 7.5" b/w form DKE GROUP
#endif
#include GxEPD_BitmapExamples
// FreeFonts from Adafruit_GFX
#include <Fonts/FreeMonoBold9pt7b.h>
#include <Fonts/FreeMonoBold12pt7b.h>
#include <Fonts/FreeMonoBold18pt7b.h>
#include <Fonts/FreeMonoBold24pt7b.h>
#include <GxIO/GxIO_SPI/GxIO_SPI.h>
#include <GxIO/GxIO.h>
#include <WiFi.h>
#define USING_SOFT_SPI
#if defined(USING_SOFT_SPI)
GxIO_Class io(EPD_SCLK, EPD_MISO, EPD_MOSI, EPD_CS, EPD_DC, EPD_RSET);
#else
GxIO_Class io(SPI, EPD_CS, EPD_DC, EPD_RSET);
#endif
GxEPD_Class display(io, EPD_RSET, EPD_BUSY);
#if defined(_HAS_SDCARD_) && !defined(_USE_SHARED_SPI_BUS_)
SPIClass SDSPI(HSPI);
#endif
#if defined(_GxGDEW0213Z16_H_) || defined(_GxGDEW029Z10_H_) || defined(_GxGDEW027C44_H_) ||defined(_GxGDEW0154Z17_H_) || defined(_GxGDEW0154Z04_H_) || defined(_GxDEPG0290R_H_)
#define _HAS_COLOR_
#endif
#if defined(LILYGO_EPD_DISPLAY_102)
Adafruit_NeoPixel strip(RGB_STRIP_COUNT, RGB_STRIP_PIN, NEO_GRBW + NEO_KHZ800);
#endif /*LILYGO_EPD_DISPLAY_102*/
void showFont(const char name[], const GFXfont *f);
void drawCornerTest(void);
bool setupSDCard(void)
{
#if defined(_HAS_SDCARD_) && !defined(_USE_SHARED_SPI_BUS_)
pinMode(SDCARD_MISO, INPUT_PULLUP);
SDSPI.begin(SDCARD_SCLK, SDCARD_MISO, SDCARD_MOSI);
return SD.begin(SDCARD_CS, SDSPI);
#elif defined(_HAS_SDCARD_)
return SD.begin(SDCARD_CS);
#endif
return false;
}
void testSpeaker()
{
#if defined(_HAS_SPEAKER_)
#ifdef _HAS_PWR_CTRL_
pinMode(SPK_POWER_EN, OUTPUT);
digitalWrite(SPK_POWER_EN, HIGH);
#endif
ledcSetup(LEDC_CHANNEL_0, 1000, 8);
ledcAttachPin(SPERKER_PIN, LEDC_CHANNEL_0);
int i = 3;
while (i--) {
ledcWriteTone(LEDC_CHANNEL_0, 1000);
delay(200);
ledcWriteTone(LEDC_CHANNEL_0, 0);
}
#ifdef _HAS_PWR_CTRL_
pinMode(SPK_POWER_EN, INPUT);
#endif
ledcDetachPin(SPERKER_PIN);
#endif
}
void testWiFi()
{
WiFi.mode(WIFI_STA);
WiFi.disconnect();
// WiFi.scanNetworks will return the number of networks found
int n = WiFi.scanNetworks();
Serial.println("scan done");
if (n == 0) {
Serial.println("no networks found");
} else {
Serial.print(n);
Serial.println(" networks found");
for (int i = 0; i < n; ++i) {
// Print SSID and RSSI for each network found
Serial.print(i + 1);
Serial.print(": ");
Serial.print(WiFi.SSID(i));
Serial.print(" (");
Serial.print(WiFi.RSSI(i));
Serial.print(")");
Serial.println((WiFi.encryptionType(i) == WIFI_AUTH_OPEN) ? " " : "*");
delay(10);
}
}
Serial.println("");
}
void setup()
{
bool rlst = false;
Serial.begin(115200);
Serial.println();
Serial.println("setup");
#if defined(LILYGO_EPD_DISPLAY_102)
pinMode(EPD_POWER_ENABLE, OUTPUT);
digitalWrite(EPD_POWER_ENABLE, HIGH);
delay(50);
// strip test
strip.begin();
strip.show();
strip.setBrightness(200);
int i = 0;
while (i < 5) {
uint32_t color[] = {0xFF0000, 0x00FF00, 0x0000FF, 0x000000};
strip.setPixelColor(0, color[i]);
strip.show();
delay(1000);
i++;
}
strip.setPixelColor(0, 0);
strip.show();
#endif /*LILYGO_EPD_DISPLAY_102*/
#if !defined(USING_SOFT_SPI)
SPI.begin(EPD_SCLK, EPD_MISO, EPD_MOSI);
#endif
display.init();
display.setTextColor(GxEPD_BLACK);
testSpeaker();
testWiFi();
rlst = setupSDCard();
display.setRotation(0);
display.fillScreen(GxEPD_WHITE);
#if defined(_HAS_COLOR_)
display.drawExampleBitmap(BitmapExample1, 0, 0, GxEPD_WIDTH, GxEPD_HEIGHT, GxEPD_RED);
#else
display.drawExampleBitmap(BitmapExample1, 0, 0, GxEPD_WIDTH, GxEPD_HEIGHT, GxEPD_BLACK);
#endif
#if defined(_HAS_SDCARD_)
display.setRotation(1);
#if defined(LILYGO_T5_V102)
display.setCursor(5, display.height() - 15);
#else
display.setCursor(20, display.height() - 15);
#endif
String sizeString = "SD:" + String(SD.cardSize() / 1024.0 / 1024.0 / 1024.0) + "G";
display.println(rlst ? sizeString : "SD:N/A");
int16_t x1, x2;
uint16_t w, h;
String str = GxEPD_BitmapExamplesQ;
str = str.substring(2, str.lastIndexOf("/"));
display.getTextBounds(str, 0, 0, &x1, &x2, &w, &h);
display.setCursor(display.width() - w - 5, display.height() - 15);
display.println(str);
#endif
display.update();
delay(1000);
}
void loop()
{
drawCornerTest();
int i = 0;
while (i < 4) {
display.setRotation(i);
showFont("FreeMonoBold9pt7b", &FreeMonoBold9pt7b);
//showFont("FreeMonoBold18pt7b", &FreeMonoBold18pt7b);
//showFont("FreeMonoBold24pt7b", &FreeMonoBold24pt7b);
i++;
}
display.fillScreen(GxEPD_WHITE);
display.update();
display.powerDown();
esp_sleep_enable_ext1_wakeup(((uint64_t)(((uint64_t)1) << BUTTON_1)), ESP_EXT1_WAKEUP_ALL_LOW);
esp_deep_sleep_start();
}
void showFont(const char name[], const GFXfont *f)
{
display.fillScreen(GxEPD_WHITE);
display.setTextColor(GxEPD_BLACK);
display.setFont(f);
display.setCursor(0, 0);
display.println();
display.println(name);
display.println(" !\"#$%&'()*+,-./");
display.println("0123456789:;<=>?");
display.println("@ABCDEFGHIJKLMNO");
display.println("PQRSTUVWXYZ[\\]^_");
display.println("`abcdefghijklmno");
display.println("pqrstuvwxyz{|}~ ");
display.update();
delay(5000);
}
void drawCornerTest()
{
display.drawCornerTest();
delay(5000);
uint8_t rotation = display.getRotation();
for (uint16_t r = 0; r < 4; r++) {
display.setRotation(r);
display.fillScreen(GxEPD_WHITE);
display.fillRect(0, 0, 8, 8, GxEPD_BLACK);
display.fillRect(display.width() - 18, 0, 16, 16, GxEPD_BLACK);
display.fillRect(display.width() - 25, display.height() - 25, 24, 24, GxEPD_BLACK);
display.fillRect(0, display.height() - 33, 32, 32, GxEPD_BLACK);
display.update();
delay(5000);
}
display.setRotation(rotation); // restore
}