From 4496981b3b9eba17231eb0c83052f745f6e21d89 Mon Sep 17 00:00:00 2001 From: you69man Date: Sat, 6 Jan 2024 20:39:17 +0100 Subject: [PATCH] add option for show ratio --- src/config/settings.h | 4 ++++ src/plugins/Display/Display.h | 8 ++++--- src/plugins/Display/Display_Mono.h | 27 ++++++++++++++++------- src/plugins/Display/Display_Mono_128X32.h | 3 ++- src/plugins/Display/Display_Mono_128X64.h | 3 ++- src/plugins/Display/Display_Mono_64X48.h | 3 ++- src/plugins/Display/Display_Mono_84X48.h | 3 ++- src/web/RestApi.h | 25 +++++++++++---------- src/web/html/setup.html | 11 +++++++++ src/web/web.h | 1 + 10 files changed, 61 insertions(+), 27 deletions(-) diff --git a/src/config/settings.h b/src/config/settings.h index 8ce71167..83e2eaa3 100644 --- a/src/config/settings.h +++ b/src/config/settings.h @@ -165,6 +165,7 @@ typedef struct { uint8_t type; bool pwrSaveAtIvOffline; uint8_t screenSaver; + uint8_t graph_ratio; uint8_t rot; //uint16_t wakeUp; //uint16_t sleepAt; @@ -461,6 +462,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.rot = 0; mCfg.plugin.display.disp_data = DEF_PIN_OFF; // SDA mCfg.plugin.display.disp_clk = DEF_PIN_OFF; // SCL @@ -697,6 +699,7 @@ class settings { disp[F("type")] = mCfg.plugin.display.type; disp[F("pwrSafe")] = (bool)mCfg.plugin.display.pwrSaveAtIvOffline; disp[F("screenSaver")] = mCfg.plugin.display.screenSaver; + disp[F("graph_ratio")] = mCfg.plugin.display.graph_ratio; disp[F("rotation")] = mCfg.plugin.display.rot; //disp[F("wake")] = mCfg.plugin.display.wakeUp; //disp[F("sleep")] = mCfg.plugin.display.sleepAt; @@ -713,6 +716,7 @@ class settings { getVal(disp, F("type"), &mCfg.plugin.display.type); getVal(disp, F("pwrSafe"), &mCfg.plugin.display.pwrSaveAtIvOffline); getVal(disp, F("screenSaver"), &mCfg.plugin.display.screenSaver); + getVal(disp, F("graph_ratio"), &mCfg.plugin.display.graph_ratio); getVal(disp, F("rotation"), &mCfg.plugin.display.rot); //mCfg.plugin.display.wakeUp = disp[F("wake")]; //mCfg.plugin.display.sleepAt = disp[F("sleep")]; diff --git a/src/plugins/Display/Display.h b/src/plugins/Display/Display.h index 387a6a0d..0b06cc58 100644 --- a/src/plugins/Display/Display.h +++ b/src/plugins/Display/Display.h @@ -54,7 +54,7 @@ class Display { default: mMono = NULL; break; } if(mMono) { - mMono->config(mCfg->pwrSaveAtIvOffline, mCfg->screenSaver, mCfg->contrast); + mMono->config(mCfg->pwrSaveAtIvOffline, mCfg->screenSaver, mCfg->contrast, mCfg->graph_ratio); mMono->init(mCfg->type, mCfg->rot, mCfg->disp_cs, mCfg->disp_dc, 0xff, mCfg->disp_clk, mCfg->disp_data, &mDisplayData); } @@ -75,10 +75,12 @@ class Display { } void tickerSecond() { + bool request_refresh = false; + if (mMono != NULL) - mMono->loop(mCfg->contrast, motionSensorActive()); + request_refresh = mMono->loop(mCfg->contrast, motionSensorActive()); - if (mNewPayload || (((++mLoopCnt) % 5) == 0)) { + if (mNewPayload || (((++mLoopCnt) % 5) == 0) || request_refresh) { DataScreen(); mNewPayload = false; mLoopCnt = 0; diff --git a/src/plugins/Display/Display_Mono.h b/src/plugins/Display/Display_Mono.h index 1d925849..76447ce3 100644 --- a/src/plugins/Display/Display_Mono.h +++ b/src/plugins/Display/Display_Mono.h @@ -26,12 +26,12 @@ class DisplayMono { 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) = 0; + virtual void config(bool enPowerSave, uint8_t screenSaver, uint8_t lum, uint8_t graph_ratio) = 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 void loop(uint8_t lum, bool motion) { + virtual bool loop(uint8_t lum, bool motion) { bool dispConditions = (!mEnPowerSave || (mDisplayData->nrProducing > 0)) && ((mScreenSaver != 2) || motion); // screensaver 2 .. motionsensor @@ -61,7 +61,7 @@ class DisplayMono { mDisplay->setContrast(mLuminance); } - monoMaintainDispSwitchState(); + return(monoMaintainDispSwitchState()); } protected: @@ -84,6 +84,7 @@ class DisplayMono { bool mEnPowerSave; uint8_t mScreenSaver = 1; // 0 .. off; 1 .. pixelShift; 2 .. motionsensor uint8_t mLuminance; + uint8_t mGraphRatio; uint8_t mLoopCnt; uint8_t mLineXOffsets[5] = {}; @@ -92,8 +93,8 @@ class DisplayMono { uint8_t mExtra; int8_t mPixelshift=0; TimeMonitor mDisplayTime = TimeMonitor(1000 * DISP_DEFAULT_TIMEOUT, true); - TimeMonitor mDispSwitchTime = TimeMonitor(10000, true); - uint8_t mDispSwitchState = 0; + TimeMonitor mDispSwitchTime = TimeMonitor(); + uint8_t mDispSwitchState; bool mDisplayActive = true; // always start with display on char mFmtText[DISP_FMT_TEXT_LEN]; @@ -113,23 +114,33 @@ class DisplayMono { mDisplay->clearBuffer(); mDispWidth = mDisplay->getDisplayWidth(); mDispHeight = mDisplay->getDisplayHeight(); + mDispSwitchTime.stopTimeMonitor(); + mDispSwitchState = d_POWER_TEXT; + if (mGraphRatio == 100) // if graph ratio is 100% start in graph mode + mDispSwitchState = d_POWER_GRAPH; + else if (mGraphRatio != 0) + mDispSwitchTime.startTimeMonitor(150 * (100 - mGraphRatio)); // start time monitor only if ratio is neither 0 nor 100 } - void monoMaintainDispSwitchState(void) { + bool monoMaintainDispSwitchState(void) { + bool change = false; switch(mDispSwitchState) { case d_POWER_TEXT: if (mDispSwitchTime.isTimeout()) { mDispSwitchState = d_POWER_GRAPH; - mDispSwitchTime.startTimeMonitor(5000); + mDispSwitchTime.startTimeMonitor(150 * mGraphRatio); // mGraphRatio: 0-100 Gesamtperiode 15000 ms + change = true; } break; case d_POWER_GRAPH: if (mDispSwitchTime.isTimeout()) { mDispSwitchState = d_POWER_TEXT; - mDispSwitchTime.startTimeMonitor(10000); + mDispSwitchTime.startTimeMonitor(150 * (100 - mGraphRatio)); + change = true; } break; } + return change; } void initPowerGraph(uint8_t width, uint8_t height) { diff --git a/src/plugins/Display/Display_Mono_128X32.h b/src/plugins/Display/Display_Mono_128X32.h index fa0cacdf..edc79b75 100644 --- a/src/plugins/Display/Display_Mono_128X32.h +++ b/src/plugins/Display/Display_Mono_128X32.h @@ -12,10 +12,11 @@ class DisplayMono128X32 : public DisplayMono { mExtra = 0; } - void config(bool enPowerSave, uint8_t screenSaver, uint8_t lum) { + void config(bool enPowerSave, uint8_t screenSaver, uint8_t lum, uint8_t graph_ratio) { mEnPowerSave = enPowerSave; mScreenSaver = screenSaver; mLuminance = lum; + mGraphRatio = graph_ratio; } 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) { diff --git a/src/plugins/Display/Display_Mono_128X64.h b/src/plugins/Display/Display_Mono_128X64.h index 8f762dde..c578f9a4 100644 --- a/src/plugins/Display/Display_Mono_128X64.h +++ b/src/plugins/Display/Display_Mono_128X64.h @@ -12,10 +12,11 @@ class DisplayMono128X64 : public DisplayMono { mExtra = 0; } - void config(bool enPowerSave, uint8_t screenSaver, uint8_t lum) { + void config(bool enPowerSave, uint8_t screenSaver, uint8_t lum, uint8_t graph_ratio) { mEnPowerSave = enPowerSave; mScreenSaver = screenSaver; mLuminance = lum; + mGraphRatio = graph_ratio; } 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) { diff --git a/src/plugins/Display/Display_Mono_64X48.h b/src/plugins/Display/Display_Mono_64X48.h index 68cac96f..5d1bf6ac 100644 --- a/src/plugins/Display/Display_Mono_64X48.h +++ b/src/plugins/Display/Display_Mono_64X48.h @@ -12,10 +12,11 @@ class DisplayMono64X48 : public DisplayMono { mExtra = 0; } - void config(bool enPowerSave, uint8_t screenSaver, uint8_t lum) { + void config(bool enPowerSave, uint8_t screenSaver, uint8_t lum, uint8_t graph_ratio) { mEnPowerSave = enPowerSave; mScreenSaver = screenSaver; mLuminance = lum; + mGraphRatio = graph_ratio; } 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) { diff --git a/src/plugins/Display/Display_Mono_84X48.h b/src/plugins/Display/Display_Mono_84X48.h index 7f0281ed..a996f52d 100644 --- a/src/plugins/Display/Display_Mono_84X48.h +++ b/src/plugins/Display/Display_Mono_84X48.h @@ -12,10 +12,11 @@ class DisplayMono84X48 : public DisplayMono { mExtra = 0; } - void config(bool enPowerSave, uint8_t screenSaver, uint8_t lum) { + void config(bool enPowerSave, uint8_t screenSaver, uint8_t lum, uint8_t graph_ratio) { mEnPowerSave = enPowerSave; mScreenSaver = screenSaver; mLuminance = lum; + mGraphRatio = graph_ratio; } 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) { diff --git a/src/web/RestApi.h b/src/web/RestApi.h index de4fe8e3..7ef4349b 100644 --- a/src/web/RestApi.h +++ b/src/web/RestApi.h @@ -671,18 +671,19 @@ class RestApi { } void getDisplay(JsonObject obj) { - obj[F("disp_typ")] = (uint8_t)mConfig->plugin.display.type; - obj[F("disp_pwr")] = (bool)mConfig->plugin.display.pwrSaveAtIvOffline; - obj[F("disp_screensaver")] = (uint8_t)mConfig->plugin.display.screenSaver; - obj[F("disp_rot")] = (uint8_t)mConfig->plugin.display.rot; - obj[F("disp_cont")] = (uint8_t)mConfig->plugin.display.contrast; - obj[F("disp_clk")] = (mConfig->plugin.display.type == 0) ? DEF_PIN_OFF : mConfig->plugin.display.disp_clk; - obj[F("disp_data")] = (mConfig->plugin.display.type == 0) ? DEF_PIN_OFF : mConfig->plugin.display.disp_data; - obj[F("disp_cs")] = (mConfig->plugin.display.type < 3) ? DEF_PIN_OFF : mConfig->plugin.display.disp_cs; - obj[F("disp_dc")] = (mConfig->plugin.display.type < 3) ? DEF_PIN_OFF : mConfig->plugin.display.disp_dc; - obj[F("disp_rst")] = (mConfig->plugin.display.type < 3) ? DEF_PIN_OFF : mConfig->plugin.display.disp_reset; - obj[F("disp_bsy")] = (mConfig->plugin.display.type < 10) ? DEF_PIN_OFF : mConfig->plugin.display.disp_busy; - obj[F("pir_pin")] = mConfig->plugin.display.pirPin; + obj[F("disp_typ")] = (uint8_t)mConfig->plugin.display.type; + obj[F("disp_pwr")] = (bool)mConfig->plugin.display.pwrSaveAtIvOffline; + obj[F("disp_screensaver")] = (uint8_t)mConfig->plugin.display.screenSaver; + obj[F("disp_rot")] = (uint8_t)mConfig->plugin.display.rot; + obj[F("disp_cont")] = (uint8_t)mConfig->plugin.display.contrast; + obj[F("disp_graph_ratio")] = (uint8_t)mConfig->plugin.display.graph_ratio; + obj[F("disp_clk")] = (mConfig->plugin.display.type == 0) ? DEF_PIN_OFF : mConfig->plugin.display.disp_clk; + obj[F("disp_data")] = (mConfig->plugin.display.type == 0) ? DEF_PIN_OFF : mConfig->plugin.display.disp_data; + obj[F("disp_cs")] = (mConfig->plugin.display.type < 3) ? DEF_PIN_OFF : mConfig->plugin.display.disp_cs; + obj[F("disp_dc")] = (mConfig->plugin.display.type < 3) ? DEF_PIN_OFF : mConfig->plugin.display.disp_dc; + obj[F("disp_rst")] = (mConfig->plugin.display.type < 3) ? DEF_PIN_OFF : mConfig->plugin.display.disp_reset; + obj[F("disp_bsy")] = (mConfig->plugin.display.type < 10) ? DEF_PIN_OFF : mConfig->plugin.display.disp_busy; + obj[F("pir_pin")] = mConfig->plugin.display.pirPin; } void getMqttInfo(JsonObject obj) { diff --git a/src/web/html/setup.html b/src/web/html/setup.html index 4903db16..4759f893 100644 --- a/src/web/html/setup.html +++ b/src/web/html/setup.html @@ -294,6 +294,15 @@

{#DISP_PINOUT}

+

Graph options

+
+
Graph Size
+
+
+
+
Show ratio (0-100 %)
+
+
@@ -1087,6 +1096,8 @@ hideDispPins(pins, parseInt(dtype_sel.value)) }); + document.getElementsByName("disp_graph_ratio")[0].value = obj["disp_graph_ratio"]; + hideDispPins(pins, obj.disp_typ); } diff --git a/src/web/web.h b/src/web/web.h index eae106a9..1b4f5702 100644 --- a/src/web/web.h +++ b/src/web/web.h @@ -584,6 +584,7 @@ class Web { // display mConfig->plugin.display.pwrSaveAtIvOffline = (request->arg("disp_pwr") == "on"); mConfig->plugin.display.screenSaver = request->arg("disp_screensaver").toInt(); + mConfig->plugin.display.graph_ratio = request->arg("disp_graph_ratio").toInt(); mConfig->plugin.display.rot = request->arg("disp_rot").toInt(); mConfig->plugin.display.type = request->arg("disp_typ").toInt(); mConfig->plugin.display.contrast = (mConfig->plugin.display.type == 0) ? 60 : request->arg("disp_cont").toInt();