diff --git a/tasmota/xdrv_10_scripter.ino b/tasmota/xdrv_10_scripter.ino
index 7731237bd..5e920afba 100755
--- a/tasmota/xdrv_10_scripter.ino
+++ b/tasmota/xdrv_10_scripter.ino
@@ -65,7 +65,9 @@ keywords if then else endif, or, and are better readable for beginners (others m
#define SCRIPT_MAXPERM (PMEM_SIZE)-4/sizeof(float)
#define MAX_SCRIPT_SIZE MAX_RULE_SIZE*MAX_RULE_SETS
+#ifndef MAX_SARRAY_NUM
#define MAX_SARRAY_NUM 32
+#endif
uint32_t EncodeLightId(uint8_t relay_id);
uint32_t DecodeLightId(uint32_t hue_id);
@@ -1413,38 +1415,42 @@ uint32_t match_vars(char *dvnam, float **fp, char **sp, uint32_t *ind) {
}
#endif //USE_SCRIPT_GLOBVARS
+#ifndef SCRIPT_IS_STRING_MAXSIZE
+#define SCRIPT_IS_STRING_MAXSIZE 256
+#endif
+
char *isargs(char *lp, uint32_t isind) {
float fvar;
lp = GetNumericArgument(lp, OPER_EQU, &fvar, 0);
SCRIPT_SKIP_SPACES
- if (*lp!='"') {
+ if (*lp != '"') {
return lp;
}
lp++;
- if (glob_script_mem.si_num[isind]>0 && glob_script_mem.last_index_string[isind]) {
+ if (glob_script_mem.si_num[isind] > 0 && glob_script_mem.last_index_string[isind]) {
free(glob_script_mem.last_index_string[isind]);
}
char *sstart = lp;
uint8_t slen = 0;
- for (uint32_t cnt = 0; cnt<256; cnt++) {
- if (*lp=='\n' || *lp=='"' || *lp==0) {
+ for (uint32_t cnt = 0; cnt < SCRIPT_IS_STRING_MAXSIZE; cnt++) {
+ if (*lp == '\n' || *lp == '"' || *lp == 0) {
lp++;
- if (cnt>0 && !slen) {
+ if (cnt > 0 && !slen) {
slen++;
}
glob_script_mem.siro_num[isind] = slen;
break;
}
- if (*lp=='|') {
+ if (*lp == '|') {
slen++;
}
lp++;
}
glob_script_mem.si_num[isind] = fvar;
- if (glob_script_mem.si_num[isind]>0) {
- if (glob_script_mem.si_num[isind]>MAX_SARRAY_NUM) {
+ if (glob_script_mem.si_num[isind] > 0) {
+ if (glob_script_mem.si_num[isind] > MAX_SARRAY_NUM) {
glob_script_mem.si_num[isind] = MAX_SARRAY_NUM;
}
@@ -1468,17 +1474,17 @@ float fvar;
char str[SCRIPT_MAXSSIZE];
str[0] = 0;
uint8_t index = fvar;
- if (index<1) index = 1;
+ if (index < 1) index = 1;
index--;
if (gv) gv->strind = index;
glob_script_mem.sind_num = isind;
if (glob_script_mem.last_index_string[isind]) {
if (!glob_script_mem.si_num[isind]) {
- if (index<=glob_script_mem.siro_num[isind]) {
+ if (index <= glob_script_mem.siro_num[isind]) {
GetTextIndexed(str, sizeof(str), index , glob_script_mem.last_index_string[isind]);
}
} else {
- if (index>glob_script_mem.si_num[isind]) {
+ if (index > glob_script_mem.si_num[isind]) {
index = glob_script_mem.si_num[isind];
}
strlcpy(str,glob_script_mem.last_index_string[isind] + (index * glob_script_mem.max_ssize), glob_script_mem.max_ssize);
@@ -1866,6 +1872,15 @@ chknext:
}
#endif //USE_SCRIPT_TASK
#endif //ESP32
+#ifdef USE_ANGLE_FUNC
+ if (!strncmp(vname, "cos(", 4)) {
+ lp = GetNumericArgument(lp + 4, OPER_EQU, &fvar, gv);
+ fvar = cosf(fvar);
+ lp++;
+ len = 0;
+ goto exit;
+ }
+#endif
break;
case 'd':
if (!strncmp(vname, "day", 3)) {
@@ -2196,6 +2211,22 @@ chknext:
len = 0;
goto exit;
}
+ if (!strncmp(vname, "fmt(", 4)) {
+ lp = GetNumericArgument(lp + 4, OPER_EQU, &fvar, gv);
+ if (!fvar) {
+#ifdef ESP8266
+ LittleFS.format();
+#endif
+#ifdef ESP32
+ LITTLEFS.format();
+#endif
+ } else {
+ //SD.format();
+ }
+ lp++;
+ len = 0;
+ goto exit;
+ }
if (!strncmp(vname, "frd(", 4)) {
char str[glob_script_mem.max_ssize + 1];
lp = GetStringArgument(lp + 4, OPER_EQU, str, 0);
diff --git a/tasmota/xdrv_13_display.ino b/tasmota/xdrv_13_display.ino
index fe599d7a7..1b8a19df9 100755
--- a/tasmota/xdrv_13_display.ino
+++ b/tasmota/xdrv_13_display.ino
@@ -80,6 +80,7 @@ const uint8_t DISPLAY_LOG_ROWS = 32; // Number of lines in display log
#define D_CMND_DISP_CLOCK "Clock"
#define D_CMND_DISP_TEXTNC "TextNC" // NC - "No Clear"
#define D_CMND_DISP_SCROLLTEXT "ScrollText"
+#define D_CMND_DISP_REINIT "reinit"
enum XdspFunctions { FUNC_DISPLAY_INIT_DRIVER, FUNC_DISPLAY_INIT, FUNC_DISPLAY_EVERY_50_MSECOND, FUNC_DISPLAY_EVERY_SECOND,
FUNC_DISPLAY_MODEL, FUNC_DISPLAY_MODE, FUNC_DISPLAY_POWER,
@@ -108,7 +109,7 @@ const char kDisplayCommands[] PROGMEM = D_PRFX_DISPLAY "|" // Prefix
#endif
D_CMND_DISP_CLEAR "|" D_CMND_DISP_NUMBER "|" D_CMND_DISP_FLOAT "|" D_CMND_DISP_NUMBERNC "|" D_CMND_DISP_FLOATNC "|"
D_CMND_DISP_RAW "|" D_CMND_DISP_LEVEL "|" D_CMND_DISP_SEVENSEG_TEXT "|" D_CMND_DISP_SEVENSEG_TEXTNC "|"
- D_CMND_DISP_SCROLLDELAY "|" D_CMND_DISP_CLOCK "|" D_CMND_DISP_TEXTNC "|" D_CMND_DISP_SCROLLTEXT
+ D_CMND_DISP_SCROLLDELAY "|" D_CMND_DISP_CLOCK "|" D_CMND_DISP_TEXTNC "|" D_CMND_DISP_SCROLLTEXT "|" D_CMND_DISP_REINIT
;
void (* const DisplayCommand[])(void) PROGMEM = {
@@ -120,7 +121,7 @@ void (* const DisplayCommand[])(void) PROGMEM = {
#endif
&CmndDisplayClear, &CmndDisplayNumber, &CmndDisplayFloat, &CmndDisplayNumberNC, &CmndDisplayFloatNC,
&CmndDisplayRaw, &CmndDisplayLevel, &CmndDisplaySevensegText, &CmndDisplaySevensegTextNC,
- &CmndDisplayScrollDelay, &CmndDisplayClock, &CmndDisplayTextNC, &CmndDisplayScrollText
+ &CmndDisplayScrollDelay, &CmndDisplayClock, &CmndDisplayTextNC, &CmndDisplayScrollText,&DisplayReInitDriver
};
#ifdef USE_GRAPH
@@ -989,7 +990,7 @@ void Display_Text_From_File(const char *file) {
File fp;
if (!ufsp) return;
fp = ufsp->open(file, FS_FILE_READ);
- if (fp >= 0) {
+ if (fp > 0) {
char *savptr = XdrvMailbox.data;
char linebuff[128];
while (fp.available()) {
@@ -1021,7 +1022,7 @@ void Display_Text_From_File(const char *file) {
fp.close();
}
}
-#endif
+#endif // USE_UFILESYS
#ifdef USE_DT_VARS
@@ -2001,6 +2002,11 @@ void CmndDisplayScrollText(void) {
if(result) ResponseCmndChar(XdrvMailbox.data);
}
+void DisplayReInitDriver(void) {
+ XdspCall(FUNC_DISPLAY_INIT_DRIVER);
+ ResponseCmndDone();
+}
+
/*********************************************************************************************\
* Optional drivers
\*********************************************************************************************/
diff --git a/tasmota/xdsp_17_universal.ino b/tasmota/xdsp_17_universal.ino
new file mode 100644
index 000000000..eb4a9dbd8
--- /dev/null
+++ b/tasmota/xdsp_17_universal.ino
@@ -0,0 +1,332 @@
+/*
+ xdsp_17_universal.ino - universal display driver support for Tasmota
+
+ Copyright (C) 2021 Gerhard Mutz and Theo Arends
+
+ 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 .
+*/
+
+
+#ifdef USE_DISPLAY
+#ifdef USE_UNIVERSAL_DISPLAY
+
+#define XDSP_17 17
+
+#include
+
+uDisplay *udisp;
+bool udisp_init_done = false;
+extern uint8_t color_type;
+extern uint16_t fg_color;
+extern uint16_t bg_color;
+
+#ifdef USE_UFILESYS
+extern FS *ufsp;
+#endif
+
+#define DISPDESC_SIZE 1000
+
+#define DSP_ROM_DESC
+
+/*********************************************************************************************/
+#ifdef DSP_ROM_DESC
+/* sample descriptor */
+const char DSP_SAMPLE_DESC[] PROGMEM =
+// name,xs,ys,bpp,interface, (HEX) address, scl,sda,reset
+// '*' means take pin number from tasmota
+":H\n"
+"SH1106,128,64,1,I2C,3c,*,*,*\n"
+// splash settings, font, size, fgcol, bgcol, x,y
+":S\n"
+"0,1,1,0,40,20\n"
+// init register settings, must be in HEX
+":I\n"
+"AE\n"
+"D5,80\n"
+"A8,3f\n"
+"D3,00\n"
+"40\n"
+"8D,14\n"
+"20,00\n"
+"A1\n"
+"C8\n"
+"DA,12\n"
+"81,CF\n"
+"D9F1\n"
+"DB,40\n"
+"A4\n"
+"A6\n"
+"AF\n"
+// switch display off
+":o\n"
+"AE\n"
+// switch display on
+":O\n"
+"AF\n"
+"#\n";
+
+#endif // DSP_ROM_DESC
+/*********************************************************************************************/
+
+void Init_uDisp(void) {
+char *ddesc = 0;
+char *fbuff;
+
+ if (1) {
+ Settings.display_model = XDSP_17;
+
+ fg_color = 1;
+ bg_color = 0;
+ color_type = COLOR_BW;
+
+ fbuff = (char*)calloc(DISPDESC_SIZE, 1);
+ if (!fbuff) return;
+
+#ifdef USE_UFILESYS
+ if (ufsp && !TasmotaGlobal.no_autoexec) {
+ File fp;
+ fp = ufsp->open("/dispdesc.txt", "r");
+ if (fp > 0) {
+ uint32_t size = fp.size();
+ fp.read((uint8_t*)fbuff, size);
+ fp.close();
+ ddesc = fbuff;
+ AddLog(LOG_LEVEL_INFO, PSTR("DSP: File descriptor used"));
+ }
+ }
+#endif
+
+
+#ifdef USE_SCRIPT
+ if (bitRead(Settings.rule_enabled, 0) && !ddesc) {
+ uint8_t dfound = Run_Scripter(">d",-2,0);
+ if (dfound == 99) {
+ char *lp = glob_script_mem.section_ptr + 2;
+ while (*lp != '\n') lp++;
+ memcpy(fbuff, lp + 1, DISPDESC_SIZE - 1);
+ ddesc = fbuff;
+ AddLog(LOG_LEVEL_INFO, PSTR("DSP: Script descriptor used"));
+ }
+ }
+#endif // USE_SCRIPT
+
+
+#ifdef DSP_ROM_DESC
+ if (!ddesc) {
+ memcpy_P(fbuff, DSP_SAMPLE_DESC, sizeof(DSP_SAMPLE_DESC));
+ ddesc = fbuff;
+ AddLog(LOG_LEVEL_INFO, PSTR("DSP: Flash descriptor used"));
+ }
+#endif // DSP_ROM_DESC
+
+ if (!ddesc) {
+ AddLog(LOG_LEVEL_INFO, PSTR("DSP: No valid descriptor found"));
+ if (fbuff) free(fbuff);
+ return;
+ }
+ // now replace tasmota vars before passing to driver
+ char *cp = strstr(ddesc, "I2C");
+ if (cp) {
+ cp += 4;
+ //,3c,22,21,-1
+ // i2c addr
+ //if (*cp == '*') {
+ // Settings.display_address
+ //}
+ uint8_t i2caddr = strtol(cp, 0, 16);
+ if (I2cSetDevice(i2caddr)) {
+ I2cSetActiveFound(i2caddr, "DSP-I2C");
+ }
+ cp+=3;
+ //replacepin(&cp, Settings.display_address);
+ replacepin(&cp, Pin(GPIO_I2C_SCL));
+ replacepin(&cp, Pin(GPIO_I2C_SDA));
+ replacepin(&cp, Pin(GPIO_OLED_RESET));
+ }
+
+ cp = strstr(ddesc, "SPI");
+ if (cp) {
+ cp += 4;
+ //; 7 params nr,cs,sclk,mosi,dc,bl,reset,miso
+ //SPI,*,*,*,*,*,*,*
+ if (*cp == '1') {
+ cp+=2;
+ replacepin(&cp, Pin(GPIO_SPI_CS));
+ replacepin(&cp, Pin(GPIO_SPI_CLK));
+ replacepin(&cp, Pin(GPIO_SPI_MOSI));
+ replacepin(&cp, Pin(GPIO_SPI_DC));
+ replacepin(&cp, Pin(GPIO_BACKLIGHT));
+ replacepin(&cp, Pin(GPIO_OLED_RESET));
+ replacepin(&cp, Pin(GPIO_SPI_MISO));
+ } else {
+ // soft spi pins
+ cp+=2;
+ replacepin(&cp, Pin(GPIO_SSPI_CS));
+ replacepin(&cp, Pin(GPIO_SSPI_SCLK));
+ replacepin(&cp, Pin(GPIO_SSPI_MOSI));
+ replacepin(&cp, Pin(GPIO_SSPI_DC));
+ replacepin(&cp, Pin(GPIO_BACKLIGHT));
+ replacepin(&cp, Pin(GPIO_OLED_RESET));
+ replacepin(&cp, Pin(GPIO_SSPI_MISO));
+ }
+ }
+
+ // init renderer
+ if (udisp) delete udisp;
+ udisp = new uDisplay(ddesc);
+
+/*
+ File fp;
+ fp = ufsp->open("/dump.txt", "w");
+ fp.write(ddesc, DISPDESC_SIZE);
+ fp.close();
+*/
+ // release desc buffer
+ if (fbuff) free(fbuff);
+
+ renderer = udisp->Init();
+ if (!renderer) return;
+
+ Settings.display_width = renderer->width();
+ Settings.display_height = renderer->height();
+ fg_color = udisp->fgcol();
+ bg_color = udisp->bgcol();
+
+ renderer->DisplayInit(DISPLAY_INIT_MODE, Settings.display_size, Settings.display_rotate, Settings.display_font);
+
+
+#ifdef SHOW_SPLASH
+ udisp->Splash();
+#endif
+
+ udisp_init_done = true;
+ AddLog(LOG_LEVEL_INFO, PSTR("DSP: %s!"), udisp->devname());
+ }
+}
+
+
+/*********************************************************************************************/
+
+void replacepin(char **cp, uint16_t pin) {
+ char *lp = *cp;
+ if (*lp == ',') lp++;
+ if (*lp == '*') {
+ char val[8];
+ itoa(pin, val, 10);
+ uint16_t slen = strlen(val);
+ //AddLog(LOG_LEVEL_INFO, PSTR("replace pin: %d"), pin);
+ memmove(lp + slen, lp + 1, strlen(lp));
+ memmove(lp, val, slen);
+ }
+ char *np = strchr(lp, ',');
+ if (np) {
+ *cp = np + 1;
+ }
+}
+
+#ifdef USE_DISPLAY_MODES1TO5
+
+void UDISP_PrintLog(void)
+{
+ disp_refresh--;
+ if (!disp_refresh) {
+ disp_refresh = Settings.display_refresh;
+ if (!disp_screen_buffer_cols) { DisplayAllocScreenBuffer(); }
+
+ char* txt = DisplayLogBuffer('\370');
+ if (txt != NULL) {
+ uint8_t last_row = Settings.display_rows -1;
+
+ renderer->clearDisplay();
+ renderer->setTextSize(Settings.display_size);
+ renderer->setCursor(0,0);
+ for (byte i = 0; i < last_row; i++) {
+ strlcpy(disp_screen_buffer[i], disp_screen_buffer[i +1], disp_screen_buffer_cols);
+ renderer->println(disp_screen_buffer[i]);
+ }
+ strlcpy(disp_screen_buffer[last_row], txt, disp_screen_buffer_cols);
+ DisplayFillScreen(last_row);
+
+ AddLog(LOG_LEVEL_DEBUG, PSTR(D_LOG_DEBUG "[%s]"), disp_screen_buffer[last_row]);
+
+ renderer->println(disp_screen_buffer[last_row]);
+ renderer->Updateframe();
+ }
+ }
+}
+
+void UDISP_Time(void)
+{
+ char line[12];
+
+ renderer->clearDisplay();
+ renderer->setTextSize(Settings.display_size);
+ renderer->setTextFont(Settings.display_font);
+ renderer->setCursor(0, 0);
+ snprintf_P(line, sizeof(line), PSTR(" %02d" D_HOUR_MINUTE_SEPARATOR "%02d" D_MINUTE_SECOND_SEPARATOR "%02d"), RtcTime.hour, RtcTime.minute, RtcTime.second); // [ 12:34:56 ]
+ renderer->println(line);
+ renderer->println();
+ snprintf_P(line, sizeof(line), PSTR("%02d" D_MONTH_DAY_SEPARATOR "%02d" D_YEAR_MONTH_SEPARATOR "%04d"), RtcTime.day_of_month, RtcTime.month, RtcTime.year); // [01-02-2018]
+ renderer->println(line);
+ renderer->Updateframe();
+}
+
+void UDISP_Refresh(void) // Every second
+{
+ if (!renderer) return;
+ if (Settings.display_mode) { // Mode 0 is User text
+ switch (Settings.display_mode) {
+ case 1: // Time
+ UDISP_Time();
+ break;
+ case 2: // Local
+ case 3: // Local
+ case 4: // Mqtt
+ case 5: // Mqtt
+ UDISP_PrintLog();
+ break;
+ }
+ }
+}
+
+#endif // USE_DISPLAY_MODES1TO5
+
+/*********************************************************************************************\
+ * Interface
+\*********************************************************************************************/
+
+bool Xdsp17(uint8_t function)
+{
+ bool result = false;
+
+ if (FUNC_DISPLAY_INIT_DRIVER == function) {
+ Init_uDisp();
+ }
+ else if (udisp_init_done && (XDSP_17 == Settings.display_model)) {
+ switch (function) {
+ case FUNC_DISPLAY_MODEL:
+ result = true;
+ break;
+#ifdef USE_DISPLAY_MODES1TO5
+ case FUNC_DISPLAY_EVERY_SECOND:
+ UDISP_Refresh();
+ break;
+#endif // USE_DISPLAY_MODES1TO5
+ }
+ }
+ return result;
+}
+
+#endif // USE_UNIVERSAL_DISPLAY
+#endif // USE_DISPLAY