From b65ad59e50fbeedc18a19a997454c294ca3ee1eb Mon Sep 17 00:00:00 2001 From: Yattien <36767821+Yattien@users.noreply.github.com> Date: Fri, 20 Jan 2023 09:34:09 +0100 Subject: [PATCH] updated waveshare code to latest (07.11.2022) --- CHANGELOG.md | 1 + ESPEInk_ESP8266.ino | 65 +++++++++--- README.md | 2 +- data/config.json | 1 + epd.h | 9 +- epd2in13.h | 146 +++++++++++++++++++++++--- epd2in7.h | 38 +++++++ epd3in52.h | 247 ++++++++++++++++++++++++++++++++++++++++++++ epd3in7.h | 7 +- epd7in5b_HD.h | 60 +++++++++++ scripts.h | 61 +++++++---- 11 files changed, 578 insertions(+), 59 deletions(-) create mode 100644 data/config.json create mode 100644 epd3in52.h create mode 100644 epd7in5b_HD.h diff --git a/CHANGELOG.md b/CHANGELOG.md index b0986e7..268d734 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Version 20 - Do not reset WiFi settings for MAX_CONNECTION_FAILURES, default is one try +- Updated waveshare code to 07.11.2022 (supports 2in13 v3, 2in13b v4, 3in52, 2in7 v2) ## Version v19 - Updated waveshare code to pre-version 19.07.2021 (supports 7in5 v2) diff --git a/ESPEInk_ESP8266.ino b/ESPEInk_ESP8266.ino index 3020d4d..9016d4f 100644 --- a/ESPEInk_ESP8266.ino +++ b/ESPEInk_ESP8266.ino @@ -35,7 +35,7 @@ WiFiClient espClient; PubSubClient mqttClient(espClient); // ----------------------------------------------------------------------------------------------------- -const int FW_VERSION = 19; // for OTA +const int FW_VERSION = 20; // for OTA // ----------------------------------------------------------------------------------------------------- const char *CONFIG_FILE = "/config.json"; const float TICKS_PER_SECOND = 80000000; // 80 MHz processor @@ -60,13 +60,26 @@ void setup() { // pinMode(LED_BUILTIN, OUTPUT); // won't work, waveshare uses D2 as DC // digitalWrite(LED_BUILTIN, HIGH); - getConfig(); + bool isConfigValid = getConfig(); initMqttClientName(); initAccessPointName(); ctx.initWifiManagerParameters(); bool wifiSetup = setupWifi(); if (wifiSetup) { +// // first check if there is a valid config file +// if (!shouldSaveConfig && !isConfigValid) { +// WiFi.disconnect(); +// delay(3000); +// +// WiFiManager wifiManager; +// wifiManager.resetSettings(); +// wifiManager.erase(true); +// +// ESP.restart(); +// delay(3000); +// } + ctx.updateParameters(); isMqttEnabled = ctx.isMqttEnabled(); @@ -76,17 +89,14 @@ void setup() { Serial.printf(" MQTT CommandTopic: %s\r\n", ctx.mqttCommandTopic); Serial.printf(" sleep time: %ld\r\n", ctx.sleepTime); Serial.printf(" firmware base URL: %s\r\n", ctx.firmwareUrl); - } else { - Serial.println(" Using configuration:"); - ctx.connectionErrorCount++; } saveConfig(); if (!wifiSetup) { + ctx.connectionErrorCount++; if (ctx.connectionErrorCount > MAX_CONNECTION_FAILURES) { Serial.printf(" Failed to connect %d times, resetting WIFI settings."); ctx.connectionErrorCount = 0; - saveConfig(); WiFi.disconnect(); delay(3000); @@ -109,15 +119,20 @@ void setup() { } // ----------------------------------------------------------------------------------------------------- -void getConfig() { +bool getConfig() { + bool configRead = true; if (SPIFFS.begin()) { if (SPIFFS.exists(CONFIG_FILE)) { Serial.println(" Reading config file..."); File configFile = SPIFFS.open(CONFIG_FILE, "r"); if (configFile) { - DynamicJsonDocument jsonDocument(512); - DeserializationError error = deserializeJson(jsonDocument, configFile); + size_t size =configFile.size(); + std::unique_ptr buf(new char[size]); + configFile.readBytes(buf.get(), size); + DynamicJsonDocument jsonDocument(1024); + DeserializationError error = deserializeJson(jsonDocument, buf.get()); if (!error) { + Serial.println(" Parsed JSON config."); strlcpy(ctx.mqttServer, jsonDocument["mqttServer"] | "", sizeof ctx.mqttServer); ctx.mqttPort = jsonDocument["mqttPort"] | 1883; strlcpy(ctx.mqttUser, jsonDocument["mqttUser"] | "", sizeof ctx.mqttUser); @@ -130,15 +145,25 @@ void getConfig() { ctx.connectionErrorCount = jsonDocument["connectionErrorCount"] | 0; Serial.println(" Config file read."); + configFile.close(); + } else { - Serial.println(" Failed to load json config."); + Serial.printf(" Failed to load json config: %s\r\n", error.c_str()); + configFile.close(); + SPIFFS.remove(CONFIG_FILE); + Serial.println(" Config file removed."); + configRead = false; } - configFile.close(); } + } else { + Serial.println(" Config file not found! Using defaults."); + configRead = false; } } else { Serial.println(" Failed to mount FS (probably initial start), continuing w/o config..."); } + + return configRead; } // ----------------------------------------------------------------------------------------------------- @@ -168,7 +193,7 @@ bool setupWifi() { if (!connected) { Serial.println(" Failed to connect."); } else { - Serial.printf(" Connected to WiFi, got IP address: %s\r\n", WiFi.localIP().toString().c_str()); + Serial.printf(" Connected to WiFi, got IP address: %s\r\n", WiFi.localIP().toString().c_str()); } return connected; @@ -190,12 +215,17 @@ void requestMqttParameters(WiFiManager *wifiManager) { // ----------------------------------------------------------------------------------------------------- void saveConfig() { if (shouldSaveConfig) { +// if (SPIFFS.begin()) { +// SPIFFS.format(); +// Serial.println(" SPIFFS formated."); +// } + Serial.println(" Saving config..."); File configFile = SPIFFS.open(CONFIG_FILE, "w"); if (!configFile) { Serial.println(" Failed to open config file for writing."); } - DynamicJsonDocument jsonDocument(512); + DynamicJsonDocument jsonDocument(1024); jsonDocument["mqttServer"] = ctx.mqttServer; jsonDocument["mqttPort"] = ctx.mqttPort; jsonDocument["mqttUser"] = ctx.mqttUser; @@ -211,6 +241,9 @@ void saveConfig() { } configFile.close(); Serial.println(" Config saved."); + + serializeJson(jsonDocument, Serial); + Serial.println(); } } @@ -429,12 +462,14 @@ void callback(char* topic, byte* message, unsigned int length) { // ----------------------------------------------------------------------------------------------------- void reconnect() { - Serial.println("Connecting to MQTT..."); + Serial.printf("Connecting to MQTT: %s:%d...\r\n", ctx.mqttServer, ctx.mqttPort); while (!mqttClient.connected()) { // clientID, username, password, willTopic, willQoS, willRetain, willMessage, cleanSession if (!mqttClient.connect(ctx.mqttClientName, ctx.mqttUser, ctx.mqttPassword, NULL, 0, 0, NULL, 0)) { - delay(1000); + Serial.println(" Connecting failed, try reconnect in 5s."); + delay(5000); } else { + Serial.println(" Connected."); boolean rc = mqttClient.subscribe(ctx.mqttUpdateStatusTopic, 1); if (rc) { Serial.printf(" Subscribed to %s\r\n", ctx.mqttUpdateStatusTopic); diff --git a/README.md b/README.md index c513459..a6665ac 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ Erweiterung des ESP8266-Waveshare-Treibers um Wifi-Einrichtungsassistent, Deepsl ![GitHub issues](https://img.shields.io/github/issues-raw/Yattien/ESPEInk_ESP8266) # Waveshare-Treiberversion -[19.07.2021](https://www.waveshare.com/wiki/File:E-Paper_ESP8266_Driver_Board_Code.7z) +[07.11.2022](https://www.waveshare.com/wiki/File:E-Paper_ESP8266_Driver_Board_Code.7z) # Installation Das fertige Image kann per OTA (siehe auch OTA-Beispiel-Sketche) oder auch per [`esptool`](https://github.com/espressif/esptool) auf den ESP8266 geladen werden. diff --git a/data/config.json b/data/config.json new file mode 100644 index 0000000..2fbf400 --- /dev/null +++ b/data/config.json @@ -0,0 +1 @@ +{"mqttServer":"192.168.1.6","mqttPort":1883,"mqttUser":"","mqttPassword":"","mqttClientName":"ESPEInk_ecfabcc5ba9d","mqttUpdateStatusTopic":"stat/doorDisplay/needUpdate","mqttCommandTopic":"cmd/doorDisplay/upload","sleepTime":60,"firmwareUrl":"","connectionErrorCount":0} \ No newline at end of file diff --git a/epd.h b/epd.h index e31ed1c..e1da946 100644 --- a/epd.h +++ b/epd.h @@ -193,6 +193,7 @@ void EPD_Reset() #include "epd2in7.h" #include "epd2in66.h" #include "epd3in7.h" +#include "epd3in52.h" #include "epd4in01f.h" #include "epd4in2.h" #include "epd5in65f.h" @@ -297,10 +298,10 @@ void EPD_loadC() Serial.print("\r\n EPD_loadC"); int index = 0; String p = server.arg(0); - + // Serial.println(p); // Get the length of the image data begin int DataLength = p.length() - 8; - + EPD_Send_2(0x44, 0, 15); //SET_RAM_X_ADDRESS_START_END_POSITION LO(x >> 3), LO((w - 1) >> 3) EPD_Send_4(0x45, 0, 0, 249, 0); //SET_RAM_Y_ADDRESS_START_END_POSITION LO(y), HI(y), LO(h - 1), HI(h - 1) @@ -584,6 +585,10 @@ EPD_dispInfo EPD_dispMass[] = { {EPD_Init_5in83_V2, EPD_loadAFilp, -1, 0, EPD_showC, "5.83 inch V2" }, // 36 {EPD_4IN01F_init, EPD_loadG, -1, 0, EPD_4IN01F_Show, "4.01 inch F" }, // 37 {EPD_Init_2in7b_V2, EPD_loadA, 0x26, EPD_loadAFilp, EPD_Show_2in7b_V2, "2.7 inch B V2" }, // 38 + {EPD_Init_2in13_V3, EPD_loadC, -1, 0, EPD_2IN13_V3_Show, "2.13 inch V3" }, // 39 + {EPD_2IN13B_V4_Init, EPD_loadC, 0x26, EPD_loadC, EPD_2IN13B_V4_Show, "2.13 inch B V4"}, // 40 + { EPD_3IN52_Init, EPD_loadA, -1, 0, EPD_3IN52_Show, "3.52 inch" },// 41 + { EPD_2IN7_V2_Init, EPD_loadA, -1 , 0, EPD_2IN7_V2_Show, "2.7 inch V2" },// 42 }; /* Initialization of an e-Paper ----------------------------------------------*/ diff --git a/epd2in13.h b/epd2in13.h index 9dfb516..6867644 100644 --- a/epd2in13.h +++ b/epd2in13.h @@ -5,7 +5,7 @@ * @version V1.0.0 * @date 23-January-2018 * @brief This file describes initialisation of e-Papers: - * 2.13, + * 2.13 and 2.13_V3, * 2.13b and 2.13c, * 2.13d. * @@ -36,6 +36,28 @@ const unsigned char lut_full_2in3v2[] = { 0x15,0x41,0xA8,0x32,0x30,0x0A, }; +const unsigned char WS_20_30_2IN13_V3[159] ={ + 0x80, 0x4A, 0x40, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x40, 0x4A, 0x80, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x80, 0x4A, 0x40, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x40, 0x4A, 0x80, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0xF, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0xF, 0x0, 0x0, 0xF, 0x0, 0x0, 0x2, + 0xF, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x0, 0x0, 0x0, + 0x22, 0x17, 0x41, 0x0, 0x32, 0x36 +}; + const unsigned char lut_vcomDC_2in13d[] = { 0x00, 0x08, 0x00, 0x00, 0x00, 0x02, 0x60, 0x28, 0x28, 0x00, 0x00, 0x01, 0x00, 0x14, 0x00, 0x00, 0x00, 0x01, 0x00, 0x12, 0x12, 0x00, @@ -108,24 +130,83 @@ int EPD_Init_2in13() EPD_Send_1(0x4E, 0x00); EPD_Send_2(0x4F, 0xF9, 0x00); - int Width, Height; - Width = (122 % 8 == 0)? (122 / 8 ): (122 / 8 + 1); - Height = 250; - EPD_SendCommand(0x24); - for (int j = 0; j < Height; j++) { - for (int i = 0; i < Width; i++) { - EPD_SendData(0XFF); - } - } - EPD_SendCommand(0x22); - EPD_SendData(0xC7); - EPD_SendCommand(0x20); - while (digitalRead(BUSY_PIN) == 1) delay(100); + int Width, Height; + Width = (122 % 8 == 0)? (122 / 8 ): (122 / 8 + 1); + Height = 250; + EPD_SendCommand(0x24); + for (int j = 0; j < Height; j++) { + for (int i = 0; i < Width; i++) { + EPD_SendData(0XFF); + } + } + EPD_SendCommand(0x22); + EPD_SendData(0xC7); + EPD_SendCommand(0x20); + while (digitalRead(BUSY_PIN) == 1) delay(100); return 0; } } +int EPD_Init_2in13_V3() +{ + Serial.print("\r\nEPD_Init_2in13 V3"); + EPD_Reset(); + delay(100); + while (digitalRead(BUSY_PIN) == 1) delay(10); + EPD_SendCommand(0x12); + while (digitalRead(BUSY_PIN) == 1) delay(10); + EPD_Send_3(0x01, 0XF9, 0X00, 0X00); + EPD_Send_1(0X11, 0X03); + EPD_Send_2(0X44, 0X00, 0X0F); + EPD_Send_4(0x45, 0x00, 0x00, 0x00, 0xF9); + EPD_Send_1(0x4E, 0x00); + EPD_Send_2(0x4F, 0X00, 0X00); + EPD_Send_1(0x3C, 0x05); + EPD_Send_2(0x21, 0x00, 0x80); + EPD_Send_1(0x18, 0x80); + + while (digitalRead(BUSY_PIN) == 1) delay(100); + int count; + EPD_SendCommand(0x32); + for(count = 0; count < 153; count++) + EPD_SendData(WS_20_30_2IN13_V3[count]); + EPD_Send_1(0x3f, WS_20_30_2IN13_V3[153]); + EPD_Send_1(0x03, WS_20_30_2IN13_V3[154]); + EPD_Send_3(0x04, WS_20_30_2IN13_V3[155], WS_20_30_2IN13_V3[156], WS_20_30_2IN13_V3[157]); + EPD_Send_1(0x2C, WS_20_30_2IN13_V3[158]); + + int Width, Height; + Width = (122 % 8 == 0)? (122 / 8 ): (122 / 8 + 1); + Height = 250; + EPD_SendCommand(0x24); + for (int j = 0; j < Height; j++) { + for (int i = 0; i < Width; i++) { + EPD_SendData(0XFF); + } + } + + EPD_SendCommand(0x22); + EPD_SendData(0xC7); + EPD_SendCommand(0x20); + while (digitalRead(BUSY_PIN) == 1) delay(10); + return 0; +} + +/* Show image and turn to deep sleep mode ------*/ +void EPD_2IN13_V3_Show() +{ + Serial.print("\r\n EPD_2IN13_V3_Show"); + // Refresh + EPD_Send_1(0x22, 0xC7); //DISPLAY_UPDATE_CONTROL_2 + EPD_SendCommand(0x20); //MASTER_ACTIVATION + while (digitalRead(BUSY_PIN) == 1) delay(10); + + // Sleep + EPD_Send_1(0x10, 0x01); //DEEP_SLEEP_MODE + EPD_WaitUntilIdle(); +} + int EPD_Init_2in13b() { EPD_Reset(); @@ -173,6 +254,43 @@ void EPD_2IN13B_V3_Show() EPD_Send_1(0X07, 0xa5); //deep sleep } +int EPD_2IN13B_V4_Init(void) +{ + EPD_Reset(); + delay(10); + + EPD_WaitUntilIdle_high(); + EPD_SendCommand(0x12); //SWRESET + EPD_WaitUntilIdle_high(); + + EPD_Send_3(0x01, 0xf9, 0x00, 0x00); //Driver output control + + EPD_Send_1(0x11, 0x03); //data entry mode + + EPD_Send_2(0X44, 0X00, 0X0F); + EPD_Send_4(0x45, 0x00, 0x00, 0x00, 0xF9); + EPD_Send_1(0x4E, 0x00); + EPD_Send_2(0x4F, 0X00, 0X00); + + EPD_Send_1(0x3C, 0x05); //BorderWavefrom + EPD_Send_1(0x18, 0x80); //Read built-in temperature sensor + EPD_Send_2(0x21, 0x80, 0x80); // Display update control + + EPD_WaitUntilIdle_high(); + + EPD_SendCommand(0x24); + + return 0; +} + +void EPD_2IN13B_V4_Show() +{ + EPD_SendCommand(0x20); //DISPLAY REFRESH + delay(2); + EPD_WaitUntilIdle_high(); + + EPD_Send_1(0X10, 0x01); +} int EPD_Init_2in13d() { diff --git a/epd2in7.h b/epd2in7.h index 50b99a2..fc87cee 100644 --- a/epd2in7.h +++ b/epd2in7.h @@ -94,6 +94,44 @@ int EPD_Init_2in7() return 0; } +int EPD_2IN7_V2_Init(void) +{ + EPD_Reset(); + EPD_WaitUntilIdle_high(); + + EPD_SendCommand(0x12); //SWRESET + EPD_WaitUntilIdle_high(); + + EPD_SendCommand(0x45); //set Ram-Y address start/end position + EPD_SendData(0x00); + EPD_SendData(0x00); + EPD_SendData(0x07); //0x0107-->(263+1)=264 + EPD_SendData(0x01); + + EPD_SendCommand(0x4F); // set RAM y address count to 0; + EPD_SendData(0x00); + EPD_SendData(0x00); + + EPD_SendCommand(0x11); // data entry mode + EPD_SendData(0x03); + + EPD_SendCommand(0x24); + delay(2); + return 0; +} + +void EPD_2IN7_V2_Show(void) +{ + EPD_SendCommand(0x22); //Display Update Control + EPD_SendData(0XF7); + EPD_SendCommand(0x20); //Activate Display Update Sequence + EPD_WaitUntilIdle_high(); + delay(2); + Serial.print("EPD_2IN7_V2_Show END\r\n"); + EPD_SendCommand(0X07); //deep sleep + EPD_SendData(0xA5); +} + unsigned char lut_dc_2in7b[] = { 0x00, 0x00, 0x00, 0x1A, 0x1A, 0x00, 0x00, 0x01, 0x00, 0x0A, 0x0A, diff --git a/epd3in52.h b/epd3in52.h new file mode 100644 index 0000000..15527fe --- /dev/null +++ b/epd3in52.h @@ -0,0 +1,247 @@ +/***************************************************************************** +* | File : EPD_3IN52.h +* | Author : Waveshare team +* | Function : 3.52inch e-paper +* | Info : +*---------------- +* | This version: V1.0 +* | Date : 2022-11-02 +* | Info : +* ----------------------------------------------------------------------------- +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documnetation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. +# +******************************************************************************/ + +//GC 0.9S +static const UBYTE EPD_3IN52_lut_R20_GC[] = +{ + 0x01,0x0f,0x0f,0x0f,0x01,0x01,0x01, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00 +}; +static const UBYTE EPD_3IN52_lut_R21_GC[] = +{ + 0x01,0x4f,0x8f,0x0f,0x01,0x01,0x01, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00 +}; +static const UBYTE EPD_3IN52_lut_R22_GC[] = +{ + 0x01,0x0f,0x8f,0x0f,0x01,0x01,0x01, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00 +}; +static const UBYTE EPD_3IN52_lut_R23_GC[] = +{ + 0x01,0x4f,0x8f,0x4f,0x01,0x01,0x01, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00 +}; +static const UBYTE EPD_3IN52_lut_R24_GC[] = +{ + 0x01,0x0f,0x8f,0x4f,0x01,0x01,0x01, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00 +}; + +UBYTE EPD_3IN52_Flag; + +/****************************************************************************** +function : Read Busy +parameter: +******************************************************************************/ +void EPD_3IN52_ReadBusy(void) +{ + Serial.print("e-Paper busy\r\n"); + UBYTE busy; + do { + busy = digitalRead(BUSY_PIN); + delay(20); + } while(!busy); + delay(200); + Serial.print("e-Paper busy release\r\n"); +} + +/** + * @brief + * + */ +void EPD_3IN52_refresh(void) +{ + EPD_SendCommand(0x17); + EPD_SendData(0xA5); + EPD_3IN52_ReadBusy(); + delay(200); +} + +// LUT download +void EPD_3IN52_lut_GC(void) +{ + UBYTE count; + EPD_SendCommand(0x20); // vcom + for(count = 0; count < 56 ; count++) + { + EPD_SendData(EPD_3IN52_lut_R20_GC[count]); + } + + EPD_SendCommand(0x21); // red not use + for(count = 0; count < 42 ; count++) + { + EPD_SendData(EPD_3IN52_lut_R21_GC[count]); + } + + EPD_SendCommand(0x24); // bb b + for(count = 0; count < 42 ; count++) + { + EPD_SendData(EPD_3IN52_lut_R24_GC[count]); + } + + if(EPD_3IN52_Flag == 0) + { + EPD_SendCommand(0x22); // bw r + for(count = 0; count < 56 ; count++) + { + EPD_SendData(EPD_3IN52_lut_R22_GC[count]); + } + + EPD_SendCommand(0x23); // wb w + for(count = 0; count < 42 ; count++) + { + EPD_SendData(EPD_3IN52_lut_R23_GC[count]); + } + + EPD_3IN52_Flag = 1; + } + + else + { + EPD_SendCommand(0x22); // bw r + for(count = 0; count < 56 ; count++) + { + EPD_SendData(EPD_3IN52_lut_R23_GC[count]); + } + + EPD_SendCommand(0x23); // wb w + for(count = 0; count < 42 ; count++) + { + EPD_SendData(EPD_3IN52_lut_R22_GC[count]); + } + + EPD_3IN52_Flag = 0; + } +} + + +void EPD_3IN52_Clear(void) +{ + EPD_SendCommand(0x13); + for(int i=0; i<10800; i++) + EPD_SendData(0xFF); + EPD_3IN52_lut_GC(); + EPD_3IN52_refresh(); + + EPD_SendCommand(0x50); + EPD_SendData(0x17); + + delay(500); +} + +/****************************************************************************** +function : Initialize the e-Paper register +parameter: +******************************************************************************/ +int EPD_3IN52_Init(void) +{ + EPD_3IN52_Flag = 0; + EPD_Reset(); + + EPD_SendCommand(0x00); // panel setting PSR + EPD_SendData(0xFF); // RES1 RES0 REG KW/R UD SHL SHD_N RST_N + EPD_SendData(0x01); // x x x VCMZ TS_AUTO TIGE NORG VC_LUTZ + + EPD_SendCommand(0x01); // POWER SETTING PWR + EPD_SendData(0x03); // x x x x x x VDS_EN VDG_EN + EPD_SendData(0x10); // x x x VCOM_SLWE VGH[3:0] VGH=20V, VGL=-20V + EPD_SendData(0x3F); // x x VSH[5:0] VSH = 15V + EPD_SendData(0x3F); // x x VSL[5:0] VSL=-15V + EPD_SendData(0x03); // OPTEN VDHR[6:0] VHDR=6.4V + // T_VDS_OFF[1:0] 00=1 frame; 01=2 frame; 10=3 frame; 11=4 frame + EPD_SendCommand(0x06); // booster soft start BTST + EPD_SendData(0x37); // BT_PHA[7:0] + EPD_SendData(0x3D); // BT_PHB[7:0] + EPD_SendData(0x3D); // x x BT_PHC[5:0] + + EPD_SendCommand(0x60); // TCON setting TCON + EPD_SendData(0x22); // S2G[3:0] G2S[3:0] non-overlap = 12 + + EPD_SendCommand(0x82); // VCOM_DC setting VDCS + EPD_SendData(0x07); // x VDCS[6:0] VCOM_DC value= -1.9v 00~3f,0x12=-1.9v + + EPD_SendCommand(0x30); + EPD_SendData(0x09); + + EPD_SendCommand(0xe3); // power saving PWS + EPD_SendData(0x88); // VCOM_W[3:0] SD_W[3:0] + + EPD_SendCommand(0x61); // resoultion setting + EPD_SendData(0xf0); // HRES[7:3] 0 0 0 + EPD_SendData(0x01); // x x x x x x x VRES[8] + EPD_SendData(0x68); // VRES[7:0] + + EPD_SendCommand(0x50); + EPD_SendData(0xB7); + + EPD_3IN52_Clear(); + + EPD_SendCommand(0x13);//DATA_START_TRANSMISSION_1 + delay(2); + return 0; +} + +void EPD_3IN52_Show(void) +{ + EPD_3IN52_lut_GC(); + EPD_3IN52_refresh(); + delay(2); + Serial.print("EPD_3IN52_Show END\r\n"); + EPD_SendCommand(0X07); //deep sleep + EPD_SendData(0xA5); +} diff --git a/epd3in7.h b/epd3in7.h index 72514b9..89be23c 100644 --- a/epd3in7.h +++ b/epd3in7.h @@ -169,9 +169,6 @@ static void EPD_3IN7_1Gray_Show(void) EPD_3IN7_ReadBusy_HIGH(); Serial.print("EPD_3IN7_Show END\r\n"); - EPD_SendCommand(0X50); - EPD_SendData(0xf7); - EPD_SendCommand(0X02); //power off - EPD_SendCommand(0X07); //deep sleep - EPD_SendData(0xA5); + EPD_SendCommand(0X10); //deep sleep + EPD_SendData(0x03); } diff --git a/epd7in5b_HD.h b/epd7in5b_HD.h new file mode 100644 index 0000000..78f2edd --- /dev/null +++ b/epd7in5b_HD.h @@ -0,0 +1,60 @@ +/** + ****************************************************************************** + @file edp7in5b_HD.h + @author Waveshare Team + @version V1.0.0 + @date 23-January-2018 + @brief This file describes initialisation of 7.5 and 7.5b e-Papers + + ****************************************************************************** +*/ +#include +static void EPD_7in5B_HD_Readbusy(void) +{ + Serial.print("\r\ne-Paper busy\r\n"); + unsigned char busy; + WiFiClient client ; + do { + busy = digitalRead(BUSY_PIN); + ESP.wdtFeed(); + server.handleClient(); + } while (busy); + Serial.print("e-Paper busy release\r\n"); + delay(200); +} + +int EPD_7in5B_HD_init() +{ + EPD_Reset(); + Serial.print("EPD_7in5B_HD_init\r\n"); + EPD_SendCommand(0x12); //SWRESET + EPD_7in5B_HD_Readbusy(); + EPD_Send_1(0X46, 0XF7); + EPD_7in5B_HD_Readbusy(); + EPD_Send_1(0X47, 0XF7); + EPD_7in5B_HD_Readbusy(); + EPD_Send_5(0X0C, 0XAE, 0XC7, 0XC3, 0XC0, 0X40); + EPD_Send_3(0X01, 0XAF, 0X02, 0X01); + EPD_Send_1(0X11, 0X01); + EPD_Send_4(0X44, 0X00, 0X00, 0X6F, 0X03); + EPD_Send_4(0X45, 0XAF, 0X02, 0X00, 0X00); + EPD_Send_1(0X3C, 0X01); + EPD_Send_1(0X18, 0X80); + EPD_Send_1(0X22, 0XB1); + EPD_SendCommand(0X20); + EPD_7in5B_HD_Readbusy(); + EPD_Send_2(0X4E, 0X00, 0X00); + EPD_Send_2(0X4F, 0XAF, 0X02); + EPD_SendCommand(0X24); + + return 0; +} + +void EPD_7IN5B_HD_Show(void) +{ + EPD_Send_1(0X22, 0XC7); + EPD_SendCommand(0X20); + delay(10); //!!!The delay here is necessary, 200uS at least!!! + EPD_7in5B_HD_Readbusy(); + //EPD_Send_1(0X10, 0X01); //deep sleep +} diff --git a/scripts.h b/scripts.h index 642553c..470e4e1 100644 --- a/scripts.h +++ b/scripts.h @@ -89,8 +89,9 @@ server.send(200, "text/javascript", "[152,296,0],[648,480,1],[128,296,1],\r\n" "[200,200,1],[104,214,1],[128,296,0],\r\n" "[400,300,1],[152,296,1],[648,480,0],\r\n" -"[640,400,7],[176,264,1]];\r\n" - +"[640,400,7],[176,264,1],[122,250,0],\r\n" +"[122,250,1],[240,360,0],[176,264,0]];\r\n" + "setInn('BT',\r\n" "Btn(0,'Select image file','processFiles(this.files);')+\r\n" "Btn(1,'Level: mono','procImg(true,false);')+\r\n" @@ -102,19 +103,23 @@ server.send(200, "text/javascript", "setInn('XY',getNud('x','0')+getNud('y','0'));\r\n" "setInn('WH',getNud('w','200')+getNud('h','200'));\r\n" -"setInn('RB',RB(0,'1.54 ')+RB(1,'1.54b')+RB(2,'1.54c')+\r\n" -"RB(3,'2.13 ')+RB(4,'2.13b')+RB(5,'2.13c
')+RB(6,'2.13d
')+\r\n" -"RB(7,'2.7  ')+RB(8,'2.7b 
')+\r\n" -"RB(9,'2.9  ')+RB(10,'2.9b ')+RB(11,'2.9c 
')+RB(12,'2.9d
')+\r\n" -"RB(13,'4.2  ')+RB(14,'4.2b ')+RB(15,'4.2c 
')+\r\n" -"RB(16,'5.83 ')+RB(17,'5.83b')+RB(18,'5.83c
')+\r\n" -"RB(19,'7.5  ')+RB(20,'7.5b ')+RB(21,'7.5c 
')+\r\n" -"RB(22,'7.5 V2')+RB(23,'7.5b V2
')+\r\n" -"RB(24,'7.5b HD  ')+\r\n" -"RB(25,'5.65f
') + RB(26,'7.5 HD') + RB(27,'3.7
') + RB(28,'2.66') + RB(29,'5.83b V2
')+\r\n" -"RB(30,'2.9b V3') + RB(31,'1.54b V2
') + RB(32,'2.13b V3') + RB(33,'2.9 V2
')+\r\n" -"RB(34,'4.2b V2') + RB(35,'2.66b
') + RB(36,'5.83 V2') + RB(37,'4.01 f
')+\r\n" -"RB(38,'2.7b V2'));\r\n" +"setInn('RB',RB(0,'1.54 ')+RB(1,'1.54b')+RB(2,'1.54c 
')+\r\n" +"RB(3,'2.13 ')+RB(4,'2.13b')+RB(5,'2.13c
')+\r\n" +"RB(6,'2.13d')+RB(7,'2.7  ')+RB(8,'2.7b 
')+\r\n" +"RB(9,'2.9  ')+RB(10,'2.9b ')+RB(11,'2.9c 
')+\r\n" +"RB(12,'2.9d ')+RB(13,'4.2  ')+RB(14,'4.2b 
')+\r\n" +"RB(15,'4.2c ')+RB(16,'5.83 ')+RB(17,'5.83b
')+\r\n" +"RB(18,'5.83c ')+RB(19,'7.5  ')+RB(20,'7.5b 
')+\r\n" +"RB(21,'7.5c')+RB(22,'7.5 V2')+RB(23,'7.5b V2
')+\r\n" +"RB(24,'7.5b HD ')+RB(25,'5.65f
')+\r\n" +"RB(26,'7.5 HD ')+RB(27,'3.7 ')+RB(28,'2.66
')+\r\n" +"RB(29,'5.83b V2 ')+RB(30,'2.9b V3
')+\r\n" +"RB(31,'1.54b V2 ')+RB(32,'2.13b V3
')+\r\n" +"RB(33,'2.9 V2 ')+RB(34,'4.2b V2
')+\r\n" +"RB(35,'2.66b ')+RB(36,'5.83 V2
')+\r\n" +"RB(37,'4.01 f ')+RB(38,'2.7b V2
')+\r\n" +"RB(39,'2.13 V3 ')+RB(40,'2.13 B V4
')+\r\n" +"RB(41,'3.52 ')+RB(42,'2.7 V2'));\r\n" "}\r\n" //------------------------------------------- "function rbClick(index){\r\n" @@ -408,7 +413,7 @@ server.send(200, "text/javascript", "return u_loadA(a,k1,k2);\r\n" "}\r\n" //------------------------------------------- -"function u_dataB(a,k1,k2){\r\n" +"function u_dataB(a,c,k1,k2){\r\n" "var x;\r\n" "rqMsg='';\r\n" "svPrv();\r\n" @@ -420,7 +425,7 @@ server.send(200, "text/javascript", "while(x<122)\r\n" "{\r\n" "var v=0;\r\n" - "for (var i=0;(i<8)&&(x<122);i++,x++)if(a[pxInd++]!=0)v|=(128>>i);\r\n" + "for (var i=0;(i<8)&&(x<122);i++,x++)if(a[pxInd++]!=c)v|=(128>>i);\r\n" "rqMsg += byteToStr(v);\r\n" "}\r\n" "}\r\n" @@ -448,21 +453,33 @@ server.send(200, "text/javascript", "rqPrf='http://'+getElm('ip_addr').value+'/';\r\n" "var init='EPD';\r\n" - "if (epdInd==3){\r\n" + "if ((epdInd==3) || (epdInd==39) ){\r\n" "xhReq.onload=xhReq.onerror = function(){\r\n" "ldPrv();\r\n" - "if(stInd==0)return u_dataB(a,0,100);\r\n" + "if(stInd==0)return u_dataB(a,0,0,100);\r\n" "if(stInd==1)return u_done();\r\n" "};\r\n" - "xhReq.open('POST',init, true);\r\n" "xhReq.send(byteToStr(epdInd));\r\n" "return 0;\r\n" "}\r\n" - + "if ((epdInd==40)){\r\n" + "xhReq.onload=xhReq.onerror = function(){\r\n" + "ldPrv();\r\n" + "if(stInd==0)return u_dataB(a,0,0,50);\r\n" + "if(stInd==1)return u_next();\r\n" + "if(stInd==2)return u_dataB(a,3,50,50);\r\n" + "if(stInd==3)return u_done();\r\n" + "};\r\n" + "xhReq.open('POST',init, true);\r\n" + "xhReq.send(byteToStr(epdInd));\r\n" + "return 0;\r\n" + "}\r\n" + + "if ((epdInd==0)||(epdInd==3)||(epdInd==6)||(epdInd==7)||(epdInd==9)||(epdInd==12)||(epdInd==16)||\ - (epdInd==19)||(epdInd==22)||(epdInd==26)||(epdInd==27)||(epdInd==28)){\r\n" + (epdInd==19)||(epdInd==22)||(epdInd==26)||(epdInd==27)||(epdInd==28) || (epdInd==39) ){\r\n" "xhReq.onload=xhReq.onerror=function(){\r\n" "ldPrv();\r\n" "if(stInd==0)return u_dataA(a,0,0,100);\r\n"