You can now set options for effects via MQTT and HTTP. Basic syntax is: <mode>,<option1>=<value1>,<option2>=<value2>,...
This commit is contained in:
parent
82fbc7be43
commit
ead076f9a3
@ -17,6 +17,7 @@ public:
|
||||
void setWindow(Window* win) {
|
||||
window = win;
|
||||
};
|
||||
virtual void apply_option(String key, String value) {};
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -17,6 +17,7 @@
|
||||
#include "effect_firework.h"
|
||||
#include "effect_gol.h"
|
||||
#include "effect_pixelclock.h"
|
||||
#include "effect_dvd.h"
|
||||
|
||||
Effect* current_effect;
|
||||
|
||||
@ -54,11 +55,39 @@ Effect* select_effect(uint32_t code) {
|
||||
};
|
||||
}
|
||||
|
||||
bool change_current_effect(String name) {
|
||||
Effect* new_effect = string_to_effect(name);
|
||||
if (new_effect == NULL) return false;
|
||||
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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,4 @@
|
||||
#include <Arduino.h>
|
||||
#include <SimpleList.h>
|
||||
|
||||
#include "ntp.h"
|
||||
#include "config.h"
|
||||
|
Loading…
Reference in New Issue
Block a user