Browse Source

add option for show ratio

pull/1330/head
you69man 1 year ago
parent
commit
4496981b3b
  1. 4
      src/config/settings.h
  2. 8
      src/plugins/Display/Display.h
  3. 27
      src/plugins/Display/Display_Mono.h
  4. 3
      src/plugins/Display/Display_Mono_128X32.h
  5. 3
      src/plugins/Display/Display_Mono_128X64.h
  6. 3
      src/plugins/Display/Display_Mono_64X48.h
  7. 3
      src/plugins/Display/Display_Mono_84X48.h
  8. 25
      src/web/RestApi.h
  9. 11
      src/web/html/setup.html
  10. 1
      src/web/web.h

4
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<uint8_t>(disp, F("type"), &mCfg.plugin.display.type);
getVal<bool>(disp, F("pwrSafe"), &mCfg.plugin.display.pwrSaveAtIvOffline);
getVal<uint8_t>(disp, F("screenSaver"), &mCfg.plugin.display.screenSaver);
getVal<uint8_t>(disp, F("graph_ratio"), &mCfg.plugin.display.graph_ratio);
getVal<uint8_t>(disp, F("rotation"), &mCfg.plugin.display.rot);
//mCfg.plugin.display.wakeUp = disp[F("wake")];
//mCfg.plugin.display.sleepAt = disp[F("sleep")];

8
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;

27
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) {

3
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) {

3
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) {

3
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) {

3
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) {

25
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) {

11
src/web/html/setup.html

@ -294,6 +294,15 @@
<p class="des">{#DISP_PINOUT}</p>
<div id="dispPins"></div>
<div id="pirPin"></div>
<p class="des">Graph options</p>
<div class="row mb-3">
<div class="col-12 col-sm-3 my-2">Graph Size</div>
<div class="col-12 col-sm-9"><input type="number" name="graph_size" min="0" max="255"></select></div>
</div>
<div class="row mb-3">
<div class="col-12 col-sm-3 my-2">Show ratio (0-100 %)</div>
<div class="col-12 col-sm-9"><input type="number" name="disp_graph_ratio" min="0" max="100"></select></div>
</div>
</fieldset>
</div>
@ -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);
}

1
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();

Loading…
Cancel
Save