From 427faf280e43a21c3422fd5b128ff3f9ddd73b0f Mon Sep 17 00:00:00 2001 From: Fabian Schlenz Date: Thu, 23 May 2019 22:14:15 +0200 Subject: [PATCH] sinematrix3 will now be shown with a masked clock. --- effects.h | 52 ++++++++++++++++++++++++---------------------------- pitrix.ino | 9 +++++---- text.h | 9 +++++---- 3 files changed, 34 insertions(+), 36 deletions(-) diff --git a/effects.h b/effects.h index e17e166..2db6041 100644 --- a/effects.h +++ b/effects.h @@ -4,6 +4,8 @@ class Effect { public: virtual void loop() = 0; boolean supports_window = false; + virtual boolean can_be_shown_with_clock() { return false; }; + virtual boolean clock_as_mask() { return false; }; void setWindow(Window win) { window = win; }; @@ -86,42 +88,34 @@ class BigClock : public Effect { class Clock : public Effect { private: - CRGB color_h = CRGB(0xFF0000); - CRGB color_m = CRGB(0x00FF00); - CRGB color_colon = CRGB(0xFFFF00); - Effect* secondary_effect = 0; Window window = {0, LED_HEIGHT - 5, LED_WIDTH, 5}; - Window secondary_window = {0, 0, LED_WIDTH, LED_HEIGHT - 6}; - long secondary_effect_started_at = 0; public: - EffectEntry* effects; - void setEffects(EffectEntry* e) { - effects = e; - } Clock() {} - - void loop() { - clear(window); + void loop() { loop(false, CRGB(0xFFFFFF), CRGB(0x000000)); } + void loop(boolean invert, CRGB fg_color, CRGB bg_color) { + if (!invert) { + clear(window, bg_color); + } else { + // Manually clear the needed parts + for(int i=0; i EFFECT_CYCLE_TIME) { - secondary_effect = effects[0].effect; - secondary_effect_started_at = millis(); - secondary_effect->setWindow(secondary_window); - } - - secondary_effect->loop(); } }; @@ -149,6 +143,8 @@ class Sinematrix3 : public Effect { public: boolean supports_window = true; + boolean can_be_shown_with_clock() { return true; }; + boolean clock_as_mask() { return true; }; Sinematrix3() {} void loop() { pangle = addmodpi( pangle, 0.0133 + (angle / 256) ); diff --git a/pitrix.ino b/pitrix.ino index b136b97..2e05734 100644 --- a/pitrix.ino +++ b/pitrix.ino @@ -65,8 +65,6 @@ void setup() { ntp_setup(); mqtt_setup(); Serial.println("Core * Setup complete"); - - clock.setEffects(&effects[0]); } Effect* current_effect = &clock; @@ -99,9 +97,12 @@ void loop() { EVERY_N_MILLISECONDS(1000 / FPS) { Serial.println("Core * loop running"); - //Serial.printf("Core * current_effect: %p\n", (void *)¤t_effect); - current_effect->loop(); + + if (current_effect->can_be_shown_with_clock()) { + clock.loop(current_effect->clock_as_mask(), CRGB(0xFFFFFF), CRGB(0x000000)); + } + FastLED.show(); } diff --git a/text.h b/text.h index 5e9bc77..4f6bc19 100644 --- a/text.h +++ b/text.h @@ -123,21 +123,22 @@ static unsigned char numbers3x5[] = { B11101, B10101, B11111, // 9 }; -void drawTextSprite(Window window, unsigned char* sprite, int w, int h, int xPos, int yPos, CRGB color) { +void drawTextSprite(Window window, unsigned char* sprite, int w, int h, int xPos, int yPos, CRGB color, boolean invert) { for (byte y=0; y>(h-1-y)&1)*255; + if (invert) on = !on; if (on) setPixel(window, x+xPos, y+yPos, color); } } void drawChar(Window window, unsigned char* font, int w, int h, int x, int y, char c, CRGB color) { unsigned char* sprite = &font[(c-32)*w]; - drawTextSprite(window, sprite, w, h, x, y, color); + drawTextSprite(window, sprite, w, h, x, y, color, false); } -void drawDigit(Window window, unsigned char* font, int w, int h, int x, int y, int digit, CRGB color) { +void drawDigit(Window window, unsigned char* font, int w, int h, int x, int y, int digit, CRGB color, boolean invert) { unsigned char* sprite = &font[digit*w]; - drawTextSprite(window, sprite, w, h, x, y, color); + drawTextSprite(window, sprite, w, h, x, y, color, invert); } void drawText(Window window, char *font, int w, int h, char *text, int x, int y, CRGB color) {