2019-05-29 22:49:54 +00:00
|
|
|
#include "effects.h"
|
2019-10-02 04:13:55 +00:00
|
|
|
#include "config.h"
|
2019-05-29 22:49:54 +00:00
|
|
|
#include "my_fastled.h"
|
|
|
|
#include "effect_bell.h"
|
|
|
|
#include "effect_sinematrix3.h"
|
|
|
|
#include "effect_big_clock.h"
|
|
|
|
#include "effect_clock.h"
|
|
|
|
#include "effect_static.h"
|
|
|
|
#include "effect_animation.h"
|
2019-06-05 04:27:07 +00:00
|
|
|
#include "effect_dynamic.h"
|
2019-05-29 22:49:54 +00:00
|
|
|
#include "effect_matrix.h"
|
|
|
|
#include "effect_twirl.h"
|
|
|
|
#include "effect_cycle.h"
|
2019-05-30 09:12:40 +00:00
|
|
|
#include "effect_confetti.h"
|
2019-05-31 03:45:07 +00:00
|
|
|
#include "effect_snake.h"
|
2019-06-04 03:58:23 +00:00
|
|
|
#include "effect_fire.h"
|
2019-06-05 04:27:07 +00:00
|
|
|
#include "effect_firework.h"
|
2019-06-14 03:32:17 +00:00
|
|
|
#include "effect_gol.h"
|
2019-06-15 12:18:35 +00:00
|
|
|
#include "effect_pixelclock.h"
|
2019-06-19 20:28:38 +00:00
|
|
|
#include "effect_dvd.h"
|
2019-09-25 04:24:24 +00:00
|
|
|
#include "effect_analogclock.h"
|
|
|
|
#include "effect_sines.h"
|
2019-09-25 04:41:52 +00:00
|
|
|
#include "effect_marquee.h"
|
2019-09-25 04:26:27 +00:00
|
|
|
#include "effect_blur2d.h"
|
2019-10-10 04:50:09 +00:00
|
|
|
#include "effect_tv_static.h"
|
2019-10-24 04:33:16 +00:00
|
|
|
#include "effect_lightspeed.h"
|
2020-04-30 04:51:02 +00:00
|
|
|
#include "effect_diamond.h"
|
2020-07-09 04:39:53 +00:00
|
|
|
#include "effect_tpm2_net.h"
|
2019-05-29 22:49:54 +00:00
|
|
|
|
2019-06-18 16:14:59 +00:00
|
|
|
Effect* current_effect;
|
2019-05-29 22:49:54 +00:00
|
|
|
|
|
|
|
ClockEffect effect_clock;
|
2019-12-21 13:21:31 +00:00
|
|
|
TimerEffect effect_timer;
|
2019-05-29 22:49:54 +00:00
|
|
|
|
2019-10-24 04:33:16 +00:00
|
|
|
// We're using 0 instead of false to get a better visual difference between true and false.
|
2020-04-29 18:17:34 +00:00
|
|
|
EffectEntry effects[] = {
|
2019-10-24 04:33:16 +00:00
|
|
|
/* 0 */ {"sinematrix3", true, [](){ return new Sinematrix3Effect(); }},
|
|
|
|
/* 1 */ {"big_clock", true, [](){ return new BigClockEffect(); }},
|
|
|
|
/* 2 */ {"clock", 0, [](){ return new ClockEffect(); }},
|
2020-04-29 18:17:34 +00:00
|
|
|
/* 3 */ {"bell", 0, [](){ return AnimationEffect::Blinker("/bell.pia", 300, 0xFFFF00); }},
|
2019-10-24 04:33:16 +00:00
|
|
|
/* 4 */ {"off", 0, [](){ return new StaticEffect(0x000000); }},
|
|
|
|
/* 5 */ {"single_dynamic", true, [](){ return new SingleDynamicEffect(); }},
|
|
|
|
/* 6 */ {"multi_dynamic", true, [](){ return new MultiDynamicEffect(); }},
|
|
|
|
/* 7 */ {"big_dynamic", true, [](){ return new BigDynamicEffect(); }},
|
|
|
|
/* 8 */ {"matrix", true, [](){ return new MatrixEffect(); }},
|
|
|
|
/* 9 */ {"random_matrix", true, [](){ return new RandomMatrixEffect(); }},
|
|
|
|
/* 10 */ {"rainbow_matrix", true, [](){ return new RainbowMatrixEffect(); }},
|
|
|
|
/* 11 */ {"cycle", 0, [](){ return new CycleEffect(); }},
|
|
|
|
/* 12 */ {"twirl", true, [](){ return new TwirlEffect(); }},
|
|
|
|
/* 13 */ {"confetti", true, [](){ return new ConfettiEffect(); }},
|
|
|
|
/* 14 */ {"random_confetti", true, [](){ return new RandomConfettiEffect(); }},
|
|
|
|
/* 15 */ {"snake", true, [](){ return new SnakeEffect(); }},
|
|
|
|
/* 16 */ {"firework", true, [](){ return new FireworkEffect(); }},
|
|
|
|
/* 17 */ {"gol", true, [](){ return new GolEffect(); }},
|
|
|
|
/* 18 */ {"pixel_clock", 0, [](){ return new PixelClockEffect(); }},
|
2020-04-30 04:52:31 +00:00
|
|
|
/* 19 */ {"dvd", true, [](){ return new DvdEffect(); }},
|
2019-10-24 04:33:16 +00:00
|
|
|
/* 20 */ {"analog_clock", 0, [](){ return new AnalogClockEffect(); }},
|
|
|
|
/* 21 */ {"sines", true, [](){ return new SinesEffect(); }},
|
|
|
|
/* 22 */ {"blur2d", true, [](){ return new Blur2DEffect(); }},
|
|
|
|
/* 23 */ {"marquee", 0, [](){ return new MarqueeEffect(); }},
|
|
|
|
/* 24 */ {"night_clock", 0, [](){ return new NightClockEffect(); }},
|
|
|
|
/* 25 */ {"tv_static", 0, [](){ return new TvStaticEffect(); }},
|
|
|
|
/* 26 */ {"sinematrix3_rainbow", true, [](){ return new Sinematrix3Effect(SINEMATRIX_COLOR_RAINBOW); }},
|
|
|
|
/* 27 */ {"sinematrix3_purplefly", true, [](){ return new Sinematrix3Effect(SINEMATRIX_COLOR_PURPLEFLY); }},
|
|
|
|
/* 28 */ {"lightspeed", true, [](){ return new LightspeedEffect(); }},
|
2020-04-29 18:27:16 +00:00
|
|
|
/* 29 */ {"koopa", 0, [](){ return new AnimationEffect("/koopa.pia"); }},
|
|
|
|
/* 30 */ {"cake", 0, [](){ return new AnimationEffect("/cake.pia"); }},
|
2020-07-09 04:42:04 +00:00
|
|
|
/* 31 */ {"child", 0, [](){ return AnimationEffect::Blinker("/child.pia", 300, 0xFFFF00); }},
|
2020-04-30 04:51:02 +00:00
|
|
|
/* 32 */ {"diamond", true, [](){ return new DiamondEffect(); }},
|
2020-07-09 04:39:53 +00:00
|
|
|
/* 33 */ {"tpm2.net", 0, [](){ return new Tpm2NetEffect(); }},
|
2019-10-02 04:16:07 +00:00
|
|
|
};
|
2020-07-09 04:39:53 +00:00
|
|
|
const uint8_t effects_size = 34;
|
2019-10-02 04:16:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
Effect* select_effect(const char* name) {
|
|
|
|
for(int i=0; i<effects_size; i++) {
|
|
|
|
if (strcmp(effects[i].name, name)==0) {
|
|
|
|
return effects[i].create();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
Effect* select_effect(uint8_t id) {
|
|
|
|
if (id < effects_size) {
|
|
|
|
return effects[id].create();
|
|
|
|
}
|
|
|
|
return NULL;
|
2019-06-18 16:14:59 +00:00
|
|
|
}
|
2019-05-29 22:49:54 +00:00
|
|
|
|
2019-06-19 20:28:38 +00:00
|
|
|
bool change_current_effect(String payload) {
|
|
|
|
int pos = payload.indexOf(",");
|
|
|
|
String options = "";
|
|
|
|
if (pos != -1) {
|
|
|
|
LOGln("Effects * Effect comes with options.");
|
|
|
|
options = payload.substring(pos+1);
|
|
|
|
payload.remove(pos);
|
|
|
|
LOGln("Effects * Cleaned effect name: %s", payload.c_str());
|
|
|
|
}
|
|
|
|
|
2019-10-02 04:16:07 +00:00
|
|
|
Effect* new_effect = select_effect( payload.c_str() );
|
2019-06-19 20:28:38 +00:00
|
|
|
if (new_effect == NULL) {
|
|
|
|
LOGln("Effects * Could not find effect with name %s", payload.c_str());
|
|
|
|
return false;
|
|
|
|
}
|
2019-09-04 04:06:47 +00:00
|
|
|
LOGln("Effects * Switching to effect %s", payload.c_str());
|
2019-06-18 16:14:59 +00:00
|
|
|
delete current_effect;
|
|
|
|
current_effect = new_effect;
|
2019-06-19 20:28:38 +00:00
|
|
|
|
|
|
|
if (options.length() > 0) {
|
|
|
|
LOGln("Effects * Parsing options: %s", options.c_str());
|
|
|
|
options += ",";
|
|
|
|
int p_colon;
|
|
|
|
while ((p_colon = options.indexOf(",")) >= 0) {
|
|
|
|
int p_equal = options.indexOf("=");
|
|
|
|
if (p_equal >= 0 && p_equal < p_colon) {
|
|
|
|
String key = options.substring(0, p_equal);
|
|
|
|
String value = options.substring(p_equal + 1, p_colon);
|
|
|
|
LOGln("Effects * Applying option: %s = %s", key.c_str(), value.c_str());
|
|
|
|
current_effect->apply_option(key, value);
|
|
|
|
}
|
|
|
|
options.remove(0, p_colon + 1);
|
|
|
|
}
|
|
|
|
}
|
2019-06-18 16:14:59 +00:00
|
|
|
return true;
|
|
|
|
}
|
2019-05-29 22:49:54 +00:00
|
|
|
|
2019-06-18 16:14:59 +00:00
|
|
|
void setup_effects() {
|
|
|
|
current_effect = new CycleEffect();
|
2019-05-29 22:49:54 +00:00
|
|
|
}
|