From 71b29f833a7a0d2a61fa71dfa3fcc60f539dec3f Mon Sep 17 00:00:00 2001 From: Felicia Hummel Date: Sat, 16 Jun 2018 15:23:11 +0200 Subject: [PATCH] When passing values for multiple WS2812 LEDs at once, updating is very slow because after each LED is set, the strip is updated. The update was so slow that it was visible with the eye. For me, it took approx 0.5 seconds to update an 28 pixel long strip. This patch suspends updates to the strip while procesing the passed LEDs, enabling the updates afterwards. --- sonoff/xdrv_04_light.ino | 3 +++ sonoff/xplg_ws2812.ino | 15 ++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/sonoff/xdrv_04_light.ino b/sonoff/xdrv_04_light.ino index 7843192f7..6d87b5a5b 100644 --- a/sonoff/xdrv_04_light.ino +++ b/sonoff/xdrv_04_light.ino @@ -1118,6 +1118,7 @@ boolean LightCommand() if (XdrvMailbox.data_len > 0) { char *p; uint16_t idx = XdrvMailbox.index; + Ws2812ForceSuspend(); for (char *color = strtok_r(XdrvMailbox.data, " ", &p); color; color = strtok_r(NULL, " ", &p)) { if (LightColorEntry(color, strlen(color))) { Ws2812SetColor(idx, light_entry_color[0], light_entry_color[1], light_entry_color[2], light_entry_color[3]); @@ -1127,6 +1128,8 @@ boolean LightCommand() break; } } + + Ws2812ForceUpdate(); } snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_INDEX_SVALUE, command, XdrvMailbox.index, Ws2812GetColor(XdrvMailbox.index, scolor)); } diff --git a/sonoff/xplg_ws2812.ino b/sonoff/xplg_ws2812.ino index 4d6410f90..2e576bfc8 100644 --- a/sonoff/xplg_ws2812.ino +++ b/sonoff/xplg_ws2812.ino @@ -93,7 +93,7 @@ uint8_t kRepeat[5] = { 1 }; // All uint8_t ws_show_next = 1; - +bool ws_suspend_update = false; /********************************************************************************************/ void Ws2812StripShow() @@ -365,6 +365,19 @@ void Ws2812SetColor(uint16_t led, uint8_t red, uint8_t green, uint8_t blue, uint strip->SetPixelColor(i, lcolor); } } + + if (!ws_suspend_update) { + strip->Show(); + ws_show_next = 1; + } +} + +void Ws2812ForceSuspend () { + ws_suspend_update = true; +} + +void Ws2812ForceUpdate () { + ws_suspend_update = false; strip->Show(); ws_show_next = 1; }