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.
This commit is contained in:
Felicia Hummel 2018-06-16 15:23:11 +02:00
parent 8fdaa258ed
commit 71b29f833a
2 changed files with 17 additions and 1 deletions

View File

@ -1118,6 +1118,7 @@ boolean LightCommand()
if (XdrvMailbox.data_len > 0) { if (XdrvMailbox.data_len > 0) {
char *p; char *p;
uint16_t idx = XdrvMailbox.index; uint16_t idx = XdrvMailbox.index;
Ws2812ForceSuspend();
for (char *color = strtok_r(XdrvMailbox.data, " ", &p); color; color = strtok_r(NULL, " ", &p)) { for (char *color = strtok_r(XdrvMailbox.data, " ", &p); color; color = strtok_r(NULL, " ", &p)) {
if (LightColorEntry(color, strlen(color))) { if (LightColorEntry(color, strlen(color))) {
Ws2812SetColor(idx, light_entry_color[0], light_entry_color[1], light_entry_color[2], light_entry_color[3]); 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; break;
} }
} }
Ws2812ForceUpdate();
} }
snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_INDEX_SVALUE, command, XdrvMailbox.index, Ws2812GetColor(XdrvMailbox.index, scolor)); snprintf_P(mqtt_data, sizeof(mqtt_data), S_JSON_COMMAND_INDEX_SVALUE, command, XdrvMailbox.index, Ws2812GetColor(XdrvMailbox.index, scolor));
} }

View File

@ -93,7 +93,7 @@ uint8_t kRepeat[5] = {
1 }; // All 1 }; // All
uint8_t ws_show_next = 1; uint8_t ws_show_next = 1;
bool ws_suspend_update = false;
/********************************************************************************************/ /********************************************************************************************/
void Ws2812StripShow() 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); 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(); strip->Show();
ws_show_next = 1; ws_show_next = 1;
} }