Tasmota/tasmota/xdsp_06_epaper_42.ino

146 lines
3.7 KiB
Arduino
Raw Normal View History

2019-08-19 12:21:54 +01:00
/*
xdsp_05_epaper.ino - Display e-paper support for Tasmota
2019-08-19 12:21:54 +01:00
2021-01-01 12:44:04 +00:00
Copyright (C) 2021 Theo Arends, Gerhard Mutz and Waveshare
2019-08-19 12:21:54 +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/>.
*/
2019-08-23 09:26:09 +01:00
2019-08-19 12:21:54 +01:00
#ifdef USE_SPI
#ifdef USE_DISPLAY
#ifdef USE_DISPLAY_EPAPER_42
2019-08-19 12:21:54 +01:00
#define XDSP_06 6
#define COLORED42 1
#define UNCOLORED42 0
// using font 8 is opional (num=3)
// very badly readable, but may be useful for graphs
#define USE_TINY_FONT
#include <epd4in2.h>
#include <epdpaint.h>
bool epd42_init_done = false;
2019-08-19 12:21:54 +01:00
Epd42 *epd42;
2019-08-23 09:26:09 +01:00
2019-08-19 12:21:54 +01:00
/*********************************************************************************************/
void EpdInitDriver42() {
if (PinUsed(GPIO_EPAPER42_CS) &&
((TasmotaGlobal.soft_spi_enabled & SPI_MOSI) || (TasmotaGlobal.spi_enabled & SPI_MOSI))) {
2019-08-19 12:21:54 +01:00
2021-06-11 17:14:12 +01:00
Settings->display_model = XDSP_06;
2019-08-19 12:21:54 +01:00
2021-06-11 17:14:12 +01:00
if (Settings->display_width != EPD_WIDTH42) {
Settings->display_width = EPD_WIDTH42;
2019-08-19 12:21:54 +01:00
}
2021-06-11 17:14:12 +01:00
if (Settings->display_height != EPD_HEIGHT42) {
Settings->display_height = EPD_HEIGHT42;
2019-08-19 12:21:54 +01:00
}
// init renderer
epd42 = new Epd42(EPD_WIDTH42, EPD_HEIGHT42);
if (TasmotaGlobal.soft_spi_enabled) {
epd42->Begin(Pin(GPIO_EPAPER42_CS), Pin(GPIO_SSPI_MOSI), Pin(GPIO_SSPI_SCLK));
}
else if (TasmotaGlobal.spi_enabled) {
epd42->Begin(Pin(GPIO_EPAPER42_CS), Pin(GPIO_SPI_MOSI), Pin(GPIO_SPI_CLK));
}
2019-08-19 12:21:54 +01:00
renderer = epd42;
epd42->Init();
renderer->fillScreen(0);
// whiten display with full update, takes 4 seconds
epd42->Init(DISPLAY_INIT_FULL);
2021-06-11 17:14:12 +01:00
renderer->DisplayInit(DISPLAY_INIT_MODE,Settings->display_size,Settings->display_rotate,Settings->display_font);
2019-08-19 12:21:54 +01:00
epd42->ClearFrame();
renderer->Updateframe();
delay(3000);
renderer->setTextColor(1,0);
#ifdef SHOW_SPLASH
if (!Settings->flag5.display_no_splash) {
// Welcome text
renderer->setTextFont(2);
renderer->DrawStringAt(50, 140, "Waveshare E-Paper!", COLORED42,0);
renderer->Updateframe();
delay(350);
renderer->fillScreen(0);
}
2019-08-19 12:21:54 +01:00
#endif
epd42_init_done = true;
2021-01-23 16:10:06 +00:00
AddLog(LOG_LEVEL_INFO, PSTR("DSP: E-Paper 4.2"));
2019-08-19 12:21:54 +01:00
}
}
/*********************************************************************************************/
/*********************************************************************************************/
#ifdef USE_DISPLAY_MODES1TO5
void EpdRefresh42() // Every second
{
2021-06-11 17:14:12 +01:00
if (Settings->display_mode) { // Mode 0 is User text
2019-08-19 12:21:54 +01:00
}
}
#endif // USE_DISPLAY_MODES1TO5
2019-08-23 09:26:09 +01:00
2019-08-19 12:21:54 +01:00
/*********************************************************************************************\
* Interface
\*********************************************************************************************/
2019-08-23 09:26:09 +01:00
bool Xdsp06(uint8_t function)
2019-08-19 12:21:54 +01:00
{
bool result = false;
if (FUNC_DISPLAY_INIT_DRIVER == function) {
EpdInitDriver42();
}
2021-06-11 17:14:12 +01:00
else if (epd42_init_done && (XDSP_06 == Settings->display_model)) {
switch (function) {
case FUNC_DISPLAY_MODEL:
result = true;
break;
2019-08-19 12:21:54 +01:00
#ifdef USE_DISPLAY_MODES1TO5
case FUNC_DISPLAY_EVERY_SECOND:
EpdRefresh42();
break;
2019-08-19 12:21:54 +01:00
#endif // USE_DISPLAY_MODES1TO5
}
}
2019-08-19 12:21:54 +01:00
return result;
}
#endif // USE_DISPLAY_EPAPER42
#endif // USE_DISPLAY
#endif // USE_SPI