2018-08-28 17:13:14 +01:00
|
|
|
/*
|
2019-10-27 10:13:24 +00:00
|
|
|
xdsp_05_epaper.ino - Display e-paper support for Tasmota
|
2018-08-28 17:13:14 +01:00
|
|
|
|
2021-01-01 12:44:04 +00:00
|
|
|
Copyright (C) 2021 Theo Arends, Gerhard Mutz and Waveshare
|
2018-08-28 17:13:14 +01:00
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef USE_SPI
|
|
|
|
#ifdef USE_DISPLAY
|
2019-08-19 15:49:20 +01:00
|
|
|
#ifdef USE_DISPLAY_EPAPER_29
|
2018-08-28 17:13:14 +01:00
|
|
|
|
|
|
|
#define XDSP_05 5
|
|
|
|
|
2018-11-29 16:50:45 +00:00
|
|
|
#define EPD_TOP 12
|
|
|
|
#define EPD_FONT_HEIGTH 12
|
|
|
|
|
2019-08-19 12:21:54 +01:00
|
|
|
#define COLORED 1
|
|
|
|
#define UNCOLORED 0
|
2018-08-28 17:13:14 +01:00
|
|
|
|
|
|
|
// using font 8 is opional (num=3)
|
|
|
|
// very badly readable, but may be useful for graphs
|
|
|
|
#define USE_TINY_FONT
|
|
|
|
|
|
|
|
#include <epd2in9.h>
|
|
|
|
#include <epdpaint.h>
|
|
|
|
|
2019-08-19 12:21:54 +01:00
|
|
|
//unsigned char image[(EPD_HEIGHT * EPD_WIDTH) / 8];
|
2018-11-29 16:50:45 +00:00
|
|
|
uint16_t epd_scroll;
|
2020-12-31 15:17:30 +00:00
|
|
|
bool epd_init_done = false;
|
2018-11-29 16:50:45 +00:00
|
|
|
|
2019-08-19 12:21:54 +01:00
|
|
|
Epd *epd;
|
2018-08-28 17:13:14 +01:00
|
|
|
|
2019-08-19 12:21:54 +01:00
|
|
|
/*********************************************************************************************/
|
2018-08-28 17:13:14 +01:00
|
|
|
|
2020-12-31 15:17:30 +00:00
|
|
|
void EpdInitDriver29(void) {
|
|
|
|
if (PinUsed(GPIO_EPAPER29_CS) &&
|
|
|
|
((TasmotaGlobal.soft_spi_enabled & SPI_MOSI) || (TasmotaGlobal.spi_enabled & SPI_MOSI))) {
|
|
|
|
|
2021-06-11 17:14:12 +01:00
|
|
|
Settings->display_model = XDSP_05;
|
2018-08-28 17:13:14 +01:00
|
|
|
|
2021-06-11 17:14:12 +01:00
|
|
|
if (Settings->display_width != EPD_WIDTH) {
|
|
|
|
Settings->display_width = EPD_WIDTH;
|
2019-07-23 13:05:42 +01:00
|
|
|
}
|
2021-06-11 17:14:12 +01:00
|
|
|
if (Settings->display_height != EPD_HEIGHT) {
|
|
|
|
Settings->display_height = EPD_HEIGHT;
|
2019-07-23 13:05:42 +01:00
|
|
|
}
|
|
|
|
|
2019-08-19 12:21:54 +01:00
|
|
|
// init renderer
|
2020-12-31 15:17:30 +00:00
|
|
|
epd = new Epd(EPD_WIDTH, EPD_HEIGHT);
|
2019-08-19 12:21:54 +01:00
|
|
|
|
|
|
|
// whiten display with full update, takes 3 seconds
|
2020-12-31 15:17:30 +00:00
|
|
|
if (TasmotaGlobal.soft_spi_enabled) {
|
2023-01-18 07:50:22 +00:00
|
|
|
epd->Begin(Pin(GPIO_EPAPER29_CS), Pin(GPIO_SSPI_MOSI), Pin(GPIO_SSPI_SCLK), Pin(GPIO_OLED_RESET), Pin(GPIO_SSPI_MISO));
|
2018-11-29 16:50:45 +00:00
|
|
|
}
|
2020-12-31 15:17:30 +00:00
|
|
|
else if (TasmotaGlobal.spi_enabled) {
|
2023-01-18 07:50:22 +00:00
|
|
|
epd->Begin(Pin(GPIO_EPAPER29_CS), Pin(GPIO_SPI_MOSI), Pin(GPIO_SPI_CLK), Pin(GPIO_OLED_RESET));
|
2018-11-29 16:50:45 +00:00
|
|
|
}
|
2018-08-28 17:13:14 +01:00
|
|
|
|
2019-08-19 12:21:54 +01:00
|
|
|
renderer = epd;
|
2021-04-21 10:01:40 +01:00
|
|
|
|
2019-08-19 12:21:54 +01:00
|
|
|
epd->Init(DISPLAY_INIT_FULL);
|
|
|
|
epd->Init(DISPLAY_INIT_PARTIAL);
|
2021-06-11 17:14:12 +01:00
|
|
|
renderer->DisplayInit(DISPLAY_INIT_MODE,Settings->display_size,Settings->display_rotate,Settings->display_font);
|
2018-08-28 17:13:14 +01:00
|
|
|
|
2019-08-19 12:21:54 +01:00
|
|
|
renderer->setTextColor(1,0);
|
2018-08-28 17:13:14 +01:00
|
|
|
|
2019-08-19 12:21:54 +01:00
|
|
|
#ifdef SHOW_SPLASH
|
2022-03-05 21:56:24 +00:00
|
|
|
if (!Settings->flag5.display_no_splash) {
|
|
|
|
// Welcome text
|
|
|
|
delay(100);
|
|
|
|
renderer->setTextFont(1);
|
|
|
|
renderer->DrawStringAt(50, 50, "Waveshare E-Paper Display!", COLORED,0);
|
|
|
|
renderer->Updateframe();
|
|
|
|
delay(1000);
|
|
|
|
renderer->fillScreen(0);
|
|
|
|
}
|
2018-08-28 17:13:14 +01:00
|
|
|
#endif
|
|
|
|
|
2020-12-31 15:17:30 +00:00
|
|
|
epd_init_done = true;
|
2021-01-23 16:10:06 +00:00
|
|
|
AddLog(LOG_LEVEL_INFO, PSTR("DSP: E-Paper 2.9"));
|
2018-08-28 17:13:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-19 12:21:54 +01:00
|
|
|
/*********************************************************************************************/
|
2018-08-28 17:13:14 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************************************/
|
|
|
|
|
|
|
|
#ifdef USE_DISPLAY_MODES1TO5
|
2019-08-19 12:21:54 +01:00
|
|
|
#define EPD_FONT_HEIGTH 12
|
|
|
|
void EpdPrintLog29(void)
|
2018-11-29 16:50:45 +00:00
|
|
|
{
|
2019-09-08 19:48:47 +01:00
|
|
|
|
2018-11-29 16:50:45 +00:00
|
|
|
disp_refresh--;
|
|
|
|
if (!disp_refresh) {
|
2021-06-11 17:14:12 +01:00
|
|
|
disp_refresh = Settings->display_refresh;
|
|
|
|
//if (Settings->display_rotate) {
|
2018-11-29 16:50:45 +00:00
|
|
|
if (!disp_screen_buffer_cols) { DisplayAllocScreenBuffer(); }
|
2019-09-08 19:48:47 +01:00
|
|
|
//}
|
2018-11-29 16:50:45 +00:00
|
|
|
|
|
|
|
char* txt = DisplayLogBuffer('\040');
|
2019-03-26 17:26:50 +00:00
|
|
|
if (txt != nullptr) {
|
2021-06-11 17:14:12 +01:00
|
|
|
uint8_t size = Settings->display_size;
|
2018-11-29 16:50:45 +00:00
|
|
|
uint16_t theight = size * EPD_FONT_HEIGTH;
|
|
|
|
|
2019-08-19 12:21:54 +01:00
|
|
|
renderer->setTextFont(size);
|
2021-06-11 17:14:12 +01:00
|
|
|
uint8_t last_row = Settings->display_rows -1;
|
2018-11-29 16:50:45 +00:00
|
|
|
|
|
|
|
// epd_scroll = theight; // Start below header
|
|
|
|
epd_scroll = 0; // Start at top with no header
|
2019-06-30 15:44:36 +01:00
|
|
|
for (uint32_t i = 0; i < last_row; i++) {
|
2018-11-29 16:50:45 +00:00
|
|
|
strlcpy(disp_screen_buffer[i], disp_screen_buffer[i +1], disp_screen_buffer_cols);
|
2019-08-19 12:21:54 +01:00
|
|
|
renderer->DrawStringAt(0, epd_scroll, disp_screen_buffer[i], COLORED, 0);
|
2018-11-29 16:50:45 +00:00
|
|
|
epd_scroll += theight;
|
|
|
|
}
|
|
|
|
strlcpy(disp_screen_buffer[last_row], txt, disp_screen_buffer_cols);
|
|
|
|
DisplayFillScreen(last_row);
|
2019-08-19 12:21:54 +01:00
|
|
|
renderer->DrawStringAt(0, epd_scroll, disp_screen_buffer[last_row], COLORED, 0);
|
2018-11-29 16:50:45 +00:00
|
|
|
// EpdDisplayFrame();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-19 12:21:54 +01:00
|
|
|
void EpdRefresh29(void) // Every second
|
2018-08-28 17:13:14 +01:00
|
|
|
{
|
2021-06-11 17:14:12 +01:00
|
|
|
if (Settings->display_mode) { // Mode 0 is User text
|
2019-09-08 19:48:47 +01:00
|
|
|
|
|
|
|
if (!renderer) return;
|
2018-11-29 16:50:45 +00:00
|
|
|
/*
|
2021-06-11 17:14:12 +01:00
|
|
|
char tftdt[Settings->display_cols[0] +1];
|
2018-11-29 16:50:45 +00:00
|
|
|
char date4[11]; // 24-04-2017
|
2021-06-11 17:14:12 +01:00
|
|
|
char space[Settings->display_cols[0] - 17];
|
2018-11-29 16:50:45 +00:00
|
|
|
char time[9]; // 13:45:43
|
|
|
|
|
|
|
|
EpdSetFont(1);
|
|
|
|
|
|
|
|
snprintf_P(date4, sizeof(date4), PSTR("%02d" D_MONTH_DAY_SEPARATOR "%02d" D_YEAR_MONTH_SEPARATOR "%04d"), RtcTime.day_of_month, RtcTime.month, RtcTime.year);
|
|
|
|
memset(space, 0x20, sizeof(space));
|
|
|
|
space[sizeof(space) -1] = '\0';
|
|
|
|
snprintf_P(time, sizeof(time), PSTR("%02d" D_HOUR_MINUTE_SEPARATOR "%02d" D_MINUTE_SECOND_SEPARATOR "%02d"), RtcTime.hour, RtcTime.minute, RtcTime.second);
|
|
|
|
snprintf_P(tftdt, sizeof(tftdt), PSTR("%s%s%s"), date4, space, time);
|
|
|
|
|
|
|
|
EpdDrawStringAt(0, 0, tftdt, COLORED, 0);
|
|
|
|
*/
|
2021-06-11 17:14:12 +01:00
|
|
|
switch (Settings->display_mode) {
|
2018-11-29 16:50:45 +00:00
|
|
|
case 1: // Text
|
|
|
|
case 2: // Local
|
|
|
|
case 3: // Local
|
|
|
|
case 4: // Mqtt
|
|
|
|
case 5: // Mqtt
|
2019-08-19 12:21:54 +01:00
|
|
|
EpdPrintLog29();
|
|
|
|
renderer->Updateframe();
|
2018-11-29 16:50:45 +00:00
|
|
|
break;
|
|
|
|
}
|
2018-08-28 17:13:14 +01:00
|
|
|
|
2018-11-29 16:50:45 +00:00
|
|
|
// EpdDisplayFrame();
|
2018-08-28 17:13:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // USE_DISPLAY_MODES1TO5
|
|
|
|
|
|
|
|
/*********************************************************************************************\
|
|
|
|
* Interface
|
|
|
|
\*********************************************************************************************/
|
|
|
|
|
2022-11-11 09:44:56 +00:00
|
|
|
bool Xdsp05(uint32_t function)
|
2018-08-28 17:13:14 +01:00
|
|
|
{
|
2019-01-28 13:08:33 +00:00
|
|
|
bool result = false;
|
2020-12-31 15:17:30 +00:00
|
|
|
|
|
|
|
if (FUNC_DISPLAY_INIT_DRIVER == function) {
|
|
|
|
EpdInitDriver29();
|
|
|
|
}
|
2021-06-11 17:14:12 +01:00
|
|
|
else if (epd_init_done && (XDSP_05 == Settings->display_model)) {
|
2020-12-31 15:17:30 +00:00
|
|
|
switch (function) {
|
|
|
|
case FUNC_DISPLAY_MODEL:
|
|
|
|
result = true;
|
|
|
|
break;
|
2018-08-28 17:13:14 +01:00
|
|
|
#ifdef USE_DISPLAY_MODES1TO5
|
2020-12-31 15:17:30 +00:00
|
|
|
case FUNC_DISPLAY_EVERY_SECOND:
|
|
|
|
EpdRefresh29();
|
|
|
|
break;
|
2018-08-28 17:13:14 +01:00
|
|
|
#endif // USE_DISPLAY_MODES1TO5
|
|
|
|
}
|
2020-12-31 15:17:30 +00:00
|
|
|
}
|
2018-08-28 17:13:14 +01:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2019-08-19 12:21:54 +01:00
|
|
|
#endif // USE_DISPLAY_EPAPER
|
2018-08-28 17:13:14 +01:00
|
|
|
#endif // USE_DISPLAY
|
|
|
|
#endif // USE_SPI
|