Joined SingleDynamicEffect and MultiDynamicEffect into one file and finally got different timings for both classes to work.

This commit is contained in:
Fabian Schlenz 2019-06-05 06:27:07 +02:00
parent b2ff3bdc54
commit 57815cb3bf
6 changed files with 50 additions and 73 deletions

View File

@ -1,6 +1,4 @@
#ifndef effect_single_dynamic_H
#define effect_single_dynamic_H
#pragma once
#include "Effect.h"
#include "config.h"
@ -8,15 +6,18 @@ class SingleDynamicEffect : public Effect {
protected:
static const int factor = 2;
static const int tile_count = LED_WIDTH/factor * LED_HEIGHT/factor;
int loopTime = 200;
CRGB tiles[tile_count];
CRGB old_tiles[tile_count];
uint8_t blend = 0;
public:
SingleDynamicEffect();
void init();
virtual void update();
boolean can_be_shown_with_clock();
virtual void loop();
void draw();
};
class MultiDynamicEffect : public SingleDynamicEffect {
public:
void loop();
};
#endif

View File

@ -1,12 +0,0 @@
#ifndef effect_multi_dynamic_H
#define effect_multi_dynamic_H
#include "effect_single_dynamic.h"
class MultiDynamicEffect : public SingleDynamicEffect {
public:
MultiDynamicEffect();
void update();
};
#endif

36
src/effect_dynamic.cpp Normal file
View File

@ -0,0 +1,36 @@
#include "effect_dynamic.h"
#include "functions.h"
#include "config.h"
SingleDynamicEffect::SingleDynamicEffect() {
init();
}
void SingleDynamicEffect::init() {
for (int i=0; i<tile_count; i++) tiles[i] = CHSV(baseHue + random8(64), 180, 255);
}
void SingleDynamicEffect::loop() {
EVERY_N_MILLISECONDS( EFFECT_SINGLE_DYNAMIC_LOOP_TIME ) {
tiles[random8(tile_count)] = CHSV(baseHue + random8(64), 180, 255);
}
this->draw();
}
void SingleDynamicEffect::draw() {
for (int x=0; x<window.w; x++) for (int y=0; y<window.h; y++) {
int index = y/2 * window.w/2 + x/2;
setPixel(window, x, y, tiles[index]);
}
}
boolean SingleDynamicEffect::can_be_shown_with_clock() {
return true;
}
void MultiDynamicEffect::loop() {
EVERY_N_MILLISECONDS( EFFECT_MULTI_DYNAMIC_LOOP_TIME ) {
for (int i=0; i<tile_count; i++) tiles[i] = CHSV(baseHue + random8(64), 180, 255);
}
this->draw();
}

View File

@ -1,12 +0,0 @@
#include "effect_multi_dynamic.h"
#include "effect_single_dynamic.h"
#include "config.h"
MultiDynamicEffect::MultiDynamicEffect() {
init();
loopTime = EFFECT_MULTI_DYNAMIC_LOOP_TIME;
}
void MultiDynamicEffect::update() {
for (int i=0; i<tile_count; i++) tiles[i] = CHSV(baseHue + random8(64), 180, 255);
}

View File

@ -1,38 +0,0 @@
#include "effect_single_dynamic.h"
#include "functions.h"
SingleDynamicEffect::SingleDynamicEffect() {
init();
loopTime = EFFECT_SINGLE_DYNAMIC_LOOP_TIME;
}
void SingleDynamicEffect::init() {
for (int i=0; i<tile_count; i++) tiles[i] = CHSV(baseHue + random8(64), 180, 255);
}
void SingleDynamicEffect::update() {
tiles[random8(tile_count)] = CHSV(baseHue + random8(64), 180, 255);
}
boolean SingleDynamicEffect::can_be_shown_with_clock() { return true; }
void SingleDynamicEffect::loop() {
/*EVERY_N_MILLISECONDS(loopTime) {
memcpy(old_tiles, tiles, tile_count*sizeof(CRGB));
blend = 0;
update();
}
for (int x=0; x<window.w; x++) for (int y=0; y<window.h; y++) {
int index = y/2 * window.w/2 + x/2;
setPixel(window, x, y, nblend(old_tiles[index], tiles[index], blend));
}
if (blend < 255) blend+=20;*/
EVERY_N_MILLISECONDS(loopTime) {
update();
}
for (int x=0; x<window.w; x++) for (int y=0; y<window.h; y++) {
int index = y/2 * window.w/2 + x/2;
setPixel(window, x, y, tiles[index]);
}
}

View File

@ -8,14 +8,14 @@
#include "effect_clock.h"
#include "effect_static.h"
#include "effect_animation.h"
#include "effect_single_dynamic.h"
#include "effect_multi_dynamic.h"
#include "effect_dynamic.h"
#include "effect_matrix.h"
#include "effect_twirl.h"
#include "effect_cycle.h"
#include "effect_confetti.h"
#include "effect_snake.h"
#include "effect_fire.h"
#include "effect_firework.h"
SimpleList<EffectEntry>* effects;
SimpleList<Effect*>* cycle_effects;
@ -26,9 +26,9 @@ BigClockEffect effect_big_clock;
//ClockEffect effect_clock; <-- generated as global variable in effects.h
BellEffect effect_bell;
StaticEffect effect_off(CRGB(0x000000));
AnimationEffect effect_anim_koopa(&animation_koopa, CRGB(0x000000), 0, 0);
AnimationEffect effect_anim_couple_rain(&animation_couple_rain, CRGB(0x000000), -8, -16);
AnimationEffect effect_anim_heart(&animation_heart, CRGB(0x000000), 0, 0);
AnimationEffect effect_anim_koopa(&animation_koopa, new CRGB(0x000000), 0, 0);
AnimationEffect effect_anim_couple_rain(&animation_couple_rain, new CRGB(0x000000), -8, -16);
AnimationEffect effect_anim_heart(&animation_heart, new CRGB(0x000000), 0, 0);
SingleDynamicEffect effect_single_dynamic;
MultiDynamicEffect effect_multi_dynamic;
MatrixEffect effect_matrix;
@ -37,6 +37,7 @@ TwirlEffect effect_twirl;
ConfettiEffect effect_confetti;
SnakeEffect effect_snake;
FireEffect effect_fire;
FireworkEffect effect_firework;
Effect* current_effect;
@ -60,6 +61,7 @@ void setup_effects() {
effects->add((EffectEntry){"confetti", (Effect *)&effect_confetti});
effects->add((EffectEntry){"snake", (Effect *)&effect_snake});
effects->add((EffectEntry){"fire", (Effect *)&effect_fire});
effects->add((EffectEntry){"firework", (Effect *)&effect_firework});
cycle_effects->add(&effect_sinematrix3);
cycle_effects->add(&effect_single_dynamic);