pitrix/src/effects.cpp

115 lines
4.9 KiB
C++
Raw Normal View History

#include "effects.h"
#include "my_fastled.h"
#include <ErriezCRC32.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"
#include "effect_dynamic.h"
#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"
#include "effect_fire.h"
#include "effect_firework.h"
#include "effect_gol.h"
2019-06-15 12:18:35 +00:00
#include "effect_pixelclock.h"
#include "effect_dvd.h"
#include "effect_analogclock.h"
#include "effect_sines.h"
2019-09-25 04:26:27 +00:00
#include "effect_blur2d.h"
Effect* current_effect;
ClockEffect effect_clock;
Effect* select_effect(uint32_t code) {
switch (code) {
// use e.g. https://crccalc.com/ for the conversion of name to crc.
case 0: case 0xD682E3C8 /* sinematrix3 */ : return new Sinematrix3Effect();
case 1: case 0x90A887DA /* big_clock */ : return new BigClockEffect();
case 2: case 0xBE7BBE92 /* clock */ : return new ClockEffect();
case 3: case 0x733BE087 /* bell */ : return new BellEffect(); //(new AnimationEffect("/bell.pia", 0x000000, 0, 0))->setFgColor(0xFFFF00);
case 4: case 0x2BBC5D43 /* off */ : return new StaticEffect(0x000000);
case 5: case 0x1D84F231 /* koopa */ : return new AnimationEffect("/koopa.pia", CRGB(0x000000), 0, 0);
case 6: case 0xAC43BCF1 /* couple_rain */ : return new AnimationEffect("/couple_rain.pia", CRGB(0x000000), -8, -16);
case 7: case 0xF1B117F7 /* single_dynamic */ : return new SingleDynamicEffect();
case 8: case 0xF52F2804 /* multi_dynamic */ : return new MultiDynamicEffect();
case 9: case 0xF83341CF /* matrix */ : return new MatrixEffect();
case 10: case 0xD2B79DD0 /* rainbow_matrix */ : return new RainbowMatrixEffect();
case 11: case 0xE8DD3433 /* random_matrix */ : return new RandomMatrixEffect();
case 12: case 0xB086D193 /* cycle */ : return new CycleEffect();
case 13: case 0x2293EF9F /* twirl */ : return new TwirlEffect();
case 14: case 0x60ECC3E6 /* heart */ : return new AnimationEffect("/heart.pia", CRGB(0x000000), 0, 0);
case 15: case 0x42090A49 /* confetti */ : return new ConfettiEffect();
case 16: case 0x516D6B9E /* snake */ : return new SnakeEffect();
case 17: case 0x58DE09CF /* fire */ : return new FireEffect();
case 18: case 0x08BA9C08 /* firework */ : return new FireworkEffect();
case 19: case 0x14B85EAC /* gol */ : return new GolEffect();
case 20: case 0xFA13015D /* cake */ : return new AnimationEffect("/cake.pia", CRGB(0x000000), 0, 0);
case 21: case 0xA2B0D68B /* pixel_clock */ : return new PixelClockEffect();
case 22: case 0x2C0E6962 /* big_dynamic */ : return new BigDynamicEffect();
case 23: case 0xDA6F31A5 /* random_confetti */ : return new RandomConfettiEffect();
case 24: case 0x8325C1DF /* dvd */ : return new DvdEffect();
case 25: case 0x8CA97519 /* analog_clock */ : return new AnalogClockEffect();
case 26: case 0xADB18CC5 /* sines */ : return new SinesEffect();
2019-09-25 04:26:27 +00:00
case 27: case 0x0407881E /* blur2d */ : return new Blur2DEffect();
default : 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( crc32String(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;
}
const char* cycle_effects[] = {
"sinematrix3",
"multi_dynamic",
"matrix", "rainbow_matrix", "random_matrix",
"confetti", "random_confetti",
"single_dynamic",
"snake",
"gol",
"twirl"};
uint8_t cycle_effects_count = 11;
void setup_effects() {
current_effect = new CycleEffect();
}