diff --git a/Artnet/Common.h b/Artnet/Common.h index 24d088e..3d16276 100644 --- a/Artnet/Common.h +++ b/Artnet/Common.h @@ -85,12 +85,6 @@ struct Destination uint8_t universe; }; -class NoPrint : public Print { - size_t write(uint8_t) { - return 0; - } -}; -NoPrint NoLog; inline bool operator<(const Destination &rhs, const Destination &lhs) { diff --git a/Artnet/Receiver.h b/Artnet/Receiver.h index fd56b83..4838372 100644 --- a/Artnet/Receiver.h +++ b/Artnet/Receiver.h @@ -11,6 +11,13 @@ namespace art_net { +class NoPrint : public Print { + size_t write(uint8_t) { + return 0; + } +}; +static NoPrint no_log; + template class Receiver_ { @@ -46,14 +53,14 @@ class Receiver_ } if (size > PACKET_SIZE) { - log->print(F("Packet size is unexpectedly too large: ")); - log->println(size); + logger->print(F("Packet size is unexpectedly too large: ")); + logger->println(size); size = PACKET_SIZE; } this->stream->read(this->packet.data(), size); if (!checkID()) { - log->println(F("Packet ID is not Art-Net")); + logger->println(F("Packet ID is not Art-Net")); return OpCode::ParseFailed; } @@ -114,8 +121,8 @@ class Receiver_ break; } default: { - log->print(F("Unsupported OpCode: ")); - log->println(this->getOpCode(), HEX); + logger->print(F("Unsupported OpCode: ")); + logger->println(this->getOpCode(), HEX); op_code = OpCode::Unsupported; break; } @@ -131,15 +138,15 @@ class Receiver_ -> std::enable_if_t::value> { if (net > 0x7F) { - log->println(F("net should be less than 0x7F")); + logger->println(F("net should be less than 0x7F")); return; } if (subnet > 0xF) { - log->println(F("subnet should be less than 0xF")); + logger->println(F("subnet should be less than 0xF")); return; } if (universe > 0xF) { - log->println(F("universe should be less than 0xF")); + logger->println(F("universe should be less than 0xF")); return; } uint16_t u = ((uint16_t)net << 8) | ((uint16_t)subnet << 4) | (uint16_t)universe; @@ -239,11 +246,11 @@ class Receiver_ n = num; } else { n = size / 3; - log->println(F("WARN: ArtNet packet size is less than requested LED numbers to forward")); - log->print(F(" requested: ")); - log->print(num * 3); - log->print(F(" received : ")); - log->println(size); + logger->println(F("WARN: ArtNet packet size is less than requested LED numbers to forward")); + logger->print(F(" requested: ")); + logger->print(num * 3); + logger->print(F(" received : ")); + logger->println(size); } for (size_t pixel = 0; pixel < n; ++pixel) { size_t idx = pixel * 3; @@ -274,8 +281,8 @@ class Receiver_ this->art_poll_reply_config.node_report = node_report; } - void logOutputTo(Print* dest) { - log = dest; + void setLogger(Print* dest) { + logger = dest; } protected: @@ -284,9 +291,11 @@ class Receiver_ this->stream = &s; } - Print* log = &NoLog; private: + + Print* logger = &no_log; + bool checkID() const { const char* idptr = reinterpret_cast(this->packet.data()); diff --git a/README.md b/README.md index 5b25797..ec47b97 100644 --- a/README.md +++ b/README.md @@ -356,7 +356,7 @@ void forwardArtDmxDataToFastLED(uint16_t universe, CRGB* leds, uint16_t num); // https://art-net.org.uk/how-it-works/discovery-packets/artpollreply/ void setArtPollReplyConfig(uint16_t oem, uint16_t esta_man, uint8_t status1, uint8_t status2, const String &short_name, const String &long_name, const String &node_report); // Set where debug output should go (default is nowhere) -void logOutputTo(Print*); +void setLogger(Print*); ``` ### Note