Changed NightClock to be a special form of BigClock.

This commit is contained in:
Fabian Schlenz 2020-04-29 20:19:26 +02:00
parent 1707084299
commit f014fd7cae
4 changed files with 33 additions and 38 deletions

View File

@ -3,17 +3,27 @@
#include "Effect.h"
class BigClockEffect : public Effect {
private:
protected:
CRGB _color_font = CRGB(0xAAAAAA);
CRGB _color_seconds_light = CRGB(0xFFFF00);
CRGB _color_seconds_dark = CRGB(0xAA0000);
CRGB _color_seconds_moving_light = CRGB(0x666600);
CRGB _color_seconds_moving_dark = CRGB(0x660000);
virtual CRGB _get_color_font() { return CRGB(0xAAAAAA); }
void _draw_seconds(uint8_t seconds);
void _draw_border_pixel(accum88 pos, CRGB* color);
virtual void _draw_border_pixel(accum88 pos, CRGB* color);
void _draw_colon(bool odd);
public:
void loop(uint16_t ms);
virtual void loop(uint16_t ms);
String get_name() override { return "big_clock"; }
};
class NightClockEffect : public BigClockEffect {
private:
CRGB _color_font = CRGB(0x440000);
CRGB _color_colon = CRGB(0x000000);
void _draw_border_pixel(accum88 pos, CRGB* color) { };
CRGB _get_color_font() { return CRGB(0x440000); }
};

View File

@ -16,10 +16,3 @@ public:
void loop_with_invert(bool invert);
void loop(boolean invert, CRGB fg_color, CRGB bg_color, uint8_t y);
};
class NightClockEffect : public ClockEffect {
public:
NightClockEffect();
~NightClockEffect();
void loop(uint16_t ms) override;
};

View File

@ -11,35 +11,43 @@ void BigClockEffect::loop(uint16_t ms) {
time(&now);
localtime_r(&now, &timeinfo);
uint8_t h = timeinfo.tm_hour;
window->drawChar(&font_numbers3x5_blocky, 6<<8, 2<<8, '0' + (h / 10), &_color_font);
window->drawChar(&font_numbers3x5_blocky, 11<<8, 2<<8, '0' + (h % 10), &_color_font);
CRGB color = _get_color_font();
window->drawChar(&font_numbers3x5_blocky, 6<<8, 2<<8, '0' + (h / 10), &color);
window->drawChar(&font_numbers3x5_blocky, 11<<8, 2<<8, '0' + (h % 10), &color);
uint8_t m = timeinfo.tm_min;
window->drawChar(&font_numbers3x5_blocky, 6<<8, 9<<8, '0' + (m / 10), &_color_font);
window->drawChar(&font_numbers3x5_blocky, 11<<8, 9<<8, '0' + (m % 10), &_color_font);
window->drawChar(&font_numbers3x5_blocky, 6<<8, 9<<8, '0' + (m / 10), &color);
window->drawChar(&font_numbers3x5_blocky, 11<<8, 9<<8, '0' + (m % 10), &color);
uint8_t s = timeinfo.tm_sec;
if (s & 1) {
window->setPixel(3, 10, &_color_font);
window->setPixel(3, 12, &_color_font);
}
_draw_colon(s & 1);
_draw_seconds(timeinfo.tm_sec);
}
void BigClockEffect::_draw_colon(bool odd) {
if (odd) {
CRGB color = _get_color_font();
window->setPixel(3, 10, &color);
window->setPixel(3, 12, &color);
}
}
void BigClockEffect::_draw_seconds(uint8_t seconds) {
for (int i=1; i<=seconds; i++) {
_draw_border_pixel(i<<8, (i%5==0) ? &_color_seconds_light : &_color_seconds_dark);
}
uint16_t mil = millis() % 1000;
/*timeval tv;
gettimeofday(&tv, nullptr);
uint16_t mil = (tv.tv_usec / 1000) % 1000;
accum88 pos = (seconds<<8) + ((settings.effects.big_clock.spacing-1)<<8) * (1000 - mil) / 1000 + (1<<8);
uint8_t sec = seconds + 1;
while (pos < (60<<8)) {
_draw_border_pixel(pos, sec%5==0 ? &_color_seconds_moving_light : &_color_seconds_moving_dark);
pos += settings.effects.big_clock.spacing<<8;
sec++;
}
}*/
}
void BigClockEffect::_draw_border_pixel(accum88 i, CRGB* color) {

View File

@ -4,18 +4,6 @@
#include "fonts.h"
#include "ntp.h"
NightClockEffect::NightClockEffect() {
window = Window::getFullWindow();
}
void NightClockEffect::loop(uint16_t ms) {
uint16_t minutes = minutes16();
//uint8_t y = minutes % ((window->height - 5) * 2 - 2);
//if (y > window->height - 5) y = 2*window->height - 2*y;
uint8_t y = minutes % 10;
ClockEffect::loop(false, CRGB(0x200000), CRGB(0x000000), y);
}
void ClockEffect::loop(uint16_t ms) {
loop_with_invert(false);
}
@ -66,7 +54,3 @@ void ClockEffect::loop(boolean invert, CRGB fg_color, CRGB bg_color, uint8_t yPo
ClockEffect::~ClockEffect() {
delete window;
}
NightClockEffect::~NightClockEffect() {
delete window;
}