diff --git a/Artnet/Common.h b/Artnet/Common.h index 7631638..76a385a 100644 --- a/Artnet/Common.h +++ b/Artnet/Common.h @@ -65,6 +65,7 @@ constexpr uint16_t PACKET_SIZE {530}; using CallbackAllType = std::function; using CallbackType = std::function; using CallbackArtSync = std::function; +using CallbackArtTrigger = std::function; #if ARX_HAVE_LIBSTDCPLUSPLUS >= 201103L // Have libstdc++11 template diff --git a/Artnet/Receiver.h b/Artnet/Receiver.h index ea2ca5e..b6b0704 100644 --- a/Artnet/Receiver.h +++ b/Artnet/Receiver.h @@ -5,6 +5,7 @@ #include "Common.h" #include "ArtDmx.h" #include "ArtPollReply.h" +#include "ArtTrigger.h" namespace art_net { @@ -18,6 +19,7 @@ class Receiver_ { CallbackMap callbacks; CallbackAllType callback_all; CallbackArtSync callback_artsync; + CallbackArtTrigger callback_arttrigger; S* stream; bool b_verbose {false}; artpollreply::ArtPollReply artpollreply_ctx; @@ -53,12 +55,12 @@ class Receiver_ { OpCode op_code = OpCode::NA; if (checkID(d)) { + remote_ip = stream->S::remoteIP(); + remote_port = (uint16_t)stream->S::remotePort(); OpCode received_op_code = static_cast(opcode(d)); switch (received_op_code) { case OpCode::Dmx: { memcpy(packet.data(), d, size); - remote_ip = stream->S::remoteIP(); - remote_port = (uint16_t)stream->S::remotePort(); if (callback_all) callback_all(universe15bit(), data(), size - HEADER_SIZE); for (auto& c : callbacks) if (universe15bit() == c.first) c.second(data(), size - HEADER_SIZE); @@ -66,12 +68,20 @@ class Receiver_ { break; } case OpCode::Poll: { - remote_ip = stream->S::remoteIP(); - remote_port = (uint16_t)stream->S::remotePort(); poll_reply(); op_code = OpCode::Poll; break; } + case OpCode::Trigger: { + if (callback_arttrigger) { + uint16_t oem = (d[art_trigger::OEM_H] << 8) | d[art_trigger::OEM_L]; + uint8_t key = d[art_trigger::KEY]; + uint8_t sub_key = d[art_trigger::SUB_KEY]; + callback_arttrigger(oem, key, sub_key, d + art_trigger::PAYLOAD, size - art_trigger::PAYLOAD); + } + op_code = OpCode::Trigger; + break; + } case OpCode::Sync: { if (callback_artsync) callback_artsync(); op_code = OpCode::Sync; @@ -185,13 +195,21 @@ class Receiver_ { callback_all = arx::function_traits::cast(func); } template - inline auto subscribeArtsync(F&& func) -> std::enable_if_t::value> { + inline auto subscribeArtSync(F&& func) -> std::enable_if_t::value> { callback_artsync = arx::function_traits::cast(func); } template - inline auto subscribeArtsync(F* func) -> std::enable_if_t::value> { + inline auto subscribeArtSync(F* func) -> std::enable_if_t::value> { callback_artsync = arx::function_traits::cast(func); } + template + inline auto subscribeArtTrigger(F&& func) -> std::enable_if_t::value> { + callback_arttrigger = arx::function_traits::cast(func); + } + template + inline auto subscribeArtTrigger(F* func) -> std::enable_if_t::value> { + callback_arttrigger = arx::function_traits::cast(func); + } inline void unsubscribe(const uint8_t universe) { auto it = callbacks.find(universe); @@ -203,6 +221,9 @@ class Receiver_ { inline void unsubscribeArtSync() { callback_artsync = nullptr; } + inline void unsubscribeArtTrigger() { + callback_arttrigger = nullptr; + } inline void clear_subscribers() { unsubscribe(); diff --git a/README.md b/README.md index 08d9c94..a15382a 100644 --- a/README.md +++ b/README.md @@ -298,16 +298,15 @@ void sync(const String& ip); ```C++ OpCode parse(); // subscribers -template inline auto subscribe(const uint8_t universe, F&& func); -template inline auto subscribe(const uint8_t universe, F* func); -template inline auto subscribe(F&& func); -template inline auto subscribe(F* func); -template inline auto subscribeArtsync(F&& func); -template inline auto subscribeArtsync(F* func); +template inline auto subscribe(const uint8_t universe, CallbackType); +template inline auto subscribe(CallbackAllTyp); +template inline auto subscribeArtSync(CallbackArtSync); +template inline auto subscribeArtTrigger(CallbackArtTrigger); // callback definitions for subscribers using CallbackAllType = std::function; using CallbackType = std::function; using CallbackArtSync = std::function; +using CallbackArTrigger = std::function; // for FastLED inline void forward(const uint8_t universe, CRGB* leds, const uint16_t num); // unsubscribe @@ -315,6 +314,7 @@ inline void unsubscribe(const uint8_t universe); inline void unsubscribe(); inline void clear_subscribers(); inline void unsubscribeArtSync(); +inline void unsubscribeArtTrigger(); // ArtPollReply information void shortname(const String& sn); void longname(const String& ln);