pitrix/src/effects.cpp

138 lines
6.3 KiB
C++

#include "effects.h"
#include "config.h"
#include "my_fastled.h"
#include "effects/bell.h"
#include "effects/sinematrix3.h"
#include "effects/big_clock.h"
#include "effects/clock.h"
#include "effects/static.h"
#include "effects/animation.h"
#include "effects/dynamic.h"
#include "effects/matrix.h"
#include "effects/twirl.h"
#include "effects/cycle.h"
#include "effects/snake.h"
#include "effects/fire.h"
#include "effects/firework.h"
#include "effects/gol.h"
#include "effects/pixelclock.h"
#include "effects/dvd.h"
#include "effects/analogclock.h"
#include "effects/sines.h"
#include "effects/marquee.h"
#include "effects/blur2d.h"
#include "effects/tv_static.h"
#include "effects/lightspeed.h"
#include "effects/diamond.h"
#include "effects/tpm2_net.h"
#include "SimpleEffect.h"
#include "effects/night_clock.h"
Effect* current_effect;
ClockEffect effect_clock;
TimerEffect effect_timer;
// We're using 0 instead of false to get a better visual difference between true and false.
EffectEntry effects[] = {
/* 0 */ {"sinematrix3", true, [](){ return new Sinematrix3Effect(); }},
/* 1 */ {"big_clock", true, [](){ return new BigClockEffect(); }},
/* 2 */ {"clock", 0, [](){ return new ClockEffect(); }},
/* 3 */ {"bell", 0, [](){ return AnimationEffect::Blinker("/bell.pia", 300, 0xFFFF00); }},
/* 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 */ SIMPLE_EFFECT("confetti", true, SE_CYCLE_COLORS | SE_FADEOUT, {return random8()>252?1:0;}),
/* 14 */ SIMPLE_EFFECT("rainbow_confetti", true, SE_RANDOM_PIXEL_COLORS | SE_FADEOUT, {return random8()>252?1:0;}),
/* 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(); }},
/* 19 */ {"dvd", true, [](){ return new DvdEffect(); }},
/* 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(); }},
/* 29 */ {"koopa", 0, [](){ return new AnimationEffect("/koopa.pia"); }},
/* 30 */ {"cake", 0, [](){ return new AnimationEffect("/cake.pia"); }},
/* 31 */ {"child", 0, [](){ return AnimationEffect::Blinker("/child.pia", 300, 0xFFFF00); }},
/* 32 */ {"diamond", true, [](){ return new DiamondEffect(); }},
/* 33 */ {"tpm2.net", 0, [](){ return new Tpm2NetEffect(); }},
/* 34 */ SIMPLE_EFFECT("slow_blinking", true, SE_CYCLE_COLORS, {return sin(t + (x+1)*(y+1)*i);} ),
/* 35 */ SIMPLE_EFFECT("upwave", true, SE_CYCLE_COLORS, {return (cos(t+y/2));} ),
/* 36 */ SIMPLE_EFFECT("centerwave", true, SE_CYCLE_COLORS, {return sin(t*2 - sqrt((x-4)*(x-4) + (y-7)*(y-7)));} ),
/* 37 */ SIMPLE_EFFECT("sineline", true, SE_RANDOM_STATIC_COLOR, {return sin(x/2)-sin(x-t)-y+6;} ),
/* 38 */ SIMPLE_EFFECT("barbershop", true, SE_RANDOM_STATIC_COLOR, {return 1*cos(0.8*i-t*5);} ),
/* 39 */ SIMPLE_EFFECT("zigzag", true, SE_CYCLE_COLORS, { return cos(cos(x+y)-y*cos(t/8+x/16));} ),
};
const uint8_t effects_size = 40;
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;
}
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());
}
Effect* new_effect = select_effect( payload.c_str() );
if (new_effect == NULL) {
LOGln("Effects * Could not find effect with name %s", payload.c_str());
return false;
}
LOGln("Effects * Switching to effect %s", payload.c_str());
delete current_effect;
current_effect = new_effect;
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);
}
}
return true;
}
void setup_effects() {
current_effect = new CycleEffect();
}