Send websockets on every state change

This commit is contained in:
cschwinne 2021-07-02 00:24:14 +02:00
parent 801df94446
commit dc01c907f1
9 changed files with 202 additions and 172 deletions

View File

@ -2,6 +2,11 @@
### Builds after release 0.12.0
#### Build 2107020
- Send websockets on every state change
- Improved Aurora effect
#### Build 2107011
- Added MQTT button feedback option (PR #2011)

View File

@ -3957,7 +3957,6 @@ uint16_t WS2812FX::mode_tv_simulator(void) {
*/
//CONFIG
#define BACKLIGHT 5
#define W_MAX_COUNT 20 //Number of simultaneous waves
#define W_MAX_SPEED 6 //Higher number, higher speed
#define W_WIDTH_FACTOR 6 //Higher number, smaller waves
@ -4082,9 +4081,13 @@ uint16_t WS2812FX::mode_aurora(void) {
}
}
uint8_t backlight = 1; //dimmer backlight if less active colors
if (SEGCOLOR(0)) backlight++;
if (SEGCOLOR(1)) backlight++;
if (SEGCOLOR(2)) backlight++;
//Loop through LEDs to determine color
for(int i = 0; i < SEGLEN; i++) {
CRGB mixedRgb = CRGB(BACKLIGHT, BACKLIGHT, BACKLIGHT);
CRGB mixedRgb = CRGB(backlight, backlight, backlight);
//For each LED we must check each wave if it is "active" at this position.
//If there are multiple waves active on a LED we multiply their values.
@ -4096,7 +4099,7 @@ uint16_t WS2812FX::mode_aurora(void) {
}
}
setPixelColor(i, mixedRgb[0], mixedRgb[1], mixedRgb[2], BACKLIGHT);
setPixelColor(i, mixedRgb[0], mixedRgb[1], mixedRgb[2]);
}
return FRAMETIME;

View File

