diff --git a/src/app.cpp b/src/app.cpp index c2a1fd6e2..32a94ceae 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -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 @@ -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"); diff --git a/src/app.h b/src/app.h index e66302192..c9a2a9ccb 100644 --- a/src/app.h +++ b/src/app.h @@ -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(); diff --git a/src/defines.h b/src/defines.h index 792080d65..5e479970c 100644 --- a/src/defines.h +++ b/src/defines.h @@ -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 //------------------------------------- diff --git a/src/plugins/Display/Display.h b/src/plugins/Display/Display.h index 7780afef0..1748f4dd0 100644 --- a/src/plugins/Display/Display.h +++ b/src/plugins/Display/Display.h @@ -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); @@ -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; @@ -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++; } diff --git a/src/plugins/Display/Display_Mono_128X64.h b/src/plugins/Display/Display_Mono_128X64.h index b4aa08cc1..a2518e4a8 100644 --- a/src/plugins/Display/Display_Mono_128X64.h +++ b/src/plugins/Display/Display_Mono_128X64.h @@ -4,6 +4,7 @@ //----------------------------------------------------------------------------- #pragma once +#include "Display.h" #include "Display_Mono.h" class DisplayMono128X64 : public DisplayMono { @@ -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; diff --git a/src/plugins/Display/Display_ePaper.cpp b/src/plugins/Display/Display_ePaper.cpp index 36d7a9019..b59e2f361 100644 --- a/src/plugins/Display/Display_ePaper.cpp +++ b/src/plugins/Display/Display_ePaper.cpp @@ -7,6 +7,7 @@ #endif #include "../../utils/helper.h" #include "imagedata.h" +#include "defines.h" #if defined(ESP32) @@ -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(_CS, _DC, _RST, _BUSY)); diff --git a/src/web/RestApi.h b/src/web/RestApi.h index 6a9e1e2b6..2b8083611 100644 --- a/src/web/RestApi.h +++ b/src/web/RestApi.h @@ -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; } diff --git a/src/web/web.h b/src/web/web.h index b0688d837..0391e449e 100644 --- a/src/web/web.h +++ b/src/web/web.h @@ -599,28 +599,28 @@ class Web { 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) || // contrast available only according optionsMap in setup.html, otherwise default value - (mConfig->plugin.display.type == 10) ? 140 : request->arg("disp_cont").toInt(); - mConfig->plugin.display.screenSaver = ((mConfig->plugin.display.type == 1) || // screensaver available only according optionsMap in setup.html, otherwise default value - (mConfig->plugin.display.type == 2) || - (mConfig->plugin.display.type == 4) || - (mConfig->plugin.display.type == 5) || - (mConfig->plugin.display.type == 6)) ? request->arg("disp_screensaver").toInt() : 1; - mConfig->plugin.display.graph_ratio = ((mConfig->plugin.display.type == 1) || // display graph available only according optionsMap in setup.html, otherwise has to be 0 - (mConfig->plugin.display.type == 2) || - (mConfig->plugin.display.type == 3) || - (mConfig->plugin.display.type == 6)) ? request->arg("disp_graph_ratio").toInt() : 0; + 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 == 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) && - (mConfig->plugin.display.type != 10) ? DEF_PIN_OFF : request->arg("disp_cs").toInt(); - mConfig->plugin.display.disp_dc = (mConfig->plugin.display.type != 3) && - (mConfig->plugin.display.type != 10) ? DEF_PIN_OFF : request->arg("disp_dc").toInt(); - mConfig->plugin.display.disp_reset = (mConfig->plugin.display.type != 10) ? DEF_PIN_OFF : request->arg("disp_rst").toInt(); - mConfig->plugin.display.disp_busy = (mConfig->plugin.display.type != 10) ? DEF_PIN_OFF : request->arg("disp_bsy").toInt(); - mConfig->plugin.display.pirPin = (mConfig->plugin.display.screenSaver != 2) ? DEF_PIN_OFF : request->arg("pir_pin").toInt(); // pir pin only for motion screensaver + 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"));