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) {
|
void setWindow(Window* win) {
|
||||||
window = win;
|
window = win;
|
||||||
};
|
};
|
||||||
|
virtual void apply_option(String key, String value) {};
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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"
|
||||||
@ -20,7 +19,7 @@ char hostname[30]; // defined as extern in prototypes.h
|
|||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(74880);
|
Serial.begin(74880);
|
||||||
LOGln("Core * Starting");
|
LOGln("Core * Starting");
|
||||||
|
|
||||||
int chipid;
|
int chipid;
|
||||||
#if defined( ESP8266 )
|
#if defined( ESP8266 )
|
||||||
chipid = ESP.getChipId();
|
chipid = ESP.getChipId();
|
||||||
@ -28,7 +27,7 @@ void setup() {
|
|||||||
chipid = ESP.getEfuseMac() & 0xFFFFFF;
|
chipid = ESP.getEfuseMac() & 0xFFFFFF;
|
||||||
#endif
|
#endif
|
||||||
snprintf(hostname, 30, HOSTNAME, chipid);
|
snprintf(hostname, 30, HOSTNAME, chipid);
|
||||||
|
|
||||||
setup_effects();
|
setup_effects();
|
||||||
wifi_setup();
|
wifi_setup();
|
||||||
ntp_setup();
|
ntp_setup();
|
||||||
|
Loading…
Reference in New Issue
Block a user