diff --git a/src/config/settings.h b/src/config/settings.h index 24ebb976..b8d0d1e9 100644 --- a/src/config/settings.h +++ b/src/config/settings.h @@ -465,7 +465,7 @@ class settings { mCfg.plugin.display.pwrSaveAtIvOffline = false; mCfg.plugin.display.contrast = 60; mCfg.plugin.display.screenSaver = 1; // default: 1 .. pixelshift for OLED for downward compatibility - mCfg.plugin.display.graph_ratio = 50; + mCfg.plugin.display.graph_ratio = 0; mCfg.plugin.display.graph_size = 2; mCfg.plugin.display.rot = 0; mCfg.plugin.display.disp_data = DEF_PIN_OFF; // SDA diff --git a/src/plugins/Display/Display.h b/src/plugins/Display/Display.h index 6c8bb9cb..0ce49c33 100644 --- a/src/plugins/Display/Display.h +++ b/src/plugins/Display/Display.h @@ -50,12 +50,11 @@ class Display { mEpaper.init(mCfg->type, mCfg->disp_cs, mCfg->disp_dc, mCfg->disp_reset, mCfg->disp_busy, mCfg->disp_clk, mCfg->disp_data, mUtcTs, mDisplayData.version); break; #endif - default: mMono = NULL; break; } if(mMono) { - mMono->config(mCfg->pwrSaveAtIvOffline, mCfg->screenSaver, mCfg->contrast, mCfg->graph_ratio, mCfg->graph_size); - mMono->init(mCfg->type, mCfg->rot, mCfg->disp_cs, mCfg->disp_dc, 0xff, mCfg->disp_clk, mCfg->disp_data, &mDisplayData); + mMono->config(mCfg); + mMono->init(&mDisplayData); } // setup PIR pin for motion sensor @@ -78,7 +77,7 @@ class Display { bool request_refresh = false; if (mMono != NULL) - request_refresh = mMono->loop(mCfg->contrast, motionSensorActive()); + request_refresh = mMono->loop(motionSensorActive()); if (mNewPayload || (((++mLoopCnt) % 5) == 0) || request_refresh) { DataScreen(); diff --git a/src/plugins/Display/Display_Mono.h b/src/plugins/Display/Display_Mono.h index c7235815..785f1334 100644 --- a/src/plugins/Display/Display_Mono.h +++ b/src/plugins/Display/Display_Mono.h @@ -25,23 +25,22 @@ class DisplayMono { public: DisplayMono() {}; - virtual void init(uint8_t type, uint8_t rot, uint8_t cs, uint8_t dc, uint8_t reset, uint8_t clock, uint8_t data, DisplayData *displayData) = 0; - virtual void config(bool enPowerSave, uint8_t screenSaver, uint8_t lum, uint8_t graph_ratio, uint8_t graph_size) = 0; + virtual void init(DisplayData *displayData) = 0; + virtual void config(display_t *cfg) = 0; virtual void disp(void) = 0; // Common loop function, manages display on/off functions for powersave and screensaver with motionsensor // can be overridden by subclasses - virtual bool loop(uint8_t lum, bool motion) { + virtual bool loop(bool motion) { - bool dispConditions = (!mEnPowerSave || (mDisplayData->nrProducing > 0)) && - ((mScreenSaver != 2) || motion); // screensaver 2 .. motionsensor + bool dispConditions = (!mCfg->pwrSaveAtIvOffline || (mDisplayData->nrProducing > 0)) && + ((mCfg->screenSaver != 2) || motion); // screensaver 2 .. motionsensor if (mDisplayActive) { if (!dispConditions) { if (mDisplayTime.isTimeout()) { // switch display off after timeout mDisplayActive = false; mDisplay->setPowerSave(true); - DBGPRINTLN("**** Display off ****"); } } else @@ -52,16 +51,15 @@ class DisplayMono { mDisplayActive = true; mDisplayTime.reStartTimeMonitor(); // switch display on mDisplay->setPowerSave(false); - DBGPRINTLN("**** Display on ****"); } } - if(mLuminance != lum) { - mLuminance = lum; + if(mLuminance != mCfg->contrast) { + mLuminance = mCfg->contrast; mDisplay->setContrast(mLuminance); } - return(monoMaintainDispSwitchState()); + return(monoMaintainDispSwitchState()); // return flag, if display content should be updated immediately } protected: @@ -71,7 +69,8 @@ class DisplayMono { }; protected: - U8G2* mDisplay; + display_t *mCfg; + U8G2 *mDisplay; DisplayData *mDisplayData; float *mPgData = nullptr; @@ -82,17 +81,10 @@ class DisplayMono { uint32_t mPgTimeOfDay = 0; uint8_t mPgLastPos = 0; - uint8_t mType; uint16_t mDispWidth; uint16_t mDispHeight; - - bool mEnPowerSave; - uint8_t mScreenSaver = 1; // 0 .. off; 1 .. pixelShift; 2 .. motionsensor uint8_t mLuminance; - uint8_t mGraphRatio; - uint8_t mGraphSize; - uint8_t mLoopCnt; uint8_t mLineXOffsets[5] = {}; uint8_t mLineYOffsets[5] = {}; @@ -105,9 +97,8 @@ class DisplayMono { char mFmtText[DISP_FMT_TEXT_LEN]; // Common initialization function to be called by subclasses - void monoInit(U8G2* display, uint8_t type, DisplayData *displayData) { + void monoInit(U8G2* display, DisplayData *displayData) { mDisplay = display; - mType = type; mDisplayData = displayData; mDisplay->begin(); mDisplay->setPowerSave(false); // always start with display on @@ -116,10 +107,10 @@ class DisplayMono { mDispWidth = mDisplay->getDisplayWidth(); mDispHeight = mDisplay->getDisplayHeight(); mDispSwitchTime.stopTimeMonitor(); - if (mGraphRatio == 100) // if graph ratio is 100% start in graph mode + if (mCfg->graph_ratio == 100) // if graph ratio is 100% start in graph mode mDispSwitchState = DispSwitchState::GRAPH; - else if (mGraphRatio != 0) - mDispSwitchTime.startTimeMonitor(150 * (100 - mGraphRatio)); // start display mode change only if ratio is neither 0 nor 100 + else if (mCfg->graph_ratio != 0) + mDispSwitchTime.startTimeMonitor(150 * (100 - mCfg->graph_ratio)); // start display mode change only if ratio is neither 0 nor 100 } bool monoMaintainDispSwitchState(void) { @@ -128,14 +119,14 @@ class DisplayMono { case DispSwitchState::TEXT: if (mDispSwitchTime.isTimeout()) { mDispSwitchState = DispSwitchState::GRAPH; - mDispSwitchTime.startTimeMonitor(150 * mGraphRatio); // mGraphRatio: 0-100 Gesamtperiode 15000 ms + mDispSwitchTime.startTimeMonitor(150 * mCfg->graph_ratio); // mGraphRatio: 0-100 Gesamtperiode 15000 ms change = true; } break; case DispSwitchState::GRAPH: if (mDispSwitchTime.isTimeout()) { mDispSwitchState = DispSwitchState::TEXT; - mDispSwitchTime.startTimeMonitor(150 * (100 - mGraphRatio)); + mDispSwitchTime.startTimeMonitor(150 * (100 - mCfg->graph_ratio)); change = true; } break; @@ -147,7 +138,6 @@ class DisplayMono { mPgWidth = width; mPgHeight = height; mPgData = new float[mPgWidth]; - //memset(mPgData, 0, mPgWidth); resetPowerGraph(); /* Inverter<> *iv; @@ -195,7 +185,7 @@ class DisplayMono { } } - uint8_t getPowerGraphXpos(uint8_t p) { // + uint8_t getPowerGraphXpos(uint8_t p) { if ((p <= mPgLastPos) && (mPgLastPos > 0)) return((p * (mPgWidth - 1)) / mPgLastPos); // scaling of x-axis else @@ -255,7 +245,7 @@ class DisplayMono { // pixelshift screensaver with wipe effect void calcPixelShift(int range) { int8_t mod = (millis() / 10000) % ((range >> 1) << 2); - mPixelshift = mScreenSaver == 1 ? ((mod < range) ? mod - (range >> 1) : -(mod - range - (range >> 1) + 1)) : 0; + mPixelshift = mCfg->screenSaver == 1 ? ((mod < range) ? mod - (range >> 1) : -(mod - range - (range >> 1) + 1)) : 0; } }; diff --git a/src/plugins/Display/Display_Mono_128X32.h b/src/plugins/Display/Display_Mono_128X32.h index 1b3927b3..6ab21a6b 100644 --- a/src/plugins/Display/Display_Mono_128X32.h +++ b/src/plugins/Display/Display_Mono_128X32.h @@ -12,17 +12,13 @@ class DisplayMono128X32 : public DisplayMono { mExtra = 0; } - void config(bool enPowerSave, uint8_t screenSaver, uint8_t lum, uint8_t graph_ratio, uint8_t graph_size) { - mEnPowerSave = enPowerSave; - mScreenSaver = screenSaver; - mLuminance = lum; - mGraphRatio = graph_ratio; - mGraphSize = graph_size; + void config(display_t *cfg) { + mCfg = cfg; } - void init(uint8_t type, uint8_t rotation, uint8_t cs, uint8_t dc, uint8_t reset, uint8_t clock, uint8_t data, DisplayData *displayData) { - u8g2_cb_t *rot = (u8g2_cb_t *)((rotation != 0x00) ? U8G2_R2 : U8G2_R0); - monoInit(new U8G2_SSD1306_128X32_UNIVISION_F_HW_I2C(rot, reset, clock, data), type, displayData); + void init(DisplayData *displayData) { + u8g2_cb_t *rot = (u8g2_cb_t *)((mCfg->rot != 0x00) ? U8G2_R2 : U8G2_R0); + monoInit(new U8G2_SSD1306_128X32_UNIVISION_F_HW_I2C(rot, 0xff, mCfg->disp_clk, mCfg->disp_data), displayData); calcLinePositions(); printText("Ahoy!", 0); printText("ahoydtu.de", 2); diff --git a/src/plugins/Display/Display_Mono_128X64.h b/src/plugins/Display/Display_Mono_128X64.h index c8338691..b4c1cfe4 100644 --- a/src/plugins/Display/Display_Mono_128X64.h +++ b/src/plugins/Display/Display_Mono_128X64.h @@ -12,31 +12,27 @@ class DisplayMono128X64 : public DisplayMono { mExtra = 0; } - void config(bool enPowerSave, uint8_t screenSaver, uint8_t lum, uint8_t graph_ratio, uint8_t graph_size) { - mEnPowerSave = enPowerSave; - mScreenSaver = screenSaver; - mLuminance = lum; - mGraphRatio = graph_ratio; - mGraphSize = graph_size; + void config(display_t *cfg) { + mCfg = cfg; } - void init(uint8_t type, uint8_t rotation, uint8_t cs, uint8_t dc, uint8_t reset, uint8_t clock, uint8_t data, DisplayData *displayData) { - u8g2_cb_t *rot = (u8g2_cb_t *)((rotation != 0x00) ? U8G2_R2 : U8G2_R0); - switch (type) { + void init(DisplayData *displayData) { + u8g2_cb_t *rot = (u8g2_cb_t *)(( mCfg->rot != 0x00) ? U8G2_R2 : U8G2_R0); + switch (mCfg->type) { case 1: - monoInit(new U8G2_SSD1306_128X64_NONAME_F_HW_I2C(rot, reset, clock, data), type, displayData); + monoInit(new U8G2_SSD1306_128X64_NONAME_F_HW_I2C(rot, 0xff, mCfg->disp_clk, mCfg->disp_data), displayData); break; case 2: - monoInit(new U8G2_SH1106_128X64_NONAME_F_HW_I2C(rot, reset, clock, data), type, displayData); + monoInit(new U8G2_SH1106_128X64_NONAME_F_HW_I2C(rot, 0xff, mCfg->disp_clk, mCfg->disp_data), displayData); break; case 6: default: - monoInit(new U8G2_SSD1309_128X64_NONAME0_F_HW_I2C(rot, reset, clock, data), type, displayData); + monoInit(new U8G2_SSD1309_128X64_NONAME0_F_HW_I2C(rot, 0xff, mCfg->disp_clk, mCfg->disp_data), displayData); break; } calcLinePositions(); - switch(mGraphSize) { // var opts2 = [[0, "Line 1 - 2"], [1, "Line 2 - 3"], [2, "Line 1 - 3"], [3, "Line 2 - 4"], [4, "Line 1 - 4"]]; + switch(mCfg->graph_size) { // var opts2 = [[0, "Line 1 - 2"], [1, "Line 2 - 3"], [2, "Line 1 - 3"], [3, "Line 2 - 4"], [4, "Line 1 - 4"]]; case 0: graph_first_line = 1; graph_last_line = 2; @@ -60,7 +56,7 @@ class DisplayMono128X64 : public DisplayMono { break; } - widthShrink = (mScreenSaver == 1) ? pixelShiftRange : 0; // shrink graphwidth for pixelshift screensaver + widthShrink = (mCfg->screenSaver == 1) ? pixelShiftRange : 0; // shrink graphwidth for pixelshift screensaver initPowerGraph(mDispWidth - 22 - widthShrink, mLineYOffsets[graph_last_line] - mLineYOffsets[graph_first_line - 1] - 2); diff --git a/src/plugins/Display/Display_Mono_64X48.h b/src/plugins/Display/Display_Mono_64X48.h index e55f5ac3..68aa3cc4 100644 --- a/src/plugins/Display/Display_Mono_64X48.h +++ b/src/plugins/Display/Display_Mono_64X48.h @@ -12,18 +12,14 @@ class DisplayMono64X48 : public DisplayMono { mExtra = 0; } - void config(bool enPowerSave, uint8_t screenSaver, uint8_t lum, uint8_t graph_ratio, uint8_t graph_size) { - mEnPowerSave = enPowerSave; - mScreenSaver = screenSaver; - mLuminance = lum; - mGraphRatio = graph_ratio; - mGraphSize = graph_size; + void config(display_t *cfg) { + mCfg = cfg; } - void init(uint8_t type, uint8_t rotation, uint8_t cs, uint8_t dc, uint8_t reset, uint8_t clock, uint8_t data, DisplayData *displayData) { - u8g2_cb_t *rot = (u8g2_cb_t *)((rotation != 0x00) ? U8G2_R2 : U8G2_R0); + void init(DisplayData *displayData) { + u8g2_cb_t *rot = (u8g2_cb_t *)((mCfg->rot != 0x00) ? U8G2_R2 : U8G2_R0); // Wemos OLed Shield is not defined in u8 lib -> use nearest compatible - monoInit(new U8G2_SSD1306_64X48_ER_F_HW_I2C(rot, reset, clock, data), type, displayData); + monoInit(new U8G2_SSD1306_64X48_ER_F_HW_I2C(rot, 0xff, mCfg->disp_clk, mCfg->disp_data), displayData); calcLinePositions(); printText("Ahoy!", 0); diff --git a/src/plugins/Display/Display_Mono_84X48.h b/src/plugins/Display/Display_Mono_84X48.h index b195e17c..51c5eafe 100644 --- a/src/plugins/Display/Display_Mono_84X48.h +++ b/src/plugins/Display/Display_Mono_84X48.h @@ -12,20 +12,17 @@ class DisplayMono84X48 : public DisplayMono { mExtra = 0; } - void config(bool enPowerSave, uint8_t screenSaver, uint8_t lum, uint8_t graph_ratio, uint8_t graph_size) { - mEnPowerSave = enPowerSave; - mScreenSaver = screenSaver; - mLuminance = lum; - mGraphRatio = graph_ratio; - mGraphSize = graph_size; + void config(display_t *cfg) { + mCfg = cfg; } - void init(uint8_t type, uint8_t rotation, uint8_t cs, uint8_t dc, uint8_t reset, uint8_t clock, uint8_t data, DisplayData *displayData) { - u8g2_cb_t *rot = (u8g2_cb_t *)((rotation != 0x00) ? U8G2_R2 : U8G2_R0); - monoInit(new U8G2_PCD8544_84X48_F_4W_SW_SPI(rot, clock, data, cs, dc, reset), type, displayData); + void init(DisplayData *displayData) { + u8g2_cb_t *rot = (u8g2_cb_t *)((mCfg->rot != 0x00) ? U8G2_R2 : U8G2_R0); + + monoInit(new U8G2_PCD8544_84X48_F_4W_SW_SPI(rot, mCfg->disp_clk, mCfg->disp_data, mCfg->disp_cs, mCfg->disp_dc, 0xff), displayData); calcLinePositions(); - switch(mGraphSize) { // var opts2 = [[0, "Line 1 - 2"], [1, "Line 2 - 3"], [2, "Line 1 - 3"], [3, "Line 2 - 4"], [4, "Line 1 - 4"]]; + switch(mCfg->graph_size) { // var opts2 = [[0, "Line 1 - 2"], [1, "Line 2 - 3"], [2, "Line 1 - 3"], [3, "Line 2 - 4"], [4, "Line 1 - 4"]]; case 0: graph_first_line = 1; graph_last_line = 2; diff --git a/src/web/html/setup.html b/src/web/html/setup.html index da9785ee..00b0477c 100644 --- a/src/web/html/setup.html +++ b/src/web/html/setup.html @@ -287,18 +287,20 @@
-
+
{#DISP_LUMINANCE}

{#DISP_PINOUT}

-

Graph options

-
-
-
Show ratio (0-100 %)
-
+
+

{#GRAPH_OPTIONS}

+
+
+
{#GRAPH_SHOW_RATIO}
+
+
@@ -1095,12 +1097,12 @@ document.getElementsByName("disp_graph_ratio")[0].value = obj["disp_graph_ratio"]; - var opts2 = [[0, "Line 1 - 2"], [1, "Line 2 - 3"], [2, "Line 1 - 3"], [3, "Line 2 - 4"], [4, "Line 1 - 4"]]; + var opts2 = [[0, "{#GRAPH_LINES_1_2}"], [1, "{#GRAPH_LINES_2_3}"], [2, "{#GRAPH_LINES_1_3}"], [3, "{#GRAPH_LINES_2_4}"], [4, "{#GRAPH_LINES_1_4}"]]; var graph_size_sel = sel("disp_graph_size", opts2, obj["disp_graph_size"]); graph_size_sel.id = 'disp_graph_size'; document.getElementById("graphSize").append( ml("div", {class: "row mb-3"}, [ - ml("div", {class: "col-12 col-sm-3 my-2"}, "Graph size"), + ml("div", {class: "col-12 col-sm-3 my-2"}, "{#GRAPH_POSITION}"), ml("div", {class: "col-12 col-sm-9"}, graph_size_sel) ]) ); @@ -1113,14 +1115,14 @@ // It depends on fix pin array (see var pins) // var pins = [['clock', 'disp_clk'], ['data', 'disp_data'], ['cs', 'disp_cs'], ['dc', 'disp_dc'], ['reset', 'disp_rst']]; const pinMap = new Map([ - [0, [0,0,0,0,0,0]], //none - [1, [1,1,0,0,0,0]], //SSD1306_128X64 - [2, [1,1,0,0,0,0]], //SH1106_128X64 - [3, [1,1,1,1,0,0]], //PCD8544_84X48 /nokia5110 - [4, [1,1,0,0,0,0]], //SSD1306_128X32 - [5, [1,1,0,0,0,0]], //SSD1306_128x64 - [6, [1,1,0,0,0,0]], //SSD1309_128x64 - [10, [1,1,1,1,1,1]] //ePaper + [0, [0,0,0,0,0,0]], //none + [1, [1,1,0,0,0,0]], //SSD1306_128X64 + [2, [1,1,0,0,0,0]], //SH1106_128X64 + [3, [1,1,1,1,0,0]], //PCD8544_84X48 /nokia5110 + [4, [1,1,0,0,0,0]], //SSD1306_128X32 + [5, [1,1,0,0,0,0]], //SSD1306_64X48 + [6, [1,1,0,0,0,0]], //SSD1309_128x64 + [10, [1,1,1,1,1,1]] //ePaper ]) for(var i = 0; i < pins.length; i++) { var cl = document.getElementById("row_" + pins[i][1]).classList; @@ -1132,14 +1134,22 @@ } } - var screenSaver = document.getElementById("disp_screensaver").value; + const optionsMap = new Map([ // options: [Graph, Luminance, Screensaver] + [0, [0,0,0]], //none + [1, [1,1,1]], //SSD1306_128X64 + [2, [1,1,1]], //SH1106_128X64 + [3, [1,1,0]], //PCD8544_84X48 /nokia5110 + [4, [0,1,1]], //SSD1306_128X32 + [5, [0,1,1]], //SSD1306_64X48 + [6, [1,1,1]], //SSD1309_128x64 + [10, [0,0,0]] //ePaper + ]) - if (2==screenSaver) { // show pir pin only for motion screensaver - setHide("pirPin", false); - } - else { // no pir pin for all others - setHide("pirPin", true); - } + var screenSaver = document.getElementById("disp_screensaver").value; + setHide("graphOptions", !optionsMap.get(dispType)[0]); + setHide("luminanceOption", !optionsMap.get(dispType)[1]); + setHide("screenSaver", !optionsMap.get(dispType)[2]); + setHide("pirPin", !(optionsMap.get(dispType)[2] && (screenSaver==2))); // show pir pin only for motion screensaver } function tick() { diff --git a/src/web/lang.json b/src/web/lang.json index cb8ab8d6..8868148d 100644 --- a/src/web/lang.json +++ b/src/web/lang.json @@ -316,7 +316,7 @@ { "token": "NTP_SET_SYS_TIME", "en": "set system time", - "de": "Systemzeit setzten" + "de": "Systemzeit setzen" }, { "token": "BTN_FROM_BROWSER", @@ -326,7 +326,7 @@ { "token": "BTN_SYNC_NTP", "en": "sync NTP", - "de": "NTP syncchronisieren" + "de": "NTP synchronisieren" }, { "token": "NTP_SYS_TIME", @@ -381,7 +381,7 @@ { "token": "DISP_OFF_INV", "en": "Turn off while inverters are offline", - "de": "schalte das Display aus, während die Wechselrichter aus sind" + "de": "Schalte das Display aus, während die Wechselrichter aus sind" }, { "token": "DISP_LUMINANCE", @@ -393,6 +393,46 @@ "en": "Pinout", "de": "Anschlusseinstellungen" }, + { + "token": "GRAPH_OPTIONS", + "en": "Graph options", + "de": "Graph Einstellungen" + }, + { + "token": "GRAPH_SHOW_RATIO", + "en": "Graph show ratio (0-100%)", + "de": "Graph Anzeigeverhältnis (0-100%)" + }, + { + "token": "GRAPH_POSITION", + "en": "Graph pos (from/to)", + "de": "Graph Position (von/bis)" + }, + { + "token": "GRAPH_LINES_1_2", + "en": "Line 1-2", + "de": "Zeile 1-2" + }, + { + "token": "GRAPH_LINES_2_3", + "en": "Line 2-3", + "de": "Zeile 2-3" + }, + { + "token": "GRAPH_LINES_1_3", + "en": "Line 1-3", + "de": "Zeile 1-3" + }, + { + "token": "GRAPH_LINES_2_4", + "en": "Line 2-4", + "de": "Zeile 2-4" + }, + { + "token": "GRAPH_LINES_1_4", + "en": "Line 1-4", + "de": "Zeile 1-4" + }, { "token": "BTN_REBOOT_SUCCESSFUL_SAVE", "en": "Reboot device after successful save", @@ -491,7 +531,7 @@ { "token": "NTP_SYNCED_AT", "en": "synced at", - "de": "syncchronisiert um" + "de": "synchronisiert um" }, { "token": "NTP_DIFF", @@ -506,7 +546,7 @@ { "token": "IMPORT_UPLOAD_STARTED", "en": "upload started", - "de": "hochladen gestartet" + "de": "Hochladen gestartet" }, { "token": "INV_EDIT", @@ -696,7 +736,7 @@ { "token": "DISP_SCREENSAVER", "en": "Screensaver (OLED only)", - "de": "Bildschrimschoner (nur OLED)" + "de": "Bildschirmschoner (nur OLED)" }, { "token": "NETWORK_PLEASE_SELECT",