move brightness defines inside the struct

This commit is contained in:
Nicu Hodos 2025-02-10 10:27:07 +01:00
parent 4e9f6c1116
commit 6e608da1f0
2 changed files with 14 additions and 13 deletions

View File

@ -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<Switch>::instance(new Switch{ "Format 24h", "format_24h",
[](const char* msg) {

View File

@ -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;