//** TEST_LilyGo_T5 **/
#define version "2.0"
//décommenter une des (ou les deux) lignes suivantes pour afficher des tests d'affichages
//#define IMAGE_BMP
//#define GROS_CARACT_1
#include <stdint.h>
#include <GxEPD.h>
#include "SD.h"
#include "SPI.h"
//! There are three versions of the 2.13 screen,
// if you are not sure which version, please test each one,
// if it is successful then it belongs to the model of the file name
//#include <GxGDE0213B1/GxGDE0213B1.h> // 2.13" b/w
//#include <GxGDEH0213B72/GxGDEH0213B72.h> // 2.13" b/w new panel
#include <GxGDEH0213B73/GxGDEH0213B73.h> // 2.13" b/w newer panel
/**
REMARQUE :
La page html de conversion "image2cpp" est ici : https://javl.github.io/image2cpp/
Elle fonctionne également en local
*/
#include "bmp/bmp_Skippy.c"
#include "chiffres/60_75/chiffres60_75.c"
// 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>
#define SPI_MOSI 23
#define SPI_MISO -1
#define SPI_CLK 18
#define ELINK_SS 5
#define ELINK_BUSY 4
#define ELINK_RESET 16
#define ELINK_DC 17
#define SDCARD_SS 13
#define SDCARD_CLK 14
#define SDCARD_MOSI 15
#define SDCARD_MISO 2
#define BUTTON_PIN 39
uint8_t B=4; // bouton
const uint32_t partial_update_period_s = 1;
const uint32_t full_update_period_s = 6 * 60 * 60;
uint32_t start_time;
uint32_t next_time;
uint32_t previous_time;
uint32_t previous_full_update;
uint32_t total_seconds = 0;
uint32_t seconds, minutes, hours;
GxIO_Class io(SPI, /*CS=5*/ ELINK_SS, /*DC=*/ ELINK_DC, /*RST=*/ ELINK_RESET);
GxEPD_Class display(io, /*RST=*/ ELINK_RESET, /*BUSY=*/ ELINK_BUSY);
SPIClass sdSPI(VSPI);
const char *skuNum = "SKU:H239";
bool sdOK = false;
int startX = 40, startY = 10;
void setup()
{
pinMode(BUTTON_PIN, INPUT);
Serial.begin(115200);
Serial.println();
Serial.println("setup");
SPI.begin(SPI_CLK, SPI_MISO, SPI_MOSI, ELINK_SS);
if (sdOK)
{
uint32_t cardSize = SD.cardSize() / (1024 * 1024);
display.println("SDCard:" + String(cardSize) + " MB");
} else { display.println("SDCard None"); }
start_time = next_time = previous_time = previous_full_update = millis();
display.init();
display.setRotation(1);
display.fillScreen(GxEPD_WHITE);
display.setTextColor(GxEPD_BLACK);
display.setFont(&FreeMonoBold12pt7b);
display.setCursor(0, 0);
sdSPI.begin(SDCARD_CLK, SDCARD_MISO, SDCARD_MOSI, SDCARD_SS);
if (!SD.begin(SDCARD_SS, sdSPI)) { sdOK = false; } else { sdOK = true; }
esp_sleep_enable_ext0_wakeup((gpio_num_t)BUTTON_PIN, LOW);
display.fillScreen(GxEPD_WHITE);
// display.eraseDisplay();
display.update();
// void drawBitmap(const uint8_t *bitmap, uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t color, int16_t mode = bm_normal);
#if defined(IMAGE_BMP)
display.drawBitmap(bmp_Skippy_bits, 0, 0, bmp_Skippy_W, bmp_Skippy_H, GxEPD_BLACK);
display.setTextColor(GxEPD_BLACK);
display.setFont(&FreeMonoBold9pt7b);
display.setCursor(display.width() - display.width() / 2, display.height() -100);
display.println("Skippy");
display.setCursor(display.width() / 2 -30, display.height() -10);
display.setFont(&FreeMonoBold24pt7b);
display.setCursor(display.width() - display.width() / 2 -30, display.height() -60);
display.println("18:45");
display.update();
delay(4000);
display.fillScreen(GxEPD_WHITE);
display.update();
#endif
#if defined(GROS_CARACT_1)
display.setFont(&FreeMonoBold24pt7b);
display.setTextSize(2);
display.setCursor(0, 90);
display.println("18");
display.setCursor(120, 90);
display.println("45");
display.setCursor(100, 70);
display.setTextSize(1);
display.println(":");
display.update();
delay(1000);
#endif
uint16_t x0=0;
uint16_t y0=20;
uint16_t w0=60;
uint16_t h0=75;
display.fillScreen(GxEPD_WHITE);
display.setFont(&FreeMonoBold12pt7b);
display.setTextSize(1);
}
void print_big_chiffre(uint8_t nb, uint16_t x0 ,uint16_t y0)
{
uint16_t w0=60;
uint16_t h0=75;
switch (nb)
{
case 0: {display.drawBitmap(chiffre0, x0, y0, w0, h0, GxEPD_BLACK); } break;
case 1: {display.drawBitmap(chiffre1, x0, y0, w0, h0, GxEPD_BLACK); } break;
case 2: {display.drawBitmap(chiffre2, x0, y0, w0, h0, GxEPD_BLACK); } break;
case 3: {display.drawBitmap(chiffre3, x0, y0, w0, h0, GxEPD_BLACK); } break;
case 4: {display.drawBitmap(chiffre4, x0, y0, w0, h0, GxEPD_BLACK); } break;
case 5: {display.drawBitmap(chiffre5, x0, y0, w0, h0, GxEPD_BLACK); } break;
case 6: {display.drawBitmap(chiffre6, x0, y0, w0, h0, GxEPD_BLACK); } break;
case 7: {display.drawBitmap(chiffre7, x0, y0, w0, h0, GxEPD_BLACK); } break;
case 8: {display.drawBitmap(chiffre8, x0, y0, w0, h0, GxEPD_BLACK); } break;
case 9: {display.drawBitmap(chiffre9, x0, y0, w0, h0, GxEPD_BLACK); } break;
}
}
void Update_box()
{
uint16_t box_x = 0;
uint16_t box_y = 20;
uint16_t box_w = 245;
uint16_t box_h = 80;
uint16_t cursor_y = box_y;
display.fillRect(box_x, box_y, box_w, box_h, GxEPD_WHITE);
display.setCursor(box_x, cursor_y);
uint8_t x0= box_x;
/*
uint8_t heures_unites;
uint8_t heures_dizaines;
heures_unites = hours %10;
heures_dizaines = hours /10;
print_big_chiffre(heures_dizaines, x0, cursor_y);
print_big_chiffre(heures_unites, x0+60, cursor_y);
x0+=120;
*/
uint8_t minutes_unites;
uint8_t minutes_dizaines;
minutes_unites = minutes %10;
minutes_dizaines = minutes /10;
print_big_chiffre(minutes_dizaines, x0, cursor_y);
print_big_chiffre(minutes_unites, x0+60, cursor_y);
display.setCursor(113, 65);
display.setTextSize(2);
display.println(":");
x0+=130;
uint8_t secondes_unites;
uint8_t secondes_dizaines;
secondes_unites = seconds %10;
secondes_dizaines = seconds /10;
print_big_chiffre(secondes_dizaines, x0, cursor_y);
print_big_chiffre(secondes_unites, x0+60, cursor_y);
if (B==0)
{
display.setFont(&FreeMonoBold9pt7b);
display.setTextSize(1);
display.setCursor(box_x, box_y);
display.println("sleeping");
}
display.updateWindow(box_x, box_y, box_w, box_h, true);
}
void loop()
{
B = digitalRead(BUTTON_PIN);
uint32_t actual = millis();
while (actual < next_time)
{
// the "BlinkWithoutDelay" method works also for overflowed millis
if ((actual - previous_time) > (partial_update_period_s * 1000))
{
//Serial.print(actual - previous_time); Serial.print(" > "); Serial.println(partial_update_period_s * 1000);
break;
}
delay(100);
actual = millis();
}
//Serial.print("actual: "); Serial.print(actual); Serial.print(" previous: "); Serial.println(previous_time);
if ((actual - previous_full_update) > full_update_period_s * 1000)
{
display.update();
previous_full_update = actual;
}
previous_time = actual;
next_time += uint32_t(partial_update_period_s * 1000);
total_seconds += partial_update_period_s;
seconds = total_seconds % 60;
minutes = (total_seconds / 60) % 60;
hours = (total_seconds / 3600) % 24;
Update_box();
if (B == 0)
{
// goto sleep
display.update();
delay(1000);
esp_deep_sleep_start();
while(1) {;}
}
}