make Brightness a class instead of namespace
This commit is contained in:
parent
0010f856aa
commit
4e9f6c1116
@ -37,7 +37,7 @@ namespace Devices {
|
|||||||
|
|
||||||
auto brightnessMqtt = Builder<Number>::instance(new Number{ "Brightness", "brightness",
|
auto brightnessMqtt = Builder<Number>::instance(new Number{ "Brightness", "brightness",
|
||||||
[](const char* msg) {
|
[](const char* msg) {
|
||||||
Display::Brightness::set(String{ msg }.toInt());
|
Display::brightness = String{ msg }.toInt();
|
||||||
}
|
}
|
||||||
}).withMin(BRIGHTNESS_MIN).withMax(BRIGHTNESS_MAX).withStep(BRIGHTNESS_STEP).restoreStateFromCommand().build();
|
}).withMin(BRIGHTNESS_MIN).withMax(BRIGHTNESS_MAX).withStep(BRIGHTNESS_STEP).restoreStateFromCommand().build();
|
||||||
|
|
||||||
@ -134,8 +134,8 @@ namespace Devices {
|
|||||||
Display::hourFormatChangedCallback = []{
|
Display::hourFormatChangedCallback = []{
|
||||||
hourFormatMqtt->updateState(Display::hourFormat24);
|
hourFormatMqtt->updateState(Display::hourFormat24);
|
||||||
};
|
};
|
||||||
Display::Brightness::brightnessChangedCallback = []{
|
Display::brightness.changedCallback = []{
|
||||||
brightnessMqtt->updateState(Display::Brightness::current);
|
brightnessMqtt->updateState(Display::brightness);
|
||||||
};
|
};
|
||||||
Display::Timer::remainingCallback = [](int8 current){
|
Display::Timer::remainingCallback = [](int8 current){
|
||||||
timerRemainingMqtt->updateState(to_string(current).c_str());
|
timerRemainingMqtt->updateState(to_string(current).c_str());
|
||||||
|
|||||||
@ -62,20 +62,25 @@ namespace Display {
|
|||||||
// Create display object
|
// Create display object
|
||||||
Adafruit_7segment clockDisplay = Adafruit_7segment();
|
Adafruit_7segment clockDisplay = Adafruit_7segment();
|
||||||
|
|
||||||
namespace Brightness {
|
class Brightness {
|
||||||
uint8_t current = BRIGHTNESS_NIGHT;
|
uint8 current = BRIGHTNESS_NIGHT;
|
||||||
void (*brightnessChangedCallback)();
|
public:
|
||||||
|
void (*changedCallback)();
|
||||||
|
|
||||||
void set(uint8_t value) {
|
void operator=(uint8 value) {
|
||||||
current = value % (BRIGHTNESS_MAX + 1);
|
current = value % (BRIGHTNESS_MAX + 1);
|
||||||
clockDisplay.setBrightness(current);
|
clockDisplay.setBrightness(current);
|
||||||
if (brightnessChangedCallback) brightnessChangedCallback();
|
if (changedCallback) changedCallback();
|
||||||
|
}
|
||||||
|
|
||||||
|
operator uint8() {
|
||||||
|
return current;
|
||||||
}
|
}
|
||||||
|
|
||||||
void change(bool increase) {
|
void change(bool increase) {
|
||||||
increase ? set(current + BRIGHTNESS_STEP) : set(current - BRIGHTNESS_STEP);
|
increase ? *this = current + BRIGHTNESS_STEP : *this = current - BRIGHTNESS_STEP;
|
||||||
}
|
}
|
||||||
}
|
} brightness;
|
||||||
|
|
||||||
namespace Timer {
|
namespace Timer {
|
||||||
int8 timer = 0, current = 0;
|
int8 timer = 0, current = 0;
|
||||||
@ -155,11 +160,11 @@ namespace Display {
|
|||||||
Ntp::tUpdateTime.restart();
|
Ntp::tUpdateTime.restart();
|
||||||
}
|
}
|
||||||
if (currentHour == 8) {
|
if (currentHour == 8) {
|
||||||
Brightness::set(BRIGHTNESS_DAY);
|
brightness = BRIGHTNESS_DAY;
|
||||||
Wifi::tConnect.enable();
|
Wifi::tConnect.enable();
|
||||||
}
|
}
|
||||||
if (currentHour == 17) {
|
if (currentHour == 17) {
|
||||||
Brightness::set(BRIGHTNESS_NIGHT);
|
brightness = BRIGHTNESS_NIGHT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static int currentMin = -1;
|
static int currentMin = -1;
|
||||||
@ -194,7 +199,7 @@ namespace Display {
|
|||||||
tDisplaySensor.setCallback(&displayTemp);
|
tDisplaySensor.setCallback(&displayTemp);
|
||||||
}
|
}
|
||||||
|
|
||||||
void displayValue(uint8_t value) {
|
void displayValue(uint8 value) {
|
||||||
tDisplayTime.disable();
|
tDisplayTime.disable();
|
||||||
clockDisplay.print(value, HEX);
|
clockDisplay.print(value, HEX);
|
||||||
clockDisplay.writeDisplay();
|
clockDisplay.writeDisplay();
|
||||||
@ -232,7 +237,7 @@ namespace Display {
|
|||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
clockDisplay.begin(DISPLAY_ADDRESS);
|
clockDisplay.begin(DISPLAY_ADDRESS);
|
||||||
clockDisplay.setBrightness(Brightness::current);
|
clockDisplay.setBrightness(brightness);
|
||||||
tDisplayTime.enable();
|
tDisplayTime.enable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user