12 #include <ESP8266WiFi.h> 29 static const char *
const TAG =
"wled_light_effect";
34 AddressableLightEffect::start();
44 AddressableLightEffect::stop();
53 for (
int led = it.
size(); led-- > 0;) {
62 udp_ = make_unique<WiFiUDP>();
65 ESP_LOGW(TAG,
"Cannot bind WLEDLightEffect to %d.",
port_);
70 std::vector<uint8_t> payload;
71 while (uint16_t packet_size =
udp_->parsePacket()) {
72 payload.resize(packet_size);
74 if (!
udp_->read(&payload[0], payload.size())) {
78 if (!this->
parse_frame_(it, &payload[0], payload.size())) {
79 ESP_LOGD(TAG,
"Frame: Invalid (size=%zu, first=0x%02X).", payload.size(), payload[0]);
99 uint8_t protocol = payload[0];
100 uint8_t timeout = payload[1];
108 if (
port_ == 19446) {
144 if (timeout == UINT8_MAX) {
146 }
else if (timeout > 0) {
165 uint8_t payload_sync_group_mask = payload[34];
168 ESP_LOGD(TAG,
"sync group mask does not match");
172 uint8_t bri = payload[0];
173 uint8_t r = esp_scale8(payload[1], bri);
174 uint8_t g = esp_scale8(payload[2], bri);
175 uint8_t b = esp_scale8(payload[3], bri);
176 uint8_t w = esp_scale8(payload[8], bri);
178 for (
auto &&led : it) {
179 led.set(
Color(r, g, b, w));
187 if ((size % 4) != 0) {
191 auto count = size / 4;
192 auto max_leds = it.
size();
194 for (; count > 0; count--, payload += 4) {
195 uint8_t led = payload[0];
196 uint8_t r = payload[1];
197 uint8_t g = payload[2];
198 uint8_t b = payload[3];
200 if (led < max_leds) {
201 it[led].set(
Color(r, g, b));
210 if ((size % 3) != 0) {
214 auto count = size / 3;
215 auto max_leds = it.
size();
217 for (uint16_t led = 0; led < count; ++led, payload += 3) {
218 uint8_t r = payload[0];
219 uint8_t g = payload[1];
220 uint8_t b = payload[2];
222 if (led < max_leds) {
223 it[led].set(
Color(r, g, b));
232 if ((size % 4) != 0) {
236 auto count = size / 4;
237 auto max_leds = it.
size();
239 for (uint16_t led = 0; led < count; ++led, payload += 4) {
240 uint8_t r = payload[0];
241 uint8_t g = payload[1];
242 uint8_t b = payload[2];
243 uint8_t w = payload[3];
245 if (led < max_leds) {
246 it[led].set(
Color(r, g, b, w));
259 uint16_t led = (uint16_t(payload[0]) << 8) + payload[1];
264 if ((size % 3) != 0) {
268 auto count = size / 3;
269 auto max_leds = it.
size();
271 for (; count > 0; count--, payload += 3, led++) {
272 uint8_t r = payload[0];
273 uint8_t g = payload[1];
274 uint8_t b = payload[2];
276 if (led < max_leds) {
277 it[led].set(
Color(r, g, b));
287 #endif // USE_ARDUINO
bool parse_frame_(light::AddressableLight &it, const uint8_t *payload, uint16_t size)
bool parse_notifier_frame_(light::AddressableLight &it, const uint8_t *payload, uint16_t size)
bool parse_dnrgb_frame_(light::AddressableLight &it, const uint8_t *payload, uint16_t size)
std::unique_ptr< UDP > udp_
const int DEFAULT_BLANK_TIME
uint32_t IRAM_ATTR HOT millis()
bool parse_drgbw_frame_(light::AddressableLight &it, const uint8_t *payload, uint16_t size)
bool parse_drgb_frame_(light::AddressableLight &it, const uint8_t *payload, uint16_t size)
virtual int32_t size() const =0
void blank_all_leds_(light::AddressableLight &it)
WLEDLightEffect(const std::string &name)
Implementation of SPI Controller mode.
bool parse_warls_frame_(light::AddressableLight &it, const uint8_t *payload, uint16_t size)