Skip to content

Commit

Permalink
Merge branch 'You69Man-feature/PR_solve_display_setting_dependencies'…
Browse files Browse the repository at this point in the history
… into development03
  • Loading branch information
lumapu committed Jan 18, 2024
2 parents c3a2ad0 + 21234d2 commit b792f69
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 42 deletions.
4 changes: 2 additions & 2 deletions src/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ void app::setup() {
#endif
// Plugins
#if defined(PLUGIN_DISPLAY)
if (mConfig->plugin.display.type != 0)
if (mConfig->plugin.display.type != DISP_TYPE_T0_NONE)
#if defined(ESP32)
mDisplay.setup(this, &mConfig->plugin.display, &mSys, &mNrfRadio, &mCmtRadio, &mTimestamp);
#else
Expand Down Expand Up @@ -186,7 +186,7 @@ void app::regularTickers(void) {
everySec(std::bind(&WebType::tickSecond, &mWeb), "webSc");
// Plugins
#if defined(PLUGIN_DISPLAY)
if (mConfig->plugin.display.type != 0)
if (mConfig->plugin.display.type != DISP_TYPE_T0_NONE)
everySec(std::bind(&DisplayType::tickerSecond, &mDisplay), "disp");
#endif
every(std::bind(&PubSerialType::tick, &mPubSerial), 5, "uart");
Expand Down
2 changes: 1 addition & 1 deletion src/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ class app : public IApp, public ah::Scheduler {
#endif /*ENABLE_MQTT*/
#endif
#if defined(PLUGIN_DISPLAY)
if(mConfig->plugin.display.type != 0)
if(mConfig->plugin.display.type != DISP_TYPE_T0_NONE)
mDisplay.payloadEventListener(cmd);
#endif
updateLed();
Expand Down
4 changes: 2 additions & 2 deletions src/config/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ class settings {
mCfg.led.luminance = 255;

mCfg.plugin.display.pwrSaveAtIvOffline = false;
mCfg.plugin.display.contrast = 60;
mCfg.plugin.display.contrast = 140;
mCfg.plugin.display.screenSaver = 1; // default: 1 .. pixelshift for OLED for downward compatibility
mCfg.plugin.display.graph_ratio = 0;
mCfg.plugin.display.graph_size = 2;
Expand All @@ -476,7 +476,7 @@ class settings {
mCfg.plugin.display.disp_reset = DEF_PIN_OFF;
mCfg.plugin.display.disp_busy = DEF_PIN_OFF;
mCfg.plugin.display.disp_dc = DEF_PIN_OFF;
mCfg.plugin.display.pirPin = DEF_MOTION_SENSOR_PIN;
mCfg.plugin.display.pirPin = DEF_PIN_OFF;
}

void loadAddedDefaults() {
Expand Down
12 changes: 12 additions & 0 deletions src/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,18 @@ union serial_u {

enum {MQTT_STATUS_OFFLINE = 0, MQTT_STATUS_PARTIAL, MQTT_STATUS_ONLINE};

enum {
DISP_TYPE_T0_NONE = 0,
DISP_TYPE_T1_SSD1306_128X64 = 1,
DISP_TYPE_T2_SH1106_128X64 = 2,
DISP_TYPE_T3_PCD8544_84X48 = 3,
DISP_TYPE_T4_SSD1306_128X32 = 4,
DISP_TYPE_T5_SSD1306_64X48 = 5,
DISP_TYPE_T6_SSD1309_128X64 = 6,
DISP_TYPE_T10_EPAPER = 10
};


//-------------------------------------
// EEPROM
//-------------------------------------
Expand Down
20 changes: 10 additions & 10 deletions src/plugins/Display/Display.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ class Display {
mDisplayData.version = app->getVersion(); // version never changes, so only set once

switch (mCfg->type) {
case 0: mMono = NULL; break; // None
case 1: mMono = new DisplayMono128X64(); break; // SSD1306_128X64 (0.96", 1.54")
case 2: mMono = new DisplayMono128X64(); break; // SH1106_128X64 (1.3")
case 3: mMono = new DisplayMono84X48(); break; // PCD8544_84X48 (1.6" - Nokia 5110)
case 4: mMono = new DisplayMono128X32(); break; // SSD1306_128X32 (0.91")
case 5: mMono = new DisplayMono64X48(); break; // SSD1306_64X48 (0.66" - Wemos OLED Shield)
case 6: mMono = new DisplayMono128X64(); break; // SSD1309_128X64 (2.42")
case DISP_TYPE_T0_NONE: mMono = NULL; break; // None
case DISP_TYPE_T1_SSD1306_128X64: mMono = new DisplayMono128X64(); break; // SSD1306_128X64 (0.96", 1.54")
case DISP_TYPE_T2_SH1106_128X64: mMono = new DisplayMono128X64(); break; // SH1106_128X64 (1.3")
case DISP_TYPE_T3_PCD8544_84X48: mMono = new DisplayMono84X48(); break; // PCD8544_84X48 (1.6" - Nokia 5110)
case DISP_TYPE_T4_SSD1306_128X32: mMono = new DisplayMono128X32(); break; // SSD1306_128X32 (0.91")
case DISP_TYPE_T5_SSD1306_64X48: mMono = new DisplayMono64X48(); break; // SSD1306_64X48 (0.66" - Wemos OLED Shield)
case DISP_TYPE_T6_SSD1309_128X64: mMono = new DisplayMono128X64(); break; // SSD1309_128X64 (2.42")
#if defined(ESP32) && !defined(ETHERNET)
case 10:
case DISP_TYPE_T10_EPAPER:
mMono = NULL; // ePaper does not use this
mRefreshCycle = 0;
mEpaper.config(mCfg->rot, mCfg->pwrSaveAtIvOffline);
Expand Down Expand Up @@ -93,7 +93,7 @@ class Display {

private:
void DataScreen() {
if (mCfg->type == 0)
if (mCfg->type == DISP_TYPE_T0_NONE)
return;

float totalPower = 0.0;
Expand Down Expand Up @@ -175,7 +175,7 @@ class Display {
mMono->disp();
}
#if defined(ESP32) && !defined(ETHERNET)
else if (mCfg->type == 10) {
else if (mCfg->type == DISP_TYPE_T10_EPAPER) {
mEpaper.loop((totalPower), totalYieldDay, totalYieldTotal, nrprod);
mRefreshCycle++;
}
Expand Down
7 changes: 4 additions & 3 deletions src/plugins/Display/Display_Mono_128X64.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
//-----------------------------------------------------------------------------

#pragma once
#include "Display.h"
#include "Display_Mono.h"

class DisplayMono128X64 : public DisplayMono {
Expand All @@ -19,13 +20,13 @@ class DisplayMono128X64 : public DisplayMono {
void init(DisplayData *displayData) {
u8g2_cb_t *rot = (u8g2_cb_t *)(( mCfg->rot != 0x00) ? U8G2_R2 : U8G2_R0);
switch (mCfg->type) {
case 1:
case DISP_TYPE_T1_SSD1306_128X64:
monoInit(new U8G2_SSD1306_128X64_NONAME_F_HW_I2C(rot, 0xff, mCfg->disp_clk, mCfg->disp_data), displayData);
break;
case 2:
case DISP_TYPE_T2_SH1106_128X64:
monoInit(new U8G2_SH1106_128X64_NONAME_F_HW_I2C(rot, 0xff, mCfg->disp_clk, mCfg->disp_data), displayData);
break;
case 6:
case DISP_TYPE_T6_SSD1309_128X64:
default:
monoInit(new U8G2_SSD1309_128X64_NONAME0_F_HW_I2C(rot, 0xff, mCfg->disp_clk, mCfg->disp_data), displayData);
break;
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/Display/Display_ePaper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#endif
#include "../../utils/helper.h"
#include "imagedata.h"
#include "defines.h"

#if defined(ESP32)

Expand All @@ -29,7 +30,7 @@ void DisplayEPaper::init(uint8_t type, uint8_t _CS, uint8_t _DC, uint8_t _RST, u
mRefreshState = RefreshStatus::BLACK;
mSecondCnt = 2;

if (type == 10) {
if (type == DISP_TYPE_T10_EPAPER) {
Serial.begin(115200);
_display = new GxEPD2_BW<GxEPD2_150_BN, GxEPD2_150_BN::HEIGHT>(GxEPD2_150_BN(_CS, _DC, _RST, _BUSY));

Expand Down
12 changes: 6 additions & 6 deletions src/web/RestApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -689,12 +689,12 @@ class RestApi {
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_graph_size")] = (uint8_t)mConfig->plugin.display.graph_size;
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("disp_clk")] = (mConfig->plugin.display.type == DISP_TYPE_T0_NONE) ? DEF_PIN_OFF : mConfig->plugin.display.disp_clk;
obj[F("disp_data")] = (mConfig->plugin.display.type == DISP_TYPE_T0_NONE) ? DEF_PIN_OFF : mConfig->plugin.display.disp_data;
obj[F("disp_cs")] = (mConfig->plugin.display.type < DISP_TYPE_T3_PCD8544_84X48) ? DEF_PIN_OFF : mConfig->plugin.display.disp_cs;
obj[F("disp_dc")] = (mConfig->plugin.display.type < DISP_TYPE_T3_PCD8544_84X48) ? DEF_PIN_OFF : mConfig->plugin.display.disp_dc;
obj[F("disp_rst")] = (mConfig->plugin.display.type < DISP_TYPE_T3_PCD8544_84X48) ? DEF_PIN_OFF : mConfig->plugin.display.disp_reset;
obj[F("disp_bsy")] = (mConfig->plugin.display.type < DISP_TYPE_T10_EPAPER) ? DEF_PIN_OFF : mConfig->plugin.display.disp_busy;
obj[F("pir_pin")] = mConfig->plugin.display.pirPin;
}

Expand Down
9 changes: 4 additions & 5 deletions src/web/html/setup.html
Original file line number Diff line number Diff line change
Expand Up @@ -309,11 +309,11 @@
<div id="pirPin"></div>
<div id="graphOptions">
<p class="des">{#GRAPH_OPTIONS}</p>
<div id="graphSize"></div>
<div class="row mb-3">
<div class="col-12 col-sm-3 my-2">{#GRAPH_SHOW_RATIO}</div>
<div class="col-12 col-sm-9"><input type="number" name="disp_graph_ratio" min="0" max="100"></select></div>
</div>
<div id="graphSize"></div>
</div>
</fieldset>
</div>
Expand Down Expand Up @@ -1060,8 +1060,8 @@
[5, "SSD1306 64x48 (0.66\" Wemos OLED Shield)"],
[4, "SSD1306 128x32 (0.91\")"],
[1, "SSD1306 128x64 (0.96\", 1.54\")"],
[6, "SSD1309 128X64 (2.42\")"],
[3, "PCD8544 84X48 (1.6\" Nokia 5110)"]];
[6, "SSD1309 128x64 (2.42\")"],
[3, "PCD8544 84x48 (1.6\" Nokia 5110)"]];
/*IF_ESP32*/
opts.push([10, "ePaper"]);
/*ENDIF_ESP32*/
Expand Down Expand Up @@ -1130,8 +1130,7 @@

function hideDispPins(pins, dispType) {
// create pin map for each display type.
// 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']];
// It depends on fix pin array, see var pins: ['clock', 'data', 'cs', 'dc', 'reset', 'busy']
const pinMap = new Map([
[0, [0,0,0,0,0,0]], //none
[1, [1,1,0,0,0,0]], //SSD1306_128X64
Expand Down
37 changes: 25 additions & 12 deletions src/web/web.h
Original file line number Diff line number Diff line change
Expand Up @@ -596,19 +596,32 @@ 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.graph_size = request->arg("disp_graph_size").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();
mConfig->plugin.display.disp_data = (mConfig->plugin.display.type == 0) ? DEF_PIN_OFF : request->arg("disp_data").toInt();
mConfig->plugin.display.disp_clk = (mConfig->plugin.display.type == 0) ? DEF_PIN_OFF : request->arg("disp_clk").toInt();
mConfig->plugin.display.disp_cs = (mConfig->plugin.display.type < 3) ? DEF_PIN_OFF : request->arg("disp_cs").toInt();
mConfig->plugin.display.disp_reset = (mConfig->plugin.display.type < 3) ? DEF_PIN_OFF : request->arg("disp_rst").toInt();
mConfig->plugin.display.disp_dc = (mConfig->plugin.display.type < 3) ? DEF_PIN_OFF : request->arg("disp_dc").toInt();
mConfig->plugin.display.disp_busy = (mConfig->plugin.display.type < 10) ? DEF_PIN_OFF : request->arg("disp_bsy").toInt();
mConfig->plugin.display.pirPin = request->arg("pir_pin").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 == DISP_TYPE_T0_NONE) || // contrast available only according optionsMap in setup.html, otherwise default value
(mConfig->plugin.display.type == DISP_TYPE_T10_EPAPER) ? 140 : request->arg("disp_cont").toInt();
mConfig->plugin.display.screenSaver = ((mConfig->plugin.display.type == DISP_TYPE_T1_SSD1306_128X64) || // screensaver available only according optionsMap in setup.html, otherwise default value
(mConfig->plugin.display.type == DISP_TYPE_T2_SH1106_128X64) ||
(mConfig->plugin.display.type == DISP_TYPE_T4_SSD1306_128X32) ||
(mConfig->plugin.display.type == DISP_TYPE_T5_SSD1306_64X48) ||
(mConfig->plugin.display.type == DISP_TYPE_T6_SSD1309_128X64)) ? request->arg("disp_screensaver").toInt() : 1;
mConfig->plugin.display.graph_ratio = ((mConfig->plugin.display.type == DISP_TYPE_T1_SSD1306_128X64) || // display graph available only according optionsMap in setup.html, otherwise has to be 0
(mConfig->plugin.display.type == DISP_TYPE_T2_SH1106_128X64) ||
(mConfig->plugin.display.type == DISP_TYPE_T3_PCD8544_84X48) ||
(mConfig->plugin.display.type == DISP_TYPE_T6_SSD1309_128X64)) ? request->arg("disp_graph_ratio").toInt() : 0;

// available pins according pinMap in setup.html, otherwise default value
mConfig->plugin.display.disp_data = (mConfig->plugin.display.type == DISP_TYPE_T0_NONE) ? DEF_PIN_OFF : request->arg("disp_data").toInt();
mConfig->plugin.display.disp_clk = (mConfig->plugin.display.type == DISP_TYPE_T0_NONE) ? DEF_PIN_OFF : request->arg("disp_clk").toInt();
mConfig->plugin.display.disp_cs = (mConfig->plugin.display.type != DISP_TYPE_T3_PCD8544_84X48) &&
(mConfig->plugin.display.type != DISP_TYPE_T10_EPAPER) ? DEF_PIN_OFF : request->arg("disp_cs").toInt();
mConfig->plugin.display.disp_dc = (mConfig->plugin.display.type != DISP_TYPE_T3_PCD8544_84X48) &&
(mConfig->plugin.display.type != DISP_TYPE_T10_EPAPER) ? DEF_PIN_OFF : request->arg("disp_dc").toInt();
mConfig->plugin.display.disp_reset = (mConfig->plugin.display.type != DISP_TYPE_T10_EPAPER) ? DEF_PIN_OFF : request->arg("disp_rst").toInt();
mConfig->plugin.display.disp_busy = (mConfig->plugin.display.type != DISP_TYPE_T10_EPAPER) ? DEF_PIN_OFF : request->arg("disp_bsy").toInt();
mConfig->plugin.display.pirPin = (mConfig->plugin.display.screenSaver != DISP_TYPE_T2_SH1106_128X64) ? DEF_PIN_OFF : request->arg("pir_pin").toInt(); // pir pin only for motion screensaver
// otherweise default value

mApp->saveSettings((request->arg("reboot") == "on"));

Expand Down

0 comments on commit b792f69

Please sign in to comment.