/***************************************************************************************
 * Project  :
 * Experimental Platform :ESP32S3 + 7.3inch E-Paper Display
 * Hardware Connection :ESP32S3-> 7.3inch E-Paper
 /* Pin wiring definion
 *      3.3V --> VCC  
 *      GND  --> GND
 *      IO21 --> CS
 *      IO12 --> CLK
 *      IO11 --> MOSI
 *      IO3  --> DC
 *      IO46  --> RST
 *      IO9  --> BUSY
 * Author      : Andy Li
 * Web Site    :www.seengreat.com
***************************************************************************************/

/******************************
 * Definition of screen coordinates:
 * 0------------> x (1~800) 
 * |
 * |
 * |
 * |
 * y (1~480)
******************************/

#include "epd_gui.h"
#include "epd_7inch3.h"
#include "Arduino.h"
#include "image.h"

unsigned char BlackImage[192000];//800*480/2=192000

void setup() {
  Serial.begin(115200);
  Serial.print("EPD init\r\n ");
  E_Paper_Gpio_Init();
  log_d("Total heap:%d",ESP.getHeapSize());
  log_d("Free heap:%d",ESP.getFreeHeap());
  log_d("Total PSRAM:%d",ESP.getPsramSize());
  log_d("Free PSRAM:%d",ESP.getFreePsram());
}
//Tips//
/*
1.When the e-paper is refreshed in full screen, the picture flicker is a normal phenomenon, and the main function is to clear the display afterimage in the previous picture.
2.After the e-paper is refreshed, you need to put it into sleep mode, please do not delete the sleep command.
3.Please do not take out the electronic paper when power is on.
4.Wake up from sleep, need to re-initialize the e-paper.
5.When you need to transplant the driver, you only need to change the corresponding IO. The BUSY pin is the input mode and the others are the output mode.
*/
void loop() {

    EPD_Init(); //Electronic paper initialization
    Serial.print("EPD Clear\r\n ");
    EPD_Clear(EPD_7IN3F_WHITE); //Refresh the picture in full screen need 25s+30s
    delay(200);
    Serial.print("Show pic0\r\n ");
    EPD_7IN3F_Display(gImage_7in3_0);//need 25s+30s
    delay(2000);
    delay(2000);
    Serial.print("Show pic1\r\n ");
    EPD_7IN3F_Display(gImage_7in3_1);//need 25s+30s
    delay(2000);
    delay(2000);

    Image_Init(BlackImage, EPD_7IN3F_WIDTH, EPD_7IN3F_HEIGHT, 0, EPD_7IN3F_WHITE);//Create Image
    printf("Image_init successful\r\n");
    Gui_SetScale(6);//Set to 6-colour mode
    // Drawing on the image
    // 1.Select Image
    printf("SelectImage:BlackImage\r\n");
    Gui_SelectImage(BlackImage);
    printf("Gui_SelectImage successful\r\n");
    Gui_Clear(EPD_7IN3F_WHITE);
    printf("Gui_Clear\r\n");
    // 2.Drawing on the image
    printf("Drawing:BlackImage\r\n");
    Gui_Draw_Point(10, 80, EPD_7IN3F_RED, PIXEL_1X1, DOT_STYLE_DFT);
    Gui_Draw_Point(10, 110, EPD_7IN3F_BLUE, PIXEL_2X2, DOT_STYLE_DFT);
    Gui_Draw_Point(10, 140, EPD_7IN3F_GREEN, PIXEL_3X3, DOT_STYLE_DFT);
    Gui_Draw_Point(10, 170, EPD_7IN3F_YELLOW, PIXEL_4X4, DOT_STYLE_DFT);
    Gui_Draw_Point(10, 200, EPD_7IN3F_BLACK, PIXEL_5X5, DOT_STYLE_DFT);
    Gui_Draw_Point(10, 230, EPD_7IN3F_RED, PIXEL_6X6, DOT_STYLE_DFT);
    Gui_Draw_Point(10, 260, EPD_7IN3F_BLUE, PIXEL_7X7, DOT_STYLE_DFT);
    Gui_Draw_Point(10, 290, EPD_7IN3F_GREEN, PIXEL_8X8, DOT_STYLE_DFT);
    
    Gui_Draw_Line(40, 170, 90, 220, EPD_7IN3F_YELLOW, PIXEL_1X1, SOLID);
    Gui_Draw_Line(90, 170, 40, 220, EPD_7IN3F_RED, PIXEL_1X1, SOLID);
    
    Gui_Draw_Rectangle(40, 170, 90, 220, EPD_7IN3F_BLACK, EMPTY, PIXEL_3X3);
    Gui_Draw_Rectangle(40, 250, 90, 300, EPD_7IN3F_BLACK, FULL, PIXEL_1X1);
    Gui_Draw_Circle(45, 95, 20, EPD_7IN3F_BLACK, EMPTY, PIXEL_1X1);
    Gui_Draw_Circle(105, 95, 20, EPD_7IN3F_RED, FULL, PIXEL_1X1);
    
    Gui_Draw_Num(200, 150, 123456789, &Font8, EPD_7IN3F_WHITE, EPD_7IN3F_BLACK);
    Gui_Draw_Num(200, 180, 987654321, &Font12,EPD_7IN3F_BLACK, EPD_7IN3F_WHITE );
    Gui_Draw_Num(200, 210, 123456789, &Font16, EPD_7IN3F_WHITE, EPD_7IN3F_BLACK);
    Gui_Draw_Num(200, 240, 987654321, &Font20,EPD_7IN3F_BLACK, EPD_7IN3F_WHITE );
    Gui_Draw_Str_EN(200, 0, "Seengerat", &Font16, EPD_7IN3F_WHITE, EPD_7IN3F_BLACK);
    Gui_Draw_Str_EN(220, 20, "Seengerat" ,&Font16, EPD_7IN3F_WHITE,EPD_7IN3F_GREEN);
    Gui_Draw_Str_EN(240, 40, "Seengerat", &Font16, EPD_7IN3F_WHITE, EPD_7IN3F_BLUE);
    Gui_Draw_Str_EN(260, 60, "Seengerat", &Font16, EPD_7IN3F_WHITE, EPD_7IN3F_RED);
    Gui_Draw_Str_EN(280, 80, "Seengerat", &Font16, EPD_7IN3F_WHITE, EPD_7IN3F_YELLOW);
    Gui_Draw_Str_EN(300, 100, "SEENGREAT", &Font16, EPD_7IN3F_WHITE, EPD_7IN3F_GREEN);
    Gui_Draw_Str_EN(400, 0, "Welcome to EPD", &Font20, EPD_7IN3F_WHITE, EPD_7IN3F_BLACK);
    Gui_Draw_Str_EN(415, 30, "Welcome to EPD", &Font20, EPD_7IN3F_GREEN, EPD_7IN3F_BLACK);
    Gui_Draw_Str_EN(430, 60, "Welcome to EPD", &Font20, EPD_7IN3F_BLUE, EPD_7IN3F_BLACK);
    Gui_Draw_Str_EN(445, 90, "Welcome to EPD", &Font24, EPD_7IN3F_RED, EPD_7IN3F_BLACK);
    Gui_Draw_Str_EN(460, 120, "Welcome to EPD", &Font24, EPD_7IN3F_YELLOW, EPD_7IN3F_BLACK);
    Gui_Draw_Str_EN(475, 150, "Welcome to EPD", &Font24, EPD_7IN3F_GREEN, EPD_7IN3F_BLACK);
    Gui_Draw_Str_EN(490, 180, "Welcome to EPD", &Font24, EPD_7IN3F_BLACK, EPD_7IN3F_WHITE);
    printf("EPD_Display\r\n");
    EPD_7IN3F_Display(BlackImage);
    delay(2000);
    delay(2000);
    Serial.print("EPD Clear\r\n ");
    EPD_Clear(EPD_7IN3F_WHITE); //Refresh the picture in full screen need 25s+30s
    EPD_DeepSleep();  //Sleep
    while(1); 
}


//////////////////////////////////END//////////////////////////////////////////////////
