simplify display time task:
- drawTime onEnable - disable drawColon onDisable - don't display time at startup, by default temperature is displayed now
This commit is contained in:
parent
bdefbf23bc
commit
2bb9de1f61
@ -12,16 +12,20 @@
|
||||
#define BRIGHTNESS_STEP 1
|
||||
#define BRIGHTNESS_NIGHT BRIGHTNESS_MIN
|
||||
#define BRIGHTNESS_DAY 11
|
||||
#define DISPLAY_TIME 2000
|
||||
#define DISPLAY_TEMP_TIME 5000
|
||||
#define SECONDS(value) value*1000
|
||||
|
||||
namespace Display {
|
||||
|
||||
void display();
|
||||
Task tDisplay(500, TASK_FOREVER, display, &ts, true);
|
||||
void displayTime();
|
||||
void drawTime();
|
||||
void drawColon(bool);
|
||||
Task tDisplayTime(500, TASK_FOREVER, displayTime, &ts, false, []() {
|
||||
drawTime();
|
||||
return true;
|
||||
}, []() {
|
||||
drawColon(false);
|
||||
});
|
||||
|
||||
int currentHour = -1;
|
||||
int currentMin = -1;
|
||||
bool hourFormat24 = false;
|
||||
void (*hourFormatChangedCallback)();
|
||||
void onHourFormatChanged(void (*f)()) {
|
||||
@ -71,6 +75,7 @@ namespace Display {
|
||||
|
||||
void drawColon(bool colonOn) {
|
||||
if (colonOn) {
|
||||
static int currentHour = -1;
|
||||
if (currentHour != hour()) {
|
||||
currentHour = hour();
|
||||
if (currentHour == 8) {
|
||||
@ -81,6 +86,7 @@ namespace Display {
|
||||
Brightness::set(BRIGHTNESS_NIGHT);
|
||||
}
|
||||
}
|
||||
static int currentMin = -1;
|
||||
if (currentMin != minute()) {
|
||||
currentMin = minute();
|
||||
drawTime();
|
||||
@ -89,8 +95,8 @@ namespace Display {
|
||||
clockDisplay.drawColon(colonOn);
|
||||
}
|
||||
|
||||
void display() {
|
||||
static bool colonOn = false;
|
||||
void displayTime() {
|
||||
static bool colonOn = true;
|
||||
|
||||
drawColon(colonOn);
|
||||
clockDisplay.writeDisplay();
|
||||
@ -99,30 +105,24 @@ namespace Display {
|
||||
}
|
||||
|
||||
void displayTemp(float value) {
|
||||
tDisplay.disable();
|
||||
drawColon(false);
|
||||
tDisplayTime.disable();
|
||||
clockDisplay.printFloat(value, 1);
|
||||
clockDisplay.writeDisplay();
|
||||
drawTime();
|
||||
tDisplay.enableDelayed(DISPLAY_TEMP_TIME);
|
||||
tDisplayTime.enableDelayed(SECONDS(10));
|
||||
}
|
||||
|
||||
void displayValue(uint8_t value) {
|
||||
tDisplay.disable();
|
||||
drawColon(false);
|
||||
tDisplayTime.disable();
|
||||
clockDisplay.print(value, HEX);
|
||||
clockDisplay.writeDisplay();
|
||||
drawTime();
|
||||
tDisplay.enableDelayed(DISPLAY_TIME);
|
||||
tDisplayTime.enableDelayed(SECONDS(2));
|
||||
}
|
||||
|
||||
void displayText(const char c[]) {
|
||||
tDisplay.disable();
|
||||
drawColon(false);
|
||||
tDisplayTime.disable();
|
||||
clockDisplay.println(c);
|
||||
clockDisplay.writeDisplay();
|
||||
drawTime();
|
||||
tDisplay.enableDelayed(DISPLAY_TIME);
|
||||
tDisplayTime.enableDelayed(SECONDS(2));
|
||||
}
|
||||
|
||||
void changeHourFormat24(bool format24) {
|
||||
@ -134,7 +134,5 @@ namespace Display {
|
||||
void setup() {
|
||||
clockDisplay.begin(DISPLAY_ADDRESS);
|
||||
clockDisplay.setBrightness(Brightness::current);
|
||||
drawTime();
|
||||
display();
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user