ESPHome 2026.6.0-dev
Loading...
Searching...
No Matches
e131.h
Go to the documentation of this file.
1#pragma once
3#ifdef USE_NETWORK
4#if defined(USE_SOCKET_IMPL_BSD_SOCKETS) || defined(USE_SOCKET_IMPL_LWIP_SOCKETS)
6#elif defined(USE_SOCKET_IMPL_LWIP_TCP)
7#include <WiFiUdp.h>
8#endif
10
11#include <cinttypes>
12#include <memory>
13#include <vector>
14
15namespace esphome::e131 {
16
17class E131AddressableLightEffect;
18
20
22
27
29 uint16_t universe;
30 uint16_t consumers;
31};
32
34 public:
37
38 void setup() override;
39 void loop() override;
40 float get_setup_priority() const override { return setup_priority::AFTER_WIFI; }
41
42 void add_effect(E131AddressableLightEffect *light_effect);
43 void remove_effect(E131AddressableLightEffect *light_effect);
44
45 void set_method(E131ListenMethod listen_method) { this->listen_method_ = listen_method; }
46
47 protected:
48 inline ssize_t read_(uint8_t *buf, size_t len) {
49#if defined(USE_SOCKET_IMPL_BSD_SOCKETS) || defined(USE_SOCKET_IMPL_LWIP_SOCKETS)
50 return this->socket_->read(buf, len);
51#elif defined(USE_SOCKET_IMPL_LWIP_TCP)
52 if (!this->udp_.parsePacket())
53 return -1;
54 return this->udp_.read(buf, len);
55#else
56 return -1;
57#endif
58 }
59 bool packet_(const uint8_t *data, size_t len, int &universe, E131Packet &packet);
60 bool process_(int universe, const E131Packet &packet);
61 bool join_igmp_groups_();
63 void join_(int universe);
64 void leave_(int universe);
65
67#if defined(USE_SOCKET_IMPL_BSD_SOCKETS) || defined(USE_SOCKET_IMPL_LWIP_SOCKETS)
68 std::unique_ptr<socket::Socket> socket_;
69#elif defined(USE_SOCKET_IMPL_LWIP_TCP)
70 WiFiUDP udp_;
71#endif
72 std::vector<E131AddressableLightEffect *> light_effects_;
73 std::vector<UniverseConsumer> universe_consumers_;
74};
75
76} // namespace esphome::e131
77
78#endif
std::vector< E131AddressableLightEffect * > light_effects_
Definition e131.h:72
void loop() override
Definition e131.cpp:68
void add_effect(E131AddressableLightEffect *light_effect)
Definition e131.cpp:89
E131ListenMethod listen_method_
Definition e131.h:66
void remove_effect(E131AddressableLightEffect *light_effect)
Definition e131.cpp:105
bool packet_(const uint8_t *data, size_t len, int &universe, E131Packet &packet)
bool process_(int universe, const E131Packet &packet)
Definition e131.cpp:124
std::unique_ptr< socket::Socket > socket_
Definition e131.h:68
void setup() override
Definition e131.cpp:25
UniverseConsumer * find_universe_(int universe)
std::vector< UniverseConsumer > universe_consumers_
Definition e131.h:73
ssize_t read_(uint8_t *buf, size_t len)
Definition e131.h:48
void set_method(E131ListenMethod listen_method)
Definition e131.h:45
float get_setup_priority() const override
Definition e131.h:40
uint16_t universe
__int64 ssize_t
Definition httplib.h:178
const int E131_MAX_PROPERTY_VALUES_COUNT
Definition e131.h:21
E131ListenMethod
Definition e131.h:19
@ E131_UNICAST
Definition e131.h:19
@ E131_MULTICAST
Definition e131.h:19
constexpr float AFTER_WIFI
For components that should be initialized after WiFi is connected.
Definition component.h:53
const void size_t len
Definition hal.h:64
uint8_t values[E131_MAX_PROPERTY_VALUES_COUNT]
Definition e131.h:25