Skip to content

Commit

Permalink
replace display numbers by enums
Browse files Browse the repository at this point in the history
  • Loading branch information
You69Man committed Jan 18, 2024
1 parent 47e30b3 commit 21234d2
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 43 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
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
40 changes: 20 additions & 20 deletions src/web/web.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down

0 comments on commit 21234d2

Please sign in to comment.