@ -320,6 +320,27 @@ class WS2812FX {
vLength = (vLength + 1) /2; // divide by 2 if mirror, leave at least a single LED
return vLength;
}
uint8_t differs(Segment& b) {
uint8_t d = 0;
if (start != b.start) d |= SEG_DIFFERS_BOUNDS;
if (stop != b.stop) d |= SEG_DIFFERS_BOUNDS;
if (offset != b.offset) d |= SEG_DIFFERS_GSO;
if (grouping != b.grouping) d |= SEG_DIFFERS_GSO;
if (spacing != b.spacing) d |= SEG_DIFFERS_GSO;
if (opacity != b.opacity) d |= SEG_DIFFERS_BRI;
if (mode != b.mode) d |= SEG_DIFFERS_FX;
if (speed != b.speed) d |= SEG_DIFFERS_FX;
if (intensity != b.intensity) d |= SEG_DIFFERS_FX;
if (palette != b.palette) d |= SEG_DIFFERS_FX;
if ((options & 0b00101111) != (b.options & 0b00101111)) d |= SEG_DIFFERS_OPT;
for (uint8_t i = 0; i < NUM_COLORS; i++)
{
if (colors[i] != b.colors[i]) d |= SEG_DIFFERS_COL;
}
return d;
}
} segment;
// segment runtime parameters
@ -613,7 +634,6 @@ class WS2812FX {
gammaCorrectBri = false,
gammaCorrectCol = true,
applyToAllSelected = true,
segmentsAreIdentical(Segment* a, Segment* b),
setEffectConfig(uint8_t m, uint8_t s, uint8_t i, uint8_t p),
// return true if the strip is being sent pixel updates
isUpdating(void);

View File

@ -1010,23 +1010,6 @@ uint32_t WS2812FX::color_from_palette(uint16_t i, bool mapping, bool wrap, uint8
return crgb_to_col(fastled_col);
}
//@returns `true` if color, mode, speed, intensity and palette match
bool WS2812FX::segmentsAreIdentical(Segment* a, Segment* b)
{
//if (a->start != b->start) return false;
//if (a->stop != b->stop) return false;
for (uint8_t i = 0; i < NUM_COLORS; i++)
{
if (a->colors[i] != b->colors[i]) return false;
}
if (a->mode != b->mode) return false;
if (a->speed != b->speed) return false;
if (a->intensity != b->intensity) return false;
if (a->palette != b->palette) return false;
//if (a->getOption(SEG_OPTION_REVERSED) != b->getOption(SEG_OPTION_REVERSED)) return false;
return true;
}
//load custom mapping table from JSON file
void WS2812FX::deserializeMap(void) {

View File

@ -77,6 +77,7 @@
#define NOTIFIER_CALL_MODE_PRESET_CYCLE 8
#define NOTIFIER_CALL_MODE_BLYNK 9
#define NOTIFIER_CALL_MODE_ALEXA 10
#define NOTIFIER_CALL_MODE_WS_SEND 11 //special call mode, not for notifier, updates websocket only
//RGB to RGBW conversion mode
#define RGBW_MODE_MANUAL_ONLY 0 //No automatic white channel calculation. Manual white channel slider
@ -195,6 +196,14 @@
#define SEG_OPTION_FREEZE 5 //Segment contents will not be refreshed
#define SEG_OPTION_TRANSITIONAL 7
//Segment differs return byte
#define SEG_DIFFERS_BRI 0x01
#define SEG_DIFFERS_OPT 0x02
#define SEG_DIFFERS_COL 0x04
#define SEG_DIFFERS_FX 0x08
#define SEG_DIFFERS_BOUNDS 0x10
#define SEG_DIFFERS_GSO 0x20
//Playlist option byte
#define PL_OPTION_SHUFFLE 0x01

View File

@ -9,9 +9,12 @@
void deserializeSegment(JsonObject elem, byte it, byte presetId)
{
byte id = elem["id"] | it;
if (id < strip.getMaxSegments())
{
if (id >= strip.getMaxSegments()) return;
WS2812FX::Segment& seg = strip.getSegment(id);
//WS2812FX::Segment prev;
//prev = seg; //make a backup so we can tell if something changed
uint16_t start = elem[F("start")] | seg.start;
int stop = elem["stop"] | -1;
@ -159,8 +162,7 @@ void deserializeSegment(JsonObject elem, byte it, byte presetId)
} else { //return to regular effect
seg.setOption(SEG_OPTION_FREEZE, false);
}
}
return; // seg.hasChanged(prev);
}
bool deserializeState(JsonObject root, byte presetId)
@ -300,6 +302,8 @@ bool deserializeState(JsonObject root, byte presetId)
if (!playlist.isNull()) {
loadPlaylist(playlist, presetId);
noNotification = true; //do not notify both for this request and the first playlist entry
} else {
interfaceUpdateCallMode = NOTIFIER_CALL_MODE_WS_SEND;
}
colorUpdated(noNotification ? NOTIFIER_CALL_MODE_NO_NOTIFY : NOTIFIER_CALL_MODE_DIRECT_CHANGE);

View File

@ -115,7 +115,7 @@ void colorUpdated(int callMode)
notify(callMode);
//set flag to update blynk and mqtt
//set flag to update blynk, ws and mqtt
interfaceUpdateCallMode = callMode;
} else {
if (nightlightActive && !nightlightActiveOld &&
@ -180,6 +180,11 @@ void colorUpdated(int callMode)
void updateInterfaces(uint8_t callMode)
{
sendDataWs();
if (callMode == NOTIFIER_CALL_MODE_WS_SEND) {
lastInterfaceUpdate = millis();
return;
}
#ifndef WLED_DISABLE_ALEXA
if (espalexaDevice != nullptr && callMode != NOTIFIER_CALL_MODE_ALEXA) {
espalexaDevice->setValue(bri);

View File

@ -8,7 +8,7 @@
*/
// version code in format yymmddb (b = daily build)
#define VERSION 2107011
#define VERSION 2107020
//uncomment this if you have a "my_config.h" file you'd like to use
//#define WLED_USE_MY_CONFIG

View File

@ -41,7 +41,8 @@ void wsEvent(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventTyp
verboseResponse = deserializeState(root);
}
if (verboseResponse || millis() - lastInterfaceUpdate < 1900) sendDataWs(client); //update if it takes longer than 100ms until next "broadcast"
//update if it takes longer than 300ms until next "broadcast"
if (verboseResponse && (millis() - lastInterfaceUpdate < 1700 || !interfaceUpdateCallMode)) sendDataWs(client);
}
} else {
//message is comprised of multiple frames or the frame is split into multiple packets