move brightness defines inside the struct
This commit is contained in:
parent
4e9f6c1116
commit
6e608da1f0
@ -39,7 +39,7 @@ namespace Devices {
|
|||||||
[](const char* msg) {
|
[](const char* msg) {
|
||||||
Display::brightness = String{ msg }.toInt();
|
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",
|
auto hourFormatMqtt = Builder<Switch>::instance(new Switch{ "Format 24h", "format_24h",
|
||||||
[](const char* msg) {
|
[](const char* msg) {
|
||||||
|
|||||||
@ -8,11 +8,6 @@
|
|||||||
#include "bme.h"
|
#include "bme.h"
|
||||||
|
|
||||||
#define DISPLAY_ADDRESS 0x70
|
#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 MILLISECONDS(value) value*TASK_MILLISECOND
|
||||||
#define SECONDS(value) value*TASK_SECOND
|
#define SECONDS(value) value*TASK_SECOND
|
||||||
#define MINUTES(value) value*TASK_MINUTE
|
#define MINUTES(value) value*TASK_MINUTE
|
||||||
@ -62,13 +57,16 @@ namespace Display {
|
|||||||
// Create display object
|
// Create display object
|
||||||
Adafruit_7segment clockDisplay = Adafruit_7segment();
|
Adafruit_7segment clockDisplay = Adafruit_7segment();
|
||||||
|
|
||||||
class Brightness {
|
struct Brightness {
|
||||||
uint8 current = BRIGHTNESS_NIGHT;
|
static constexpr uint8 MIN = 0;
|
||||||
public:
|
static constexpr uint8 MAX = 15;
|
||||||
|
static constexpr uint8 STEP = 1;
|
||||||
|
static constexpr uint8 DAY = 11;
|
||||||
|
static constexpr uint8 NIGHT = MIN;
|
||||||
void (*changedCallback)();
|
void (*changedCallback)();
|
||||||
|
|
||||||
void operator=(uint8 value) {
|
void operator=(uint8 value) {
|
||||||
current = value % (BRIGHTNESS_MAX + 1);
|
current = value % (MAX + 1);
|
||||||
clockDisplay.setBrightness(current);
|
clockDisplay.setBrightness(current);
|
||||||
if (changedCallback) changedCallback();
|
if (changedCallback) changedCallback();
|
||||||
}
|
}
|
||||||
@ -78,8 +76,11 @@ namespace Display {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void change(bool increase) {
|
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;
|
} brightness;
|
||||||
|
|
||||||
namespace Timer {
|
namespace Timer {
|
||||||
@ -160,11 +161,11 @@ namespace Display {
|
|||||||
Ntp::tUpdateTime.restart();
|
Ntp::tUpdateTime.restart();
|
||||||
}
|
}
|
||||||
if (currentHour == 8) {
|
if (currentHour == 8) {
|
||||||
brightness = BRIGHTNESS_DAY;
|
brightness = Brightness::DAY;
|
||||||
Wifi::tConnect.enable();
|
Wifi::tConnect.enable();
|
||||||
}
|
}
|
||||||
if (currentHour == 17) {
|
if (currentHour == 17) {
|
||||||
brightness = BRIGHTNESS_NIGHT;
|
brightness = Brightness::NIGHT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static int currentMin = -1;
|
static int currentMin = -1;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user