Skip to content

Commit

Permalink
introducing display nightmode - see readme (chapter display support) …
Browse files Browse the repository at this point in the history
…+ minor fixes at display functions
  • Loading branch information
ohAnd committed Sep 9, 2024
1 parent ecfc935 commit 91a408d
Show file tree
Hide file tree
Showing 12 changed files with 415 additions and 207 deletions.
11 changes: 10 additions & 1 deletion include/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,16 @@ struct UserConfig
boolean remoteDisplayActive = false; // remote display to get data from mqtt

uint8_t displayConnected = 0; // OLED default
uint16_t displayOrientation = 0; // OLED 0,180 degrees - TFT 0,90,180,270 degrees
uint16_t displayOrientation = 0; // OLED 0,180 degrees - TFT 0,90,180,270 degrees
uint8_t displayBrightnessDay = 100;
uint8_t displayBrightnessNight = 10;
boolean displayNightClock = false; // in night mode: true - display clock/ false - display dark screen

boolean displayNightMode = false; // night mode enabled
uint16_t displayNightmodeStart = 1320; // 22:00 = 22 * 60 = 1320
uint16_t displayNightmodeEnd = 360; // 06:00 = 6 * 60 = 360



boolean wifiAPstart = true;
int selectedUpdateChannel = 0; // 0 - release 1 - snapshot
Expand Down
6 changes: 6 additions & 0 deletions include/display.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class Display {
void drawUpdateMode(String text,String text2="");

void setRemoteDisplayMode(bool remoteDisplayActive);

private:
void drawScreen();
void drawHeader();
Expand All @@ -40,12 +41,17 @@ class Display {

void screenSaver();
void checkChangedValues();

void checkNightMode();
void setBrightnessAuto();

// private member variables
DisplayData lastDisplayData;
uint8_t brightness=BRIGHTNESS_MAX;
u8g2_uint_t offset_x = 0; // shifting for anti burn in effect
u8g2_uint_t offset_y = 0; // shifting for anti burn in effect
bool valueChanged = false;
boolean isNight = false;
uint16_t displayTicks = 0; // local timer state machine
};

Expand Down
22 changes: 16 additions & 6 deletions include/displayTFT.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,15 @@

// TFT display

#define BRIGHTNESS_MIN 50
#define BRIGHTNESS_MAX 250

#if defined(ESP8266)
#define BACKLIIGHT_PIN 12
#elif defined(ESP32)
#define BACKLIIGHT_PIN 4
#endif

#define BRIGHTNESS_TFT_MIN 0
#define BRIGHTNESS_TFT_MAX 255

#define DARKER_GREY 0x18E3
#define SPECIAL_BLUE 0x24ae
Expand All @@ -21,9 +28,6 @@ struct DisplayDataTFT {
uint8_t powerLimit=0;
uint8_t rssiGW=0;
uint8_t rssiDTU=0;
bool stateWasOffline=false;
bool stateWasCloudPause=true;
bool stateWasNormal=false;
boolean remoteDisplayActive = false;
};

Expand All @@ -47,12 +51,18 @@ class DisplayTFT {

void drawIcon(const uint16_t *icon, int16_t x, int16_t y, int16_t w, int16_t h);

void checkNightMode();
void setBrightnessAuto();

// private member variables
DisplayDataTFT lastDisplayData;
uint8_t brightness=BRIGHTNESS_MIN;
uint8_t brightness=BRIGHTNESS_TFT_MIN;
uint8_t offset_x = 0; // shifting for anti burn in effect
uint8_t offset_y = 0; // shifting for anti burn in effect
bool valueChanged = false;
boolean isNight = false;
uint8_t displayState = 0; // local state machine
uint8_t displayStateOld = 0; // local state machine
uint16_t displayTicks = 0; // local timer state machine

void showDebug();
Expand Down
6 changes: 3 additions & 3 deletions include/version.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#define VERSION "1.9.639_localDev"
#define BUILDTIME "04.09.2024 - 12:15:16"
#define BUILDTIMESTAMP "1725444916"
#define VERSION "1.9.857_localDev"
#define BUILDTIME "09.09.2024 - 12:39:02"
#define BUILDTIMESTAMP "1725878342"
8 changes: 4 additions & 4 deletions include/version.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"version": "1.9.639_localDev",
"versiondate": "04.09.2024 - 12:15:16",
"linksnapshot": "https://github.com/ohAnd/dtuGateway/releases/download/snapshot/dtuGateway_snapshot_1.9.639_localDev.bin",
"link": "https://github.com/ohAnd/dtuGateway/releases/latest/download/dtuGateway_release_1.9.639_localDev.bin"
"version": "1.9.857_localDev",
"versiondate": "09.09.2024 - 12:39:02",
"linksnapshot": "https://github.com/ohAnd/dtuGateway/releases/download/snapshot/dtuGateway_snapshot_1.9.857_localDev.bin",
"link": "https://github.com/ohAnd/dtuGateway/releases/latest/download/dtuGateway_release_1.9.857_localDev.bin"
}
8 changes: 4 additions & 4 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ platform = espressif32
board = esp32dev
framework = arduino
monitor_speed = 115200
monitor_port = COM3
upload_port = COM3
monitor_port = COM8
upload_port = COM8
upload_speed = 921600
lib_deps =
arduino-libraries/NTPClient @ ^3.2.1
Expand Down Expand Up @@ -64,8 +64,8 @@ platform = espressif8266
board = esp07s
framework = arduino
monitor_speed = 115200
monitor_port = COM7
upload_port = COM7
monitor_port = COM3
upload_port = COM3
upload_speed = 921600
lib_deps =
arduino-libraries/NTPClient @ ^3.2.1
Expand Down
30 changes: 21 additions & 9 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,18 @@ So I decided to put this abstraction in an **ESP8266** to have a stable abstract
- setting the orientation of the display via advanced web config[^2]
- OLED - 0 and 180 degrees are supported
- TFT - 0, 90, 180, 270 degrees are supported
- brightness and night mode (brightness only for OLED and TFT with connected backlight control)
- with night mode enabled and during the active time frame the display will be
- off/ blank (without backlight control) or
- show the current time and power (if greater than 0) in a reduced scope
- adjustable via web config[^2]
- brightness day [0...255] - will also be used without night mode enabled for standard brightness (falling back to this after power value changed)
- brightness night [0...255]
- (to disable PWM control for TFT without backlight control set both brightness values to zero)
- night mode enabled on/ off
- night mode start in minutes to start of the day - e.g. 1320 for 22:00
- night mode stop in minutes to start of the day - e.g. 360 for 6:00
- night clock enabled on/ of - on = clock will be displayed instead of dark screen
- display hardware types
- display SSH1106 OLED 1,3" 128x64 (other sizes with same driver (SSH1106) and resolution should also directly work)

Expand All @@ -122,7 +134,7 @@ So I decided to put this abstraction in an **ESP8266** to have a stable abstract
- small screensaver to prevent burn-in effect with steady components on the screen (shifting the whole screen every minute with 1 pixel in a 4 step rotation)
- smooth brightness control for changed main value - increase to max after change and then dimmming smooth back to the default level

- display GC9A01 round TFT 1,28" 240x240
- display GC9A01 round TFT 1,28" 240x240 with or without backlight control

<img src="doc/images/roundTFT_firstSTart.jpg" alt="roundTFT_firstSTart" width="180"/>
<img src="doc/images/roundTFT.jpg" alt="roundTFT" width="180"/>
Expand Down Expand Up @@ -370,16 +382,16 @@ So I decided to put this abstraction in an **ESP8266** to have a stable abstract
- optional display GC9A01 round TFT 1,28" 240x240 (e.g. [link](https://de.aliexpress.com/i/1005006190625792.html)):
- connect SSH1106 driven round TFT display (240x240) with your ESP8266/ ESP32 board (VCC, GND, SCL, SDA, DC, CS, RST)
- pinning for different boards (display connector to ESPxx board pins)

| dev board | ESP family | VCC | GND | SCL | SDA | DC | CS | RST | tested |
|--------------------------------------------------|------------|:----:|:---:|:----------------:|:---------------:|:-----------------:|:-------------------:|:------------:|:------:|
| AZDelivery D1 Board NodeMCU ESP8266MOD-12F | ESP8266 | 3.3V | GND | t.b.d. | t.b.d. | t.b.d. | t.b.d. | t.b.d. | t.b.c. |
| AZDelivery NodeMCU V2 WiFi Amica ESP8266 ESP-12F | ESP8266 | 3.3V | GND | D5/GPI14/SCLK | D7/GPIO13/MOSI | D3/GPIO0/Flash | D8/GPIO15/CS | 3V3[^1] | OK |
| AZDelivery D1 Mini NodeMcu mit ESP8266-12F | ESP8266 | 3V3 | G | D5/GPI14/SCLK | D7/GPIO13/MOSI | D3/GPIO0/Flash | D8/GPIO15/CS | 3V3[^1] | OK |
| ESP-WROOM-32 NodeMCU-32S | ESP32 | 3.3V | GND | D18/GPIO18/SCK | D23/GPIO23/MOSI | D2/GPIO2/HSPI_WP0 | D15/GPIO15/HSPI_CS0 | 3.3V (D4) [^1]| OK |
- BLK = backlight control - will be served with PWM via GPIO 4

| dev board | ESP family | VCC | GND | SCL | SDA | DC | CS | RST | BKL (opt) | tested |
|--------------------------------------------------|------------|:----:|:---:|:----------------:|:---------------:|:-----------------:|:-------------------:|:-------------:|:--------------:|:------:|
| AZDelivery D1 Board NodeMCU ESP8266MOD-12F | ESP8266 | 3.3V | GND | t.b.d. | t.b.d. | t.b.d. | t.b.d. | t.b.d. | t.b.d. | t.b.c. |
| AZDelivery NodeMCU V2 WiFi Amica ESP8266 ESP-12F | ESP8266 | 3.3V | GND | D5/GPI14/SCLK | D7/GPIO13/MOSI | D3/GPIO0/Flash | D8/GPIO15/CS | 3V3[^1] | D6/GPIO12 | OK |
| AZDelivery D1 Mini NodeMcu mit ESP8266-12F | ESP8266 | 3V3 | G | D5/GPI14/SCLK | D7/GPIO13/MOSI | D3/GPIO0/Flash | D8/GPIO15/CS | 3V3[^1] | t.b.d. | OK |
| ESP-WROOM-32 NodeMCU-32S | ESP32 | 3.3V | GND | D18/GPIO18/SCK | D23/GPIO23/MOSI | D2/GPIO2/HSPI_WP0 | D15/GPIO15/HSPI_CS0 | 3V3[^1] | D4/GPIO04 | OK |
[^1]: reset pin of display currently not in use therefore directly pulled up to 3,3 V


### first installation to the ESP device
#### example for ESP8266
1. download the preferred release as binary (see below)
Expand Down
29 changes: 27 additions & 2 deletions src/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,23 @@ void UserConfigManager::printConfigdata()
Serial.print(F("update channel: \t\t"));
Serial.println(userConfig.selectedUpdateChannel);

Serial.print(F("display connected: \t"));
Serial.print(F("\ndisplay connected: \t"));
Serial.println(userConfig.displayConnected);
Serial.print(F("display orientation: \t"));
Serial.print(F("display orientation: \t\t"));
Serial.println(userConfig.displayOrientation);
Serial.print(F("display brightness day: \t\t"));
Serial.println(userConfig.displayBrightnessDay);
Serial.print(F("display brightness night: \t"));
Serial.println(userConfig.displayBrightnessNight);
Serial.print(F("display night clock: \t\t"));
Serial.println(userConfig.displayNightClock);
Serial.print(F("display night mode: \t\t"));
Serial.println(userConfig.displayNightMode);
Serial.print(F("display nightmode start: \t"));
Serial.println(userConfig.displayNightmodeStart);
Serial.print(F("display nightmode end: \t\t"));
Serial.println(userConfig.displayNightmodeEnd);

Serial.print(F("--------------------------------------\n"));
}

