encapsulate hourFormat24 under a struct
This commit is contained in:
parent
dbaae667ec
commit
f10c456f68
@ -43,7 +43,7 @@ namespace Devices {
|
|||||||
|
|
||||||
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) {
|
||||||
strcmp("ON", msg) == 0 ? Display::changeHourFormat24(true) : Display::changeHourFormat24(false);
|
Display::hourFormat24 = (strcmp("ON", msg) == 0);
|
||||||
}
|
}
|
||||||
}).restoreStateFromCommand().build();
|
}).restoreStateFromCommand().build();
|
||||||
Number* displayTimerMqtt = Builder<Number>::instance(new Number{ "Timer duration", "timer_duration",
|
Number* displayTimerMqtt = Builder<Number>::instance(new Number{ "Timer duration", "timer_duration",
|
||||||
@ -131,7 +131,7 @@ namespace Devices {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Display::hourFormatChangedCallback = []{
|
Display::hourFormat24.changedCallback = []{
|
||||||
hourFormatMqtt->updateState(Display::hourFormat24);
|
hourFormatMqtt->updateState(Display::hourFormat24);
|
||||||
};
|
};
|
||||||
Display::brightness.changedCallback = []{
|
Display::brightness.changedCallback = []{
|
||||||
|
|||||||
@ -51,8 +51,21 @@ namespace Display {
|
|||||||
tDisplayTime.enable();
|
tDisplayTime.enable();
|
||||||
});
|
});
|
||||||
|
|
||||||
bool hourFormat24 = false;
|
struct HourFormat {
|
||||||
void (*hourFormatChangedCallback)();
|
void (*changedCallback)();
|
||||||
|
|
||||||
|
operator bool() {
|
||||||
|
return format24;
|
||||||
|
}
|
||||||
|
|
||||||
|
void operator=(bool value) {
|
||||||
|
format24 = value;
|
||||||
|
tDisplayTime.restart();
|
||||||
|
if (changedCallback) changedCallback();
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
bool format24 = false;
|
||||||
|
} hourFormat24;
|
||||||
|
|
||||||
// Create display object
|
// Create display object
|
||||||
Adafruit_7segment clockDisplay = Adafruit_7segment();
|
Adafruit_7segment clockDisplay = Adafruit_7segment();
|
||||||
@ -225,12 +238,6 @@ namespace Display {
|
|||||||
clockDisplay.writeDisplay();
|
clockDisplay.writeDisplay();
|
||||||
}
|
}
|
||||||
|
|
||||||
void changeHourFormat24(bool format24) {
|
|
||||||
hourFormat24 = format24;
|
|
||||||
tDisplayTime.restart();
|
|
||||||
if (hourFormatChangedCallback) hourFormatChangedCallback();
|
|
||||||
}
|
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
clockDisplay.begin(DISPLAY_ADDRESS);
|
clockDisplay.begin(DISPLAY_ADDRESS);
|
||||||
clockDisplay.setBrightness(brightness);
|
clockDisplay.setBrightness(brightness);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user