Compare commits

..

9 Commits

7 changed files with 125 additions and 141 deletions

View File

@@ -1,96 +1,49 @@
# Important Note: # Important Note:
This project has been unofficially forked from https://github.com/techniccontroller/wordclock_esp8266 which was initially created by techniccontroller. Copyright and licensing is respected. This project has been unofficially forked from https://github.com/techniccontroller/wordclock_esp8266 which was initially created by techniccontroller. Copyright and licensing is respected. Very many thanks for the initial code!
# Wordclock 2.0 # Wordclock 2.0
Wordclock 2.0 with ESP8266 and NTP time Wordclock 2.0 with ESP8266 and NTP time
More details on my website: https://techniccontroller.com/word-clock-with-wifi-and-neopixel/ More details on techniccontroller's website: https://techniccontroller.com/word-clock-with-wifi-and-neopixel/
**Languages** **Languages**
The Wordclock is available in **German**, **English** and **Italian** language. By default the language is German. The Wordclock is available in **German** language.
To use the English or Italian language please replace the file *wordclockfunctions.ino* with *wordclockfunctions.ino_english* or *wordclockfunctions.ino_italian*.
The code compiles only with one file named *wordclockfunctions.ino*. So please rename the file you want to use to *wordclockfunctions.ino* and replace the existing file.
## Features ## Features
- 6 modes (Clock, Digital Clock, SPIRAL animation, TETRIS, SNAKE, PONG) - Time update via NTP server
- time update via NTP server - Games: Pong, Snake, Tetris, ...
- automatic summer/wintertime change - Automatic summer/wintertime change
- easy WIFI setup with WifiManager - Easy wifi setup with WifiManager
- configurable color - Configurable color
- configurable night mode (start and end time) - Configurable night mode (start and end time)
- configurable brightness - Configurable brightness
- automatic mode change - Automatic mode change
- webserver interface for configuration and control - Webserver interface for configuration and control (web address: wordclock.local)
- physical button to change mode or enable night mode without webserver - Automatic current limiting of LEDs
- automatic current limiting of LEDs
## Pictures of clock ## Pictures of clock
![modes_images2](https://user-images.githubusercontent.com/36072504/156947689-dd90874d-a887-4254-bede-4947152d85c1.png) ![modes_images2](https://user-images.githubusercontent.com/36072504/156947689-dd90874d-a887-4254-bede-4947152d85c1.png)
## Screenshots of webserver UI
![screenshots_UI](https://user-images.githubusercontent.com/36072504/158478447-d828e460-d4eb-489e-981e-216e08d4b129.png)
## Quickstart ## Quickstart
1. Clone the project into the sketch folder of the Arduino IDE, 1. Clone the project into the a directory.
2. Rename the file "example_secrets.h" to "secrets.h". You don't need to change anything in the file if you want uses the normal WiFi setup with WiFiManager (see section "Remark about the WiFi setup"). 2. Open directory in VSCode with PlatformIO extension installed.
3. Install the additional libraries and flash it to the ESP8266 as usual (See section [*Upload program to ESP8266*](https://github.com/techniccontroller/wordclock_esp8266/blob/main/README.md#upload-program-to-esp8266-with-arduino-ide) below). 3. Current dependencies (2024-07-21):
4. The implemented WiFiManager helps you to set up a WiFi connection with your home WiFi -> on the first startup it will create a WiFi access point named "WordclockAP". Connect your phone to this access point and follow the steps which will be shown to you. - Platform espressif8266 @ 2.6.3 (required: espressif8266 @ 2.6.3)
5. After a successful WiFi setup, open the browser and enter the IP address of your ESP8266 to access the interface of the webserver. - Libraries
6. Here you can then upload all files located in the folder "data". Please make sure all icons stay in the folder "icons" also on the webserver. - ├── FastLED @ 3.7.0 (required: fastled/FastLED @ 3.7.0)
- ├── FastLED NeoMatrix @ 1.2.0 (required: marcmerlin/FastLED NeoMatrix @ ^1.2)
- │⠀⠀⠀└── Framebuffer GFX @ 1.1.0 (required: Framebuffer GFX)
<img src="https://techniccontroller.com/wp-content/uploads/filemanager1-1.png" height="300px" /> <img src="https://techniccontroller.com/wp-content/uploads/filemanager2-1.png" height="300px" /> <img src="https://techniccontroller.com/wp-content/uploads/filemanager3-1.png" height="300px" /> - │⠀⠀⠀│⠀⠀⠀├── Adafruit GFX Library @ 1.11.9 (required: Adafruit GFX Library)
- │⠀⠀⠀│⠀⠀⠀│⠀⠀⠀└── Adafruit BusIO @ 1.16.1 (required: Adafruit BusIO)
## Install needed Libraries - ├── WiFiManager @ 0.16.0 (required: tzapu/WiFiManager @ ^0.16.0)
- └── base64 @ 1.4.0 (required: densaugeo/base64 @ ^1.4.0)
Please download all these libraries as ZIP from GitHub, and extract them in the *libraries* folder of your Sketchbook location (see **File -> Preferences**):
- https://github.com/adafruit/Adafruit-GFX-Library
- https://github.com/adafruit/Adafruit_NeoMatrix
- https://github.com/adafruit/Adafruit_NeoPixel
- https://github.com/tzapu/WiFiManager
- https://github.com/adafruit/Adafruit_BusIO
## Remark about the WiFi setup ## Remark about the WiFi setup
Regarding the Wifi setting, I have actually implemented two variants: By default the WifiManager is activated. That is, the word clock makes the first time its own WiFi (should be called "WordclockAP"). There you simply connect to the cell phone and you can perform configuration of the WiFi settings conveniently as with SmartHome devices.
1. By default the WifiManager is activated. That is, the word clock makes the first time its own WiFi (should be called "WordclockAP"). There you simply connect to the cell phone and you can perform configuration of the WiFi settings conveniently as with a SmartHome devices (Very elegant 😊)
2. Another (traditional) variant is to define the wifi credentials in the code (in secrets.h).
- For this you have to comment out lines 230 to 251 in the code of the file *wordclock_esp8266.ino* (/\* before and \*/ after)
- and comment out lines 257 to 305 (/\* and \*/ remove)
## Remark about Logging
The wordclock send continuously log messages to the serial port and via multicast UDP. If you want to see these messages, you have to
- open the serial monitor in the Arduino IDE (Tools -> Serial Monitor). The serial monitor must be set to 115200 baud.
OR
- run the following steps for the multicast UDP logging:
1. starting situation: wordclock is connected to WLAN, a computer with installed Python (https://www.python.org/downloads/) is in the same local area network (WLAN or LAN doesn't matter).
3. open the file **multicastUDP_receiver.py** in a text editor and in line 81 enter the IP address of the computer (not the wordclock!).
```python
# ip address of network interface
MCAST_IF_IP = '192.168.0.7'
```
4. execute the script with following command:
```bash
python multicastUDP_receiver_analyzer.py
```
5. now you should see the log messages of the word clock (every 5 seconds a heartbeat message and the currently displayed time).
If this is not the case, there could be a problem with the network settings of the computer, then recording is unfortunately not possible.
6. If special events (failed NTP update, reboot) occur, a section of the log is saved in a file called *log.txt*.
In principle, the events are not critical and will occur from time to time, but should not be too frequent.

View File

@@ -69,6 +69,7 @@
#define MATRIX_WIDTH (11) #define MATRIX_WIDTH (11)
#define MATRIX_HEIGHT (11) #define MATRIX_HEIGHT (11)
#define NUM_MATRIX (MATRIX_WIDTH * (MATRIX_HEIGHT + 1)) #define NUM_MATRIX (MATRIX_WIDTH * (MATRIX_HEIGHT + 1))
#define MIN_LEDS_PATTERN (0x0F)
// NTP macros // NTP macros
#define BUILD_YEAR (__DATE__ + 7) // Will expand to current year at compile time as string. #define BUILD_YEAR (__DATE__ + 7) // Will expand to current year at compile time as string.

View File

@@ -17,11 +17,13 @@ board = nodemcuv2
framework = arduino framework = arduino
lib_deps = lib_deps =
densaugeo/base64@^1.4.0 densaugeo/base64@^1.4.0
fastled/FastLED@3.7.0 fastled/FastLED@3.7.6
marcmerlin/FastLED NeoMatrix@^1.2 marcmerlin/FastLED NeoMatrix@^1.2
tzapu/WiFiManager@^0.16.0 tzapu/WiFiManager@^2.0.17
build_flags = build_flags =
-DFASTLED_ESP8266_RAW_PIN_ORDER -DFASTLED_ESP8266_RAW_PIN_ORDER
board_build.f_cpu = 160000000L
extra_scripts = post:post_build.py
[env:nodemcuv2] [env:nodemcuv2]
monitor_speed = 115200 monitor_speed = 115200

25
post_build.py Normal file
View File

@@ -0,0 +1,25 @@
Import("env")
from pathlib import Path
import hashlib
print("Current CLI targets", COMMAND_LINE_TARGETS)
print("Current Build targets", BUILD_TARGETS)
def sha256sum(filename):
with open(filename, 'rb', buffering=0) as f:
return hashlib.file_digest(f, 'sha256').hexdigest()
def post_buildprog_action(source, target, env):
source_path = Path(source[0].get_abspath())
sha256 = sha256sum(source_path)
print(f"Calculated SHA256: {sha256}")
build_dir = source_path.parent
sha_txt_file = build_dir / "firmware.bin.sha256"
with Path.open(sha_txt_file, "w") as f:
f.write(sha256)
env.AddPostAction("buildprog", post_buildprog_action)

View File

@@ -43,6 +43,7 @@ String Diagnosis::print_device_info()
// Retrieve and print device information // Retrieve and print device information
String device_info = "Device Information:\n"; String device_info = "Device Information:\n";
device_info += "Chip ID: " + String(ESP.getChipId()) + "\n"; device_info += "Chip ID: " + String(ESP.getChipId()) + "\n";
device_info += "CPU frequency: " + String(ESP.getCpuFreqMHz()) + " MHz\n";
device_info += "Flash Chip ID: " + String(ESP.getFlashChipId()) + "\n"; device_info += "Flash Chip ID: " + String(ESP.getFlashChipId()) + "\n";
device_info += "Flash Chip Size: " + String(ESP.getFlashChipSize()) + " bytes\n"; device_info += "Flash Chip Size: " + String(ESP.getFlashChipSize()) + " bytes\n";
device_info += "Free Heap Size: " + String(ESP.getFreeHeap()) + " bytes\n"; device_info += "Free Heap Size: " + String(ESP.getFreeHeap()) + " bytes\n";

View File

@@ -44,12 +44,13 @@ bool TimeManager::ntp_sync_successful(void) const
bool TimeManager::ntp_sync_overdue(void) bool TimeManager::ntp_sync_overdue(void)
{ {
bool retval = false;
if (!ntp_sync_successful()) if (!ntp_sync_successful())
{ {
return false; return retval;
} }
bool retval = false;
// after the ntp sync update delay has been reached six times, the sync is considered overdue // after the ntp sync update delay has been reached six times, the sync is considered overdue
if (_now >= (_ntp_sync_timestamp_s + (time_t)(6 * (sntp_update_delay_MS_rfc_not_less_than_15000() / 1000)))) if (_now >= (_ntp_sync_timestamp_s + (time_t)(6 * (sntp_update_delay_MS_rfc_not_less_than_15000() / 1000))))
{ {
@@ -61,12 +62,13 @@ bool TimeManager::ntp_sync_overdue(void)
bool TimeManager::ntp_sync_timeout(void) bool TimeManager::ntp_sync_timeout(void)
{ {
bool retval = false;
if (!ntp_sync_successful()) if (!ntp_sync_successful())
{ {
return false; return retval;
} }
bool retval = false;
// after the maxmimum offline time has been reached, the sync is considered timed out // after the maxmimum offline time has been reached, the sync is considered timed out
if (_now >= (_ntp_sync_timestamp_s + (time_t)_ntp_max_offline_time_s)) if (_now >= (_ntp_sync_timestamp_s + (time_t)_ntp_max_offline_time_s))
{ {

View File

@@ -1,7 +1,7 @@
/** /**
* Wordclock 2.0 - Wordclock with ESP8266 and NTP time update * Wordclock 2.0 - Wordclock with ESP8266 and NTP time update
* *
* created by techniccontroller 04.12.2021 * created by techniccontroller 04.12.2021, refactored and additions by ranse 10.12.2024
* *
* components: * components:
* - ESP8266 * - ESP8266
@@ -60,10 +60,10 @@ ESP8266WebServer webserver(HTTP_PORT); // Webse
// STATIC VARIABLES // STATIC VARIABLES
// ---------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------
// EEPROM values // EEPROM values
static EepromLayout_st eeprom_buffer = {{0, 0, 0, 0}, {0U, 0U, 0U, false}, {0U, 0U, 0U, 0U}}; static EepromLayout_st eeprom_buffer_st = {{0, 0, 0, 0}, {0U, 0U, 0U, false}, {0U, 0U, 0U, 0U}};
static Brightness_st *const brightness_ps = &eeprom_buffer.brightness_values; static Brightness_st *const brightness_cpst = &eeprom_buffer_st.brightness_values;
static Color_st *const colors_ps = &eeprom_buffer.color_values; static Color_st *const colors_cpst = &eeprom_buffer_st.color_values;
static NightModeTimes_st *const night_mode_times_ps = &eeprom_buffer.night_mode_times; static NightModeTimes_st *const night_mode_times_cpst = &eeprom_buffer_st.night_mode_times;
// Games // Games
static Pong pong = Pong(&led_matrix, &logger); static Pong pong = Pong(&led_matrix, &logger);
@@ -138,7 +138,7 @@ void setup()
led_matrix.set_current_limit(CURRENT_LIMIT_LED); led_matrix.set_current_limit(CURRENT_LIMIT_LED);
// Turn on minutes LEDs (blue) // Turn on minutes LEDs (blue)
led_matrix.set_min_indicator((uint8_t)0b1111, colors_24bit[6]); led_matrix.set_min_indicator(MIN_LEDS_PATTERN, colors_24bit[6]);
led_matrix.draw_on_matrix_instant(); led_matrix.draw_on_matrix_instant();
/* Use WiFiMaanger for handling initial Wifi setup */ /* Use WiFiMaanger for handling initial Wifi setup */
@@ -157,7 +157,7 @@ void setup()
WiFi.persistent(true); WiFi.persistent(true);
// Turn off minutes LEDs // Turn off minutes LEDs
led_matrix.set_min_indicator((uint8_t)0b1111, 0); led_matrix.set_min_indicator(MIN_LEDS_PATTERN, 0);
led_matrix.draw_on_matrix_instant(); led_matrix.draw_on_matrix_instant();
// init ESP8266 File manager (LittleFS) // init ESP8266 File manager (LittleFS)
@@ -295,8 +295,8 @@ void log_data()
logger.log_string("IP: " + WiFi.localIP().toString()); logger.log_string("IP: " + WiFi.localIP().toString());
logger.log_string("Reset Reason: " + ESP.getResetReason()); logger.log_string("Reset Reason: " + ESP.getResetReason());
logger.log_string("Nightmode starts at: " + String(night_mode_times_ps->start_hour) + ":" + String(night_mode_times_ps->start_min)); logger.log_string("Nightmode starts at: " + String(night_mode_times_cpst->start_hour) + ":" + String(night_mode_times_cpst->start_min));
logger.log_string("Nightmode ends at: " + String(night_mode_times_ps->end_hour) + ":" + String(night_mode_times_ps->end_min)); logger.log_string("Nightmode ends at: " + String(night_mode_times_cpst->end_hour) + ":" + String(night_mode_times_cpst->end_min));
logger.log_string("Brightness: " + String(((uint16_t)current_brightness * 100) / UINT8_MAX) + "%\n"); logger.log_string("Brightness: " + String(((uint16_t)current_brightness * 100) / UINT8_MAX) + "%\n");
} }
@@ -363,7 +363,7 @@ void handle_current_state()
// clear matrix // clear matrix
led_matrix.flush(); led_matrix.flush();
// Turn on minutes LEDs (blue) // Turn on minutes LEDs (blue)
led_matrix.set_min_indicator((uint8_t)0b1111, colors_24bit[6]); led_matrix.set_min_indicator((uint8_t)MIN_LEDS_PATTERN, colors_24bit[6]);
led_matrix.draw_on_matrix_instant(); led_matrix.draw_on_matrix_instant();
} }
break; break;
@@ -379,7 +379,7 @@ void handle_current_state()
// clear matrix // clear matrix
led_matrix.flush(); led_matrix.flush();
// Turn on minutes LEDs (blue) // Turn on minutes LEDs (blue)
led_matrix.set_min_indicator((uint8_t)0b1111, colors_24bit[6]); led_matrix.set_min_indicator((uint8_t)MIN_LEDS_PATTERN, colors_24bit[6]);
led_matrix.draw_on_matrix_instant(); led_matrix.draw_on_matrix_instant();
} }
break; break;
@@ -482,11 +482,11 @@ void check_night_mode()
int hours = tm_mgr.hour(); int hours = tm_mgr.hour();
int minutes = tm_mgr.minute(); int minutes = tm_mgr.minute();
if ((hours == night_mode_times_ps->start_hour) && (minutes == night_mode_times_ps->start_min)) if ((hours == night_mode_times_cpst->start_hour) && (minutes == night_mode_times_cpst->start_min))
{ {
set_night_mode(true); set_night_mode(true);
} }
else if ((hours == night_mode_times_ps->end_hour) && (minutes == night_mode_times_ps->end_min)) else if ((hours == night_mode_times_cpst->end_hour) && (minutes == night_mode_times_cpst->end_min))
{ {
set_night_mode(false); set_night_mode(false);
} }
@@ -657,9 +657,9 @@ void set_main_color(uint8_t red, uint8_t green, uint8_t blue)
main_color_clock = LEDMatrix::color_24bit(red, green, blue); main_color_clock = LEDMatrix::color_24bit(red, green, blue);
// Update colors and save color settings to EEPROM // Update colors and save color settings to EEPROM
colors_ps->blue = blue; colors_cpst->blue = blue;
colors_ps->red = red; colors_cpst->red = red;
colors_ps->green = green; colors_cpst->green = green;
write_settings_to_EEPROM(); write_settings_to_EEPROM();
} }
@@ -670,9 +670,9 @@ void set_main_color(uint8_t red, uint8_t green, uint8_t blue)
void draw_main_color() void draw_main_color()
{ {
uint8_t red = colors_ps->red; uint8_t red = colors_cpst->red;
uint8_t green = colors_ps->green; uint8_t green = colors_cpst->green;
uint8_t blue = colors_ps->blue; uint8_t blue = colors_cpst->blue;
if ((int(red) + int(green) + int(blue)) < 50) if ((int(red) + int(green) + int(blue)) < 50)
{ {
@@ -769,14 +769,14 @@ void handle_command()
{ {
String cmd_str = webserver.arg(0) + "-"; String cmd_str = webserver.arg(0) + "-";
logger.log_string("Nightmode setting change via Webserver to: " + cmd_str); logger.log_string("Nightmode setting change via Webserver to: " + cmd_str);
night_mode_times_ps->start_hour = (int)split(cmd_str, '-', 0).toInt(); night_mode_times_cpst->start_hour = (int)split(cmd_str, '-', 0).toInt();
night_mode_times_ps->start_min = (int)split(cmd_str, '-', 1).toInt(); night_mode_times_cpst->start_min = (int)split(cmd_str, '-', 1).toInt();
night_mode_times_ps->end_hour = (int)split(cmd_str, '-', 2).toInt(); night_mode_times_cpst->end_hour = (int)split(cmd_str, '-', 2).toInt();
night_mode_times_ps->end_min = (int)split(cmd_str, '-', 3).toInt(); night_mode_times_cpst->end_min = (int)split(cmd_str, '-', 3).toInt();
brightness_ps->static_brightness = (uint8_t)split(cmd_str, '-', 4).toInt(); brightness_cpst->static_brightness = (uint8_t)split(cmd_str, '-', 4).toInt();
flg_reset_wifi_creds = split(cmd_str, '-', 5).toInt() > 0 ? true : false; flg_reset_wifi_creds = split(cmd_str, '-', 5).toInt() > 0 ? true : false;
brightness_ps->dyn_brightness_min = (uint8_t)split(cmd_str, '-', 6).toInt(); brightness_cpst->dyn_brightness_min = (uint8_t)split(cmd_str, '-', 6).toInt();
brightness_ps->dyn_brightness_max = (uint8_t)split(cmd_str, '-', 7).toInt(); brightness_cpst->dyn_brightness_max = (uint8_t)split(cmd_str, '-', 7).toInt();
if (flg_reset_wifi_creds == true) if (flg_reset_wifi_creds == true)
{ {
@@ -788,9 +788,9 @@ void handle_command()
// Update EEPROM with new settings // Update EEPROM with new settings
write_settings_to_EEPROM(); write_settings_to_EEPROM();
logger.log_string("Nightmode starts at: " + String(night_mode_times_ps->start_hour) + ":" + String(night_mode_times_ps->start_min)); logger.log_string("Nightmode starts at: " + String(night_mode_times_cpst->start_hour) + ":" + String(night_mode_times_cpst->start_min));
delay(10); delay(10);
logger.log_string("Nightmode ends at: " + String(night_mode_times_ps->end_hour) + ":" + String(night_mode_times_ps->end_min)); logger.log_string("Nightmode ends at: " + String(night_mode_times_cpst->end_hour) + ":" + String(night_mode_times_cpst->end_min));
delay(10); delay(10);
// Update brightness // Update brightness
@@ -906,17 +906,17 @@ void handle_data_request()
message += ","; message += ",";
message += "\"night_mode\":\"" + String(flg_night_mode) + "\""; message += "\"night_mode\":\"" + String(flg_night_mode) + "\"";
message += ","; message += ",";
message += "\"nightModeStart\":\"" + leading_zero2digit(night_mode_times_ps->start_hour) + "-" + leading_zero2digit(night_mode_times_ps->start_min) + "\""; message += "\"nightModeStart\":\"" + leading_zero2digit(night_mode_times_cpst->start_hour) + "-" + leading_zero2digit(night_mode_times_cpst->start_min) + "\"";
message += ","; message += ",";
message += "\"nightModeEnd\":\"" + leading_zero2digit(night_mode_times_ps->end_hour) + "-" + leading_zero2digit(night_mode_times_ps->end_min) + "\""; message += "\"nightModeEnd\":\"" + leading_zero2digit(night_mode_times_cpst->end_hour) + "-" + leading_zero2digit(night_mode_times_cpst->end_min) + "\"";
message += ","; message += ",";
message += "\"static_brightness\":\"" + String(brightness_ps->static_brightness) + "\""; message += "\"static_brightness\":\"" + String(brightness_cpst->static_brightness) + "\"";
message += ","; message += ",";
message += "\"dyn_brightness\":\"" + String(brightness_ps->flg_dynamic_brightness) + "\""; message += "\"dyn_brightness\":\"" + String(brightness_cpst->flg_dynamic_brightness) + "\"";
message += ","; message += ",";
message += "\"min_brightness\":\"" + String(brightness_ps->dyn_brightness_min) + "\""; message += "\"min_brightness\":\"" + String(brightness_cpst->dyn_brightness_min) + "\"";
message += ","; message += ",";
message += "\"max_brightness\":\"" + String(brightness_ps->dyn_brightness_max) + "\""; message += "\"max_brightness\":\"" + String(brightness_cpst->dyn_brightness_max) + "\"";
} }
message += "}"; message += "}";
webserver.send(200, "application/json", message); webserver.send(200, "application/json", message);
@@ -942,7 +942,7 @@ void set_night_mode(bool state)
*/ */
void set_dynamic_brightness(bool state) void set_dynamic_brightness(bool state)
{ {
brightness_ps->flg_dynamic_brightness = state; brightness_cpst->flg_dynamic_brightness = state;
} }
/** /**
@@ -1012,7 +1012,7 @@ uint8_t calculate_dynamic_brightness(uint8_t min_brightness, uint8_t max_brightn
*/ */
void read_settings_from_EEPROM() void read_settings_from_EEPROM()
{ {
EEPROM.get(0, eeprom_buffer); EEPROM.get(0, eeprom_buffer_st);
} }
/** /**
@@ -1023,7 +1023,7 @@ void read_settings_from_EEPROM()
void write_settings_to_EEPROM() void write_settings_to_EEPROM()
{ {
// Copy EEPROM buffer // Copy EEPROM buffer
EEPROM.put(0, eeprom_buffer); EEPROM.put(0, eeprom_buffer_st);
// Commit changes // Commit changes
EEPROM.commit(); EEPROM.commit();
} }
@@ -1037,17 +1037,17 @@ uint8_t update_brightness()
{ {
uint8_t new_brightness = 0; uint8_t new_brightness = 0;
if (brightness_ps->flg_dynamic_brightness == true) if (brightness_cpst->flg_dynamic_brightness == true)
{ {
new_brightness = calculate_dynamic_brightness(brightness_ps->dyn_brightness_min, new_brightness = calculate_dynamic_brightness(brightness_cpst->dyn_brightness_min,
brightness_ps->dyn_brightness_max, brightness_cpst->dyn_brightness_max,
tm_mgr.hour(), tm_mgr.hour(),
tm_mgr.minute(), tm_mgr.minute(),
tm_mgr.isdst()); tm_mgr.isdst());
} }
else // use static brightness else // use static brightness
{ {
new_brightness = brightness_ps->static_brightness; new_brightness = brightness_cpst->static_brightness;
} }
// now set new brightness // now set new brightness
led_matrix.set_brightness(new_brightness); led_matrix.set_brightness(new_brightness);
@@ -1063,30 +1063,30 @@ uint8_t update_brightness()
void limit_value_ranges() void limit_value_ranges()
{ {
// Range limits // Range limits
brightness_ps->dyn_brightness_min = RANGE_LIMIT(brightness_ps->dyn_brightness_min, brightness_cpst->dyn_brightness_min = RANGE_LIMIT(brightness_cpst->dyn_brightness_min,
MIN_BRIGHTNESS, MIN_BRIGHTNESS,
brightness_ps->dyn_brightness_max - 1); // minimum brightness brightness_cpst->dyn_brightness_max - 1); // minimum brightness
brightness_ps->dyn_brightness_max = RANGE_LIMIT(brightness_ps->dyn_brightness_max, brightness_cpst->dyn_brightness_max = RANGE_LIMIT(brightness_cpst->dyn_brightness_max,
brightness_ps->dyn_brightness_min + 1, brightness_cpst->dyn_brightness_min + 1,
MAX_BRIGHTNESS); // maximum brightness MAX_BRIGHTNESS); // maximum brightness
brightness_ps->static_brightness = RANGE_LIMIT(brightness_ps->static_brightness, brightness_cpst->static_brightness = RANGE_LIMIT(brightness_cpst->static_brightness,
MIN_BRIGHTNESS, MIN_BRIGHTNESS,
MAX_BRIGHTNESS); // static brightness MAX_BRIGHTNESS); // static brightness
night_mode_times_ps->start_hour = RANGE_LIMIT_SUB(night_mode_times_ps->start_hour, night_mode_times_cpst->start_hour = RANGE_LIMIT_SUB(night_mode_times_cpst->start_hour,
0,
HOUR_MAX,
NIGHTMODE_START_HR);
night_mode_times_cpst->start_min = RANGE_LIMIT_SUB(night_mode_times_cpst->start_min,
0,
MINUTE_MAX,
NIGHTMODE_START_MIN);
night_mode_times_cpst->end_hour = RANGE_LIMIT_SUB(night_mode_times_cpst->end_hour,
0, 0,
HOUR_MAX, HOUR_MAX,
NIGHTMODE_START_HR); NIGHTMODE_END_HR);
night_mode_times_ps->start_min = RANGE_LIMIT_SUB(night_mode_times_ps->start_min, night_mode_times_cpst->end_min = RANGE_LIMIT_SUB(night_mode_times_cpst->end_min,
0, 0,
MINUTE_MAX, MINUTE_MAX,
NIGHTMODE_START_MIN); NIGHTMODE_END_MIN);
night_mode_times_ps->end_hour = RANGE_LIMIT_SUB(night_mode_times_ps->end_hour,
0,
HOUR_MAX,
NIGHTMODE_END_HR);
night_mode_times_ps->end_min = RANGE_LIMIT_SUB(night_mode_times_ps->end_min,
0,
MINUTE_MAX,
NIGHTMODE_END_MIN);
} }