You can now set options for effects via MQTT and HTTP. Basic syntax is: <mode>,<option1>=<value1>,<option2>=<value2>,...

This commit is contained in:
Fabian Schlenz 2019-06-19 22:28:38 +02:00
parent 82fbc7be43
commit ead076f9a3
3 changed files with 35 additions and 6 deletions

View File

@ -17,6 +17,7 @@ public:
void setWindow(Window* win) { void setWindow(Window* win) {
window = win; window = win;
}; };
virtual void apply_option(String key, String value) {};
}; };
#endif #endif

View File

@ -17,6 +17,7 @@
#include "effect_firework.h" #include "effect_firework.h"
#include "effect_gol.h" #include "effect_gol.h"
#include "effect_pixelclock.h" #include "effect_pixelclock.h"
#include "effect_dvd.h"
Effect* current_effect; Effect* current_effect;
@ -54,11 +55,39 @@ Effect* select_effect(uint32_t code) {
}; };
} }
bool change_current_effect(String name) { bool change_current_effect(String payload) {
Effect* new_effect = string_to_effect(name); int pos = payload.indexOf(",");
if (new_effect == NULL) return false; 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;
}
delete current_effect; delete current_effect;
current_effect = new_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; return true;
} }

View File

@ -1,5 +1,4 @@
#include <Arduino.h> #include <Arduino.h>
#include <SimpleList.h>
#include "ntp.h" #include "ntp.h"
#include "config.h" #include "config.h"