diff --git a/include/effect_clock.h b/include/effect_clock.h index bc37721..73e0f8d 100644 --- a/include/effect_clock.h +++ b/include/effect_clock.h @@ -6,12 +6,19 @@ #include "Window.h" class ClockEffect : public Effect { -private: +protected: Window* window = new Window(0, LED_HEIGHT - 6, LED_WIDTH, 6); public: ~ClockEffect(); - void loop(); - void loop(boolean invert, CRGB fg_color, CRGB bg_color); + virtual void loop(); String get_name() override { return "clock"; } + 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(); + void loop() override; }; diff --git a/src/effect_clock.cpp b/src/effect_clock.cpp index 2866a1c..adaadbd 100644 --- a/src/effect_clock.cpp +++ b/src/effect_clock.cpp @@ -4,23 +4,41 @@ #include "fonts.h" #include "ntp.h" -void ClockEffect::loop() { - loop(false, CRGB(0xFFFFFF), CRGB(0x000000)); +NightClockEffect::NightClockEffect() { + window = Window::getFullWindow(); } -void ClockEffect::loop(boolean invert, CRGB fg_color, CRGB bg_color) { +void NightClockEffect::loop() { + 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(0x880000), CRGB(0x000000), y); +} + +void ClockEffect::loop() { + loop_with_invert(false); +} + +void ClockEffect::loop_with_invert(bool invert) { + // Clear the first line to have a bit of space to the other stuff on screen + CRGB bg_color(0x000000); + for(int i=0; iwidth; i++) window->setPixel(i, 0, &bg_color); + loop(invert, CRGB(0xFFFFFF), bg_color, 1); +} + +void ClockEffect::loop(boolean invert, CRGB fg_color, CRGB bg_color, uint8_t yPos) { if (!invert) { window->clear(&bg_color); } else { // Manually clear the needed parts - for(int i=0; iwidth; i++) window->setPixel(i, 0, &bg_color); for(int y=0; y<6; y++) { - window->setPixel(3, y, &bg_color); + window->setPixel(3, yPos+y, &bg_color); if (y!=2 && y!=4) { - window->setPixel(7, y, &bg_color); + window->setPixel(7, yPos+y, &bg_color); } - window->setPixel(8, y, &bg_color); - window->setPixel(12, y, &bg_color); + window->setPixel(8, yPos+y, &bg_color); + window->setPixel(12, yPos+y, &bg_color); } fg_color = bg_color; } @@ -30,14 +48,14 @@ void ClockEffect::loop(boolean invert, CRGB fg_color, CRGB bg_color) { } int h = ntpClient.getHours(); //void drawChar(Font f, uint8_t x, uint8_t y, const char c, CRGB* color, bool mask=false); - window->drawChar(&font_numbers3x5, 0<<8, 1<<8, '0' + (h / 10), &fg_color, invert); - window->drawChar(&font_numbers3x5, 4<<8, 1<<8, '0' + (h % 10), &fg_color, invert); + window->drawChar(&font_numbers3x5, 0<<8, yPos<<8, '0' + (h / 10), &fg_color, invert); + window->drawChar(&font_numbers3x5, 4<<8, yPos<<8, '0' + (h % 10), &fg_color, invert); int m = ntpClient.getMinutes(); - window->drawChar(&font_numbers3x5, 9<<8, 1<<8, '0' + (m / 10), &fg_color, invert); - window->drawChar(&font_numbers3x5, 13<<8, 1<<8, '0' + (m % 10), &fg_color, invert); + window->drawChar(&font_numbers3x5, 9<<8, yPos<<8, '0' + (m / 10), &fg_color, invert); + window->drawChar(&font_numbers3x5, 13<<8, yPos<<8, '0' + (m % 10), &fg_color, invert); if (ntpClient.getSeconds() & 1) { - window->setPixel(7, 2, &fg_color); - window->setPixel(7, 4, &fg_color); + window->setPixel(7, yPos+1, &fg_color); + window->setPixel(7, yPos+3, &fg_color); } } diff --git a/src/effects.cpp b/src/effects.cpp index 1548fdc..e2da49e 100644 --- a/src/effects.cpp +++ b/src/effects.cpp @@ -59,6 +59,7 @@ Effect* select_effect(uint32_t code) { case 26: case 0xADB18CC5 /* sines */ : return new SinesEffect(); case 27: case 0x0407881E /* blur2d */ : return new Blur2DEffect(); case 28: case 0x935CFA7C /* marquee */ : return new MarqueeEffect(); + case 29: case 0xE27D739E /* night_clock */ : return new NightClockEffect(); default : return NULL; }; } diff --git a/src/pitrix.cpp b/src/pitrix.cpp index 6f902bc..9ade2a6 100644 --- a/src/pitrix.cpp +++ b/src/pitrix.cpp @@ -92,7 +92,7 @@ void loop() { //LOGln("Core * loop ran"); if (current_effect->can_be_shown_with_clock()) { - effect_clock.loop(current_effect->clock_as_mask(), CRGB(0xFFFFFF), CRGB(0x000000)); + effect_clock.loop_with_invert(current_effect->clock_as_mask()); } FastLED.show(); #ifdef MQTT_REPORT_METRICS