diff --git a/Artnet.h b/Artnet.h index 367d72e..8223710 100644 --- a/Artnet.h +++ b/Artnet.h @@ -397,6 +397,28 @@ namespace arduino subscribe(u, func); } + inline void unsubscribe(const uint32_t universe) + { + size_t idx = callbacks.size(); + for (size_t i = 0; i < callbacks.size(); ++i) + if (callbacks[i].universe == universe) { + idx = i; + break; + } + + if (idx != callbacks.size()) + callbacks.erase(callbacks.begin() + idx); + } + inline void unsubscribe() + { + unsubscribe(0); + } + inline void unsubscribe(const uint8_t net, const uint8_t subnet, const uint8_t universe) + { + uint32_t u = ((uint32_t)net << 8) | ((uint32_t)subnet << 4) | (uint32_t)universe; + unsubscribe(u); + } + protected: void attach(S& s) { stream = &s; } diff --git a/README.md b/README.md index 4616191..402d0eb 100644 --- a/README.md +++ b/README.md @@ -213,6 +213,9 @@ uint8_t data(const uint16_t i) const; void subscribe(const uint32_t universe, const CallbackType& func); void subscribe(const CallbackType& func); void subscribe(const uint8_t net, const uint8_t subnet, const uint8_t universe, const CallbackType& func); +void unsubscribe(const uint32_t universe); +void unsubscribe(); +void unsubscribe(const uint8_t net, const uint8_t subnet, const uint8_t universe); ``` ## Supported Platform