sinematrix3 will now be shown with a masked clock.

This commit is contained in:
Fabian Schlenz 2019-05-23 22:14:15 +02:00
parent 0e82f94846
commit 427faf280e
3 changed files with 34 additions and 36 deletions

View File

@ -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<window.w; i++) setPixel(i, window.y-1, bg_color);
for(int i=0; i<5; i++) {
setPixel(window, 3, i, bg_color);
setPixel(window, 7, i, bg_color);
setPixel(window, 8, i, bg_color);
setPixel(window, 12, i, bg_color);
}
}
int h = ntpClient.getHours();
drawDigit(window, numbers3x5, 3, 5, 0, 0, h / 10, color_h);
drawDigit(window, numbers3x5, 3, 5, 4, 0, h % 10, color_h);
drawDigit(window, numbers3x5, 3, 5, 0, 0, h / 10, invert ? bg_color : fg_color, invert);
drawDigit(window, numbers3x5, 3, 5, 4, 0, h % 10, invert ? bg_color : fg_color, invert);
int m = ntpClient.getMinutes();
drawDigit(window, numbers3x5, 3, 5, 9, 0, m / 10, color_m);
drawDigit(window, numbers3x5, 3, 5, 13, 0, m % 10, color_m);
drawDigit(window, numbers3x5, 3, 5, 9, 0, m / 10, invert ? bg_color : fg_color, invert);
drawDigit(window, numbers3x5, 3, 5, 13, 0, m % 10, invert ? bg_color : fg_color, invert);
if (ntpClient.getSeconds() & 1) {
setPixel(window, 7, 1, color_colon);
setPixel(window, 7, 3, color_colon);
setPixel(window, 7, 1, invert ? bg_color : fg_color);
setPixel(window, 7, 3, invert ? bg_color : fg_color);
}
// Change effect?
if (secondary_effect == 0 || secondary_effect_started_at == 0 || millis() - secondary_effect_started_at > 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) );

View File

@ -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 *)&current_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();
}

9
text.h
View File

@ -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; y++) for (byte x=0; x<w; x++) {
bool on = (sprite[x]>>(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) {