Added live preview json

This commit is contained in:
cschwinne 2019-11-18 12:29:36 +01:00
parent 81298a1034
commit 3aacb7150d
6 changed files with 64 additions and 5 deletions

View File

@ -2324,3 +2324,34 @@ uint16_t WS2812FX::mode_halloween_eyes()
return FRAMETIME; return FRAMETIME;
} }
//Speed slider sets amount of LEDs lit, intensity sets unlit
uint16_t WS2812FX::mode_static_pattern()
{
uint16_t lit = 1 + SEGMENT.speed;
uint16_t unlit = 1 + SEGMENT.intensity;
bool drawingLit = true;
uint16_t cnt = 0;
for (uint16_t i = SEGMENT.start; i < SEGMENT.stop; i++) {
setPixelColor(i, (drawingLit) ? color_from_palette(i, true, PALETTE_SOLID_WRAP, 0) : SEGCOLOR(1));
cnt++;
if (cnt >= ((drawingLit) ? lit : unlit)) {
cnt = 0;
drawingLit = !drawingLit;
}
}
return FRAMETIME;
}
//Speed slider sets number of "lights", intensity sets LEDs per light
/*uint16_t WS2812FX::mode_static_pattern2()
{
uint16_t maxlights = SEGLEN >> 1;
uint16_t zones = 1 + (SEGMENT.speed);
return FRAMETIME;
}*/

View File

@ -84,7 +84,7 @@
#define IS_REVERSE ((SEGMENT.options & REVERSE ) == REVERSE ) #define IS_REVERSE ((SEGMENT.options & REVERSE ) == REVERSE )
#define IS_SELECTED ((SEGMENT.options & SELECTED) == SELECTED ) #define IS_SELECTED ((SEGMENT.options & SELECTED) == SELECTED )
#define MODE_COUNT 83 #define MODE_COUNT 84
#define FX_MODE_STATIC 0 #define FX_MODE_STATIC 0
#define FX_MODE_BLINK 1 #define FX_MODE_BLINK 1
@ -170,6 +170,7 @@
#define FX_MODE_TWINKLEFOX 80 #define FX_MODE_TWINKLEFOX 80
#define FX_MODE_TWINKLECAT 81 #define FX_MODE_TWINKLECAT 81
#define FX_MODE_HALLOWEEN_EYES 82 #define FX_MODE_HALLOWEEN_EYES 82
#define FX_MODE_STATIC_PATTERN 83
class WS2812FX { class WS2812FX {
@ -308,6 +309,8 @@ class WS2812FX {
_mode[FX_MODE_TWINKLEFOX] = &WS2812FX::mode_twinklefox; _mode[FX_MODE_TWINKLEFOX] = &WS2812FX::mode_twinklefox;
_mode[FX_MODE_TWINKLECAT] = &WS2812FX::mode_twinklecat; _mode[FX_MODE_TWINKLECAT] = &WS2812FX::mode_twinklecat;
_mode[FX_MODE_HALLOWEEN_EYES] = &WS2812FX::mode_halloween_eyes; _mode[FX_MODE_HALLOWEEN_EYES] = &WS2812FX::mode_halloween_eyes;
_mode[FX_MODE_STATIC_PATTERN] = &WS2812FX::mode_static_pattern;
_brightness = DEFAULT_BRIGHTNESS; _brightness = DEFAULT_BRIGHTNESS;
currentPalette = CRGBPalette16(CRGB::Black); currentPalette = CRGBPalette16(CRGB::Black);
@ -482,7 +485,8 @@ class WS2812FX {
mode_ripple(void), mode_ripple(void),
mode_twinklefox(void), mode_twinklefox(void),
mode_twinklecat(void), mode_twinklecat(void),
mode_halloween_eyes(void); mode_halloween_eyes(void),
mode_static_pattern(void);
private: private:
NeoPixelWrapper *bus; NeoPixelWrapper *bus;
@ -553,7 +557,7 @@ const char JSON_mode_names[] PROGMEM = R"=====([
"Out Out","Out In","Circus","Halloween","Tri Chase","Tri Wipe","Tri Fade","Lightning","ICU","Multi Comet", "Out Out","Out In","Circus","Halloween","Tri Chase","Tri Wipe","Tri Fade","Lightning","ICU","Multi Comet",
"Dual Scanner","Stream 2","Oscillate","Pride 2015","Juggle","Palette","Fire 2012","Colorwaves","BPM","Fill Noise", "Dual Scanner","Stream 2","Oscillate","Pride 2015","Juggle","Palette","Fire 2012","Colorwaves","BPM","Fill Noise",
"Noise 1","Noise 2","Noise 3","Noise 4","Colortwinkles","Lake","Meteor","Smooth Meteor","Railway","Ripple", "Noise 1","Noise 2","Noise 3","Noise 4","Colortwinkles","Lake","Meteor","Smooth Meteor","Railway","Ripple",
"Twinklefox","Twinklecat","Halloween Eyes" "Twinklefox","Twinklecat","Halloween Eyes","Solid Pattern"
])====="; ])=====";

Binary file not shown.

View File

@ -100,7 +100,7 @@
//version code in format yymmddb (b = daily build) //version code in format yymmddb (b = daily build)
#define VERSION 1911122 #define VERSION 1911161
char versionString[] = "0.8.7-dev"; char versionString[] = "0.8.7-dev";

View File

@ -83,7 +83,7 @@ void publishMqtt()
strcat(subuf, "/g"); strcat(subuf, "/g");
mqtt->publish(subuf, 0, true, s); mqtt->publish(subuf, 0, true, s);
sprintf(s, "#%06X", col[3]*16777216 + col[0]*65536 + col[1]*256 + col[2]); sprintf(s, "#%06X", (col[3] << 24) | (col[0] << 16) | (col[1] << 8) | (col[2]));
strcpy(subuf, mqttDeviceTopic); strcpy(subuf, mqttDeviceTopic);
strcat(subuf, "/c"); strcat(subuf, "/c");
mqtt->publish(subuf, 0, true, s); mqtt->publish(subuf, 0, true, s);

View File

@ -248,6 +248,10 @@ void serveJson(AsyncWebServerRequest* request)
const String& url = request->url(); const String& url = request->url();
if (url.indexOf("state") > 0) subJson = 1; if (url.indexOf("state") > 0) subJson = 1;
else if (url.indexOf("info") > 0) subJson = 2; else if (url.indexOf("info") > 0) subJson = 2;
else if (url.indexOf("live") > 0) {
serveLiveLeds(request);
return;
}
else if (url.indexOf("eff") > 0) { else if (url.indexOf("eff") > 0) {
request->send_P(200, "application/json", JSON_mode_names); request->send_P(200, "application/json", JSON_mode_names);
return; return;
@ -282,3 +286,23 @@ void serveJson(AsyncWebServerRequest* request)
response->setLength(); response->setLength();
request->send(response); request->send(response);
} }
#define MAX_LIVE_LEDS 180
void serveLiveLeds(AsyncWebServerRequest* request)
{
byte n = (ledCount -1) /MAX_LIVE_LEDS +1; //only serve every n'th LED if count over MAX_LIVE_LEDS
char buffer[2000] = "{\"leds\":[";
olen = 9;
obuf = buffer;
for (uint16_t i= 0; i < ledCount; i += n)
{
olen += sprintf(buffer + olen, "\"%06X\",", strip.getPixelColor(i));
}
olen -= 1;
oappend("],\"n\":");
oappendi(n);
oappend("}");
request->send(200, "application/json", buffer);
}