ESPHome 2026.3.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 {
16namespace e131 {
17
18class E131AddressableLightEffect;
19
21
23
28
30 uint16_t universe;
31 uint16_t consumers;
32};
33
35 public:
38
39 void setup() override;
40 void loop() override;
41 float get_setup_priority() const override { return setup_priority::AFTER_WIFI; }
42
43 void add_effect(E131AddressableLightEffect *light_effect);
44 void remove_effect(E131AddressableLightEffect *light_effect);
45
46 void set_method(E131ListenMethod listen_method) { this->listen_method_ = listen_method; }
47
48 protected:
49 inline ssize_t read_(uint8_t *buf, size_t len) {
50#if defined(USE_SOCKET_IMPL_BSD_SOCKETS) || defined(USE_SOCKET_IMPL_LWIP_SOCKETS)
51 return this->socket_->read(buf, len);
52#elif defined(USE_SOCKET_IMPL_LWIP_TCP)
53 if (!this->udp_.parsePacket())
54 return -1;
55 return this->udp_.read(buf, len);
56#endif
57 }
58 bool packet_(const uint8_t *data, size_t len, int &universe, E131Packet &packet);
59 bool process_(int universe, const E131Packet &packet);
60 bool join_igmp_groups_();
62 void join_(int universe);
63 void leave_(int universe);
64
66#if defined(USE_SOCKET_IMPL_BSD_SOCKETS) || defined(USE_SOCKET_IMPL_LWIP_SOCKETS)
67 std::unique_ptr<socket::Socket> socket_;
68#elif defined(USE_SOCKET_IMPL_LWIP_TCP)
69 WiFiUDP udp_;
70#endif
71 std::vector<E131AddressableLightEffect *> light_effects_;
72 std::vector<UniverseConsumer> universe_consumers_;
73};
74
75} // namespace e131
76} // namespace esphome
77#endif
std::vector< E131AddressableLightEffect * > light_effects_
Definition e131.h:71
void loop() override
Definition e131.cpp:69
void add_effect(E131AddressableLightEffect *light_effect)
Definition e131.cpp:90
E131ListenMethod listen_method_
Definition e131.h:65
void remove_effect(E131AddressableLightEffect *light_effect)
Definition e131.cpp:106
bool packet_(const uint8_t *data, size_t len, int &universe, E131Packet &packet)
bool process_(int universe, const E131Packet &packet)
Definition e131.cpp:125
std::unique_ptr< socket::Socket > socket_
Definition e131.h:67
void setup() override
Definition e131.cpp:26
UniverseConsumer * find_universe_(int universe)
std::vector< UniverseConsumer > universe_consumers_
Definition e131.h:72
ssize_t read_(uint8_t *buf, size_t len)
Definition e131.h:49
void set_method(E131ListenMethod listen_method)
Definition e131.h:46
float get_setup_priority() const override
Definition e131.h:41
uint16_t universe
__int64 ssize_t
Definition httplib.h:178
const int E131_MAX_PROPERTY_VALUES_COUNT
Definition e131.h:22
E131ListenMethod
Definition e131.h:20
@ E131_UNICAST
Definition e131.h:20
@ E131_MULTICAST
Definition e131.h:20
constexpr float AFTER_WIFI
For components that should be initialized after WiFi is connected.
Definition component.h:41
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
std::string size_t len
Definition helpers.h:817
uint8_t values[E131_MAX_PROPERTY_VALUES_COUNT]
Definition e131.h:26