From f014fd7cae546c1d5d5f7965768141e4dc15d3c3 Mon Sep 17 00:00:00 2001 From: Fabian Schlenz Date: Wed, 29 Apr 2020 20:19:26 +0200 Subject: [PATCH] Changed NightClock to be a special form of BigClock. --- include/effect_big_clock.h | 18 ++++++++++++++---- include/effect_clock.h | 7 ------- src/effect_big_clock.cpp | 30 +++++++++++++++++++----------- src/effect_clock.cpp | 16 ---------------- 4 files changed, 33 insertions(+), 38 deletions(-) diff --git a/include/effect_big_clock.h b/include/effect_big_clock.h index c029c71..20dda87 100644 --- a/include/effect_big_clock.h +++ b/include/effect_big_clock.h @@ -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); } +}; diff --git a/include/effect_clock.h b/include/effect_clock.h index 343e951..fb0fc44 100644 --- a/include/effect_clock.h +++ b/include/effect_clock.h @@ -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; -}; diff --git a/src/effect_big_clock.cpp b/src/effect_big_clock.cpp index f6b95ef..4d93c99 100644 --- a/src/effect_big_clock.cpp +++ b/src/effect_big_clock.cpp @@ -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) { diff --git a/src/effect_clock.cpp b/src/effect_clock.cpp index df441aa..0fb587e 100644 --- a/src/effect_clock.cpp +++ b/src/effect_clock.cpp @@ -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; -} \ No newline at end of file