Expand Down Expand Up @@ -199,6 +212,12 @@ JsonDocument UserConfigManager::mappingStructToJson(const UserConfig &config)

doc["display"]["type"] = config.displayConnected;
doc["display"]["orientation"] = config.displayOrientation;
doc["display"]["brightnessDay"] = config.displayBrightnessDay;
doc["display"]["brightnessNight"] = config.displayBrightnessNight;
doc["display"]["nightClock"] = config.displayNightClock;
doc["display"]["nightMode"] = config.displayNightMode;
doc["display"]["nightmodeStart"] = config.displayNightmodeStart;
doc["display"]["nightmodeEnd"] = config.displayNightmodeEnd;

doc["local"]["selectedUpdateChannel"] = config.selectedUpdateChannel;
doc["local"]["wifiAPstart"] = config.wifiAPstart;
Expand Down Expand Up @@ -236,6 +255,12 @@ void UserConfigManager::mappingJsonToStruct(JsonDocument doc)

userConfig.displayConnected = doc["display"]["type"];
userConfig.displayOrientation = doc["display"]["orientation"];
userConfig.displayBrightnessDay = doc["display"]["brightnessDay"];
userConfig.displayBrightnessNight = doc["display"]["brightnessNight"];
userConfig.displayNightClock = doc["display"]["nightClock"];
userConfig.displayNightMode = doc["display"]["nightMode"];
userConfig.displayNightmodeStart = doc["display"]["nightmodeStart"];
userConfig.displayNightmodeEnd = doc["display"]["nightmodeEnd"];

userConfig.selectedUpdateChannel = doc["local"]["selectedUpdateChannel"];
userConfig.wifiAPstart = doc["local"]["wifiAPstart"];
Expand Down
Loading

0 comments on commit 91a408d

Please sign in to comment.