From 6e608da1f035068946044516e85292902e415d3f Mon Sep 17 00:00:00 2001 From: Nicu Hodos Date: Mon, 10 Feb 2025 10:27:07 +0100 Subject: [PATCH] move brightness defines inside the struct --- include/devices.h | 2 +- include/display.h | 25 +++++++++++++------------ 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/include/devices.h b/include/devices.h index 9ef1228..3d0a1d0 100644 --- a/include/devices.h +++ b/include/devices.h @@ -39,7 +39,7 @@ namespace Devices { [](const char* msg) { Display::brightness = String{ msg }.toInt(); } - }).withMin(BRIGHTNESS_MIN).withMax(BRIGHTNESS_MAX).withStep(BRIGHTNESS_STEP).restoreStateFromCommand().build(); + }).withMin(Display::Brightness::MIN).withMax(Display::Brightness::MAX).withStep(Display::Brightness::STEP).restoreStateFromCommand().build(); auto hourFormatMqtt = Builder::instance(new Switch{ "Format 24h", "format_24h", [](const char* msg) { diff --git a/include/display.h b/include/display.h index 28b50f1..b2b5c2c 100644 --- a/include/display.h +++ b/include/display.h @@ -8,11 +8,6 @@ #include "bme.h" #define DISPLAY_ADDRESS 0x70 -#define BRIGHTNESS_MIN 0 -#define BRIGHTNESS_MAX 15 -#define BRIGHTNESS_STEP 1 -#define BRIGHTNESS_NIGHT BRIGHTNESS_MIN -#define BRIGHTNESS_DAY 11 #define MILLISECONDS(value) value*TASK_MILLISECOND #define SECONDS(value) value*TASK_SECOND #define MINUTES(value) value*TASK_MINUTE @@ -62,13 +57,16 @@ namespace Display { // Create display object Adafruit_7segment clockDisplay = Adafruit_7segment(); - class Brightness { - uint8 current = BRIGHTNESS_NIGHT; - public: + struct Brightness { + static constexpr uint8 MIN = 0; + static constexpr uint8 MAX = 15; + static constexpr uint8 STEP = 1; + static constexpr uint8 DAY = 11; + static constexpr uint8 NIGHT = MIN; void (*changedCallback)(); void operator=(uint8 value) { - current = value % (BRIGHTNESS_MAX + 1); + current = value % (MAX + 1); clockDisplay.setBrightness(current); if (changedCallback) changedCallback(); } @@ -78,8 +76,11 @@ namespace Display { } void change(bool increase) { - increase ? *this = current + BRIGHTNESS_STEP : *this = current - BRIGHTNESS_STEP; + increase ? *this = current + STEP : *this = current - STEP; } + + private: + uint8 current = NIGHT; } brightness; namespace Timer { @@ -160,11 +161,11 @@ namespace Display { Ntp::tUpdateTime.restart(); } if (currentHour == 8) { - brightness = BRIGHTNESS_DAY; + brightness = Brightness::DAY; Wifi::tConnect.enable(); } if (currentHour == 17) { - brightness = BRIGHTNESS_NIGHT; + brightness = Brightness::NIGHT; } } static int currentMin = -1;