Update display and epaper drivers

Update display and epaper drivers
This commit is contained in:
Theo Arends 2018-11-29 17:50:45 +01:00
parent 4d556d159f
commit 8b5bbd773e
5 changed files with 95 additions and 13 deletions

View File

@ -2,6 +2,7 @@
* Add Command CalcRes to set number of decimals (0 - 7) used in commands ADD, SUB, MULT and SCALE (#4420)
* Add support for SM Smart Wifi Dimmer PS-16-DZ (#4465)
* Move some static (serial) buffers to dynamic buffers
* Update display and epaper drivers
*
* 6.3.0.13 20181126
* Add command SetOption59 0/1 to change state topic from tele/STATE to stat/RESULT (#4450)

View File

@ -340,7 +340,7 @@
#define USE_DISPLAY // Add SPI Display support for 320x240 and 480x320 TFT
#endif
#define USE_DISPLAY_ILI9341 // [DisplayModel 4] Enable ILI9341 Tft 480x320 display (+19k code)
// #define USE_DISPLAY_EPAPER // [DisplayModel 5] Enable e-paper display (+19k code)
// #define USE_DISPLAY_EPAPER_29 // [DisplayModel 5] Enable e-paper 2.9 inch display (+19k code)
#endif // USE_SPI
// -- Serial sensors ------------------------------

View File

@ -156,7 +156,7 @@ void GetFeatures(void)
#ifdef USE_DISPLAY_ILI9341
feature_drv2 |= 0x00000400; // xdsp_04_ili9341.ino
#endif
#ifdef USE_DISPLAY_EPAPER
#ifdef USE_DISPLAY_EPAPER_29
feature_drv2 |= 0x00000800; // xdsp_05_epaper.ino
#endif
#ifdef USE_DISPLAY_SH1106

View File

@ -23,7 +23,7 @@
#define XDRV_13 13
#define DISPLAY_MAX_DRIVERS 16 // Max number of display drivers/models supported by xdsp_interface.ino
#define DISPLAY_MAX_COLS 40 // Max number of columns allowed with command DisplayCols
#define DISPLAY_MAX_COLS 44 // Max number of columns allowed with command DisplayCols
#define DISPLAY_MAX_ROWS 32 // Max number of lines allowed with command DisplayRows
#define DISPLAY_LOG_ROWS 32 // Number of lines in display log buffer
@ -1066,7 +1066,7 @@ boolean Xdrv13(byte function)
{
boolean result = false;
if ((i2c_flg || spi_flg) && XdspPresent()) {
if ((i2c_flg || spi_flg || soft_spi_flg) && XdspPresent()) {
switch (function) {
case FUNC_PRE_INIT:
DisplayInitDriver();

View File

@ -1,5 +1,5 @@
/*
xdsp_05_epaper.ino - Display e-paper support for Sonoff-Tasmota
xdsp_05_epaper_29.ino - 2.9 Inch display e-paper support for Sonoff-Tasmota
Copyright (C) 2018 Theo Arends, Gerhard Mutz and Waveshare
@ -23,6 +23,9 @@
#define XDSP_05 5
#define EPD_TOP 12
#define EPD_FONT_HEIGTH 12
#define COLORED 0
#define UNCOLORED 1
@ -39,6 +42,8 @@ Paint paint(image, EPD_WIDTH, EPD_HEIGHT); // width should be the multiple of
Epd epd;
sFONT *selected_font;
uint16_t epd_scroll;
/*********************************************************************************************/
void EpdInitMode(void)
@ -70,6 +75,8 @@ void EpdInitMode(void)
delay(1000);
*/
paint.Clear(UNCOLORED);
epd_scroll = EPD_TOP;
}
void EpdInitPartial(void)
@ -111,11 +118,18 @@ void EpdInitDriver(void)
}
if (XDSP_05 == Settings.display_model) {
epd.cs_pin = pin[GPIO_SPI_CS];
epd.mosi_pin = pin[GPIO_SPI_MOSI]; // 13
epd.sclk_pin = pin[GPIO_SPI_CLK]; // 14
EpdInitMode();
if ((pin[GPIO_SPI_CS] < 99) && (pin[GPIO_SPI_CLK] < 99) && (pin[GPIO_SPI_MOSI] < 99)) {
epd.cs_pin = pin[GPIO_SPI_CS];
epd.sclk_pin = pin[GPIO_SPI_CLK]; // 14
epd.mosi_pin = pin[GPIO_SPI_MOSI]; // 13
EpdInitMode();
}
else if ((pin[GPIO_SSPI_CS] < 99) && (pin[GPIO_SSPI_SCLK] < 99) && (pin[GPIO_SSPI_MOSI] < 99)) {
epd.cs_pin = pin[GPIO_SSPI_CS];
epd.sclk_pin = pin[GPIO_SSPI_SCLK];
epd.mosi_pin = pin[GPIO_SSPI_MOSI];
EpdInitMode();
}
}
}
@ -143,6 +157,12 @@ void EpdSetFont(uint8_t font)
}
}
void EpdDisplayFrame(void)
{
epd.SetFrameMemory(paint.GetImage(), 0, 0, paint.GetWidth(), paint.GetHeight());
epd.DisplayFrame();
}
void EpdDrawStringAt(uint16_t x, uint16_t y, char *str, uint8_t color, uint8_t flag)
{
if (!flag) {
@ -167,10 +187,72 @@ void EpdOnOff(void)
#ifdef USE_DISPLAY_MODES1TO5
void EpdPrintLog(void)
{
disp_refresh--;
if (!disp_refresh) {
disp_refresh = Settings.display_refresh;
if (Settings.display_rotate) {
if (!disp_screen_buffer_cols) { DisplayAllocScreenBuffer(); }
}
char* txt = DisplayLogBuffer('\040');
if (txt != NULL) {
byte size = Settings.display_size;
uint16_t theight = size * EPD_FONT_HEIGTH;
EpdSetFont(size);
uint8_t last_row = Settings.display_rows -1;
// epd_scroll = theight; // Start below header
epd_scroll = 0; // Start at top with no header
for (byte i = 0; i < last_row; i++) {
strlcpy(disp_screen_buffer[i], disp_screen_buffer[i +1], disp_screen_buffer_cols);
EpdDrawStringAt(0, epd_scroll, disp_screen_buffer[i], COLORED, 0);
epd_scroll += theight;
}
strlcpy(disp_screen_buffer[last_row], txt, disp_screen_buffer_cols);
DisplayFillScreen(last_row);
EpdDrawStringAt(0, epd_scroll, disp_screen_buffer[last_row], COLORED, 0);
// EpdDisplayFrame();
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_APPLICATION "[%s]"), txt);
AddLog(LOG_LEVEL_DEBUG);
}
}
}
void EpdRefresh(void) // Every second
{
if (Settings.display_mode) { // Mode 0 is User text
/*
char tftdt[Settings.display_cols[0] +1];
char date4[11]; // 24-04-2017
char space[Settings.display_cols[0] - 17];
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);
*/
switch (Settings.display_mode) {
case 1: // Text
case 2: // Local
case 3: // Local
case 4: // Mqtt
case 5: // Mqtt
EpdPrintLog();
EpdDisplayFrame();
break;
}
// EpdDisplayFrame();
}
}
@ -184,7 +266,7 @@ boolean Xdsp05(byte function)
{
boolean result = false;
if (spi_flg) {
if (spi_flg || soft_spi_flg) {
if (FUNC_DISPLAY_INIT_DRIVER == function) {
EpdInitDriver();
}
@ -227,8 +309,7 @@ boolean Xdsp05(byte function)
paint.DrawFilledRectangle(dsp_x, dsp_y, dsp_x + dsp_x2, dsp_y + dsp_y2, dsp_color);
break;
case FUNC_DISPLAY_DRAW_FRAME:
epd.SetFrameMemory(paint.GetImage(), 0, 0, paint.GetWidth(), paint.GetHeight());
epd.DisplayFrame();
EpdDisplayFrame();
break;
case FUNC_DISPLAY_TEXT_SIZE:
// EpdSetFontorSize(Settings.display_size);