From 93a7ae673de5a5162335ecdab87a9efcd7ac34b6 Mon Sep 17 00:00:00 2001 From: Hideaki Tai Date: Sun, 7 Jul 2024 00:50:20 +0900 Subject: [PATCH 1/2] refactor: logger and reamde --- Artnet/Receiver.h | 68 +++++++++++++++++++++++++++-------------------- README.md | 9 ++++++- 2 files changed, 47 insertions(+), 30 deletions(-) diff --git a/Artnet/Receiver.h b/Artnet/Receiver.h index 992c139..6a35d96 100644 --- a/Artnet/Receiver.h +++ b/Artnet/Receiver.h @@ -11,13 +11,16 @@ namespace art_net { -class NoPrint : public Print { - size_t write(uint8_t) { - return 0; - } +namespace { + +struct NoPrint : public Print +{ + size_t write(uint8_t) override { return 0; } }; static NoPrint no_log; +} // namespace + template class Receiver_ { @@ -31,6 +34,8 @@ class Receiver_ art_trigger::CallbackType callback_art_trigger; ArtPollReplyConfig art_poll_reply_config; + Print *logger {&no_log}; + public: #if ARX_HAVE_LIBSTDCPLUSPLUS >= 201103L // Have libstdc++11 #else @@ -53,14 +58,14 @@ class Receiver_ } if (size > PACKET_SIZE) { - logger->print(F("Packet size is unexpectedly too large: ")); - logger->println(size); + this->logger->print(F("Packet size is unexpectedly too large: ")); + this->logger->println(size); size = PACKET_SIZE; } this->stream->read(this->packet.data(), size); if (!checkID()) { - logger->println(F("Packet ID is not Art-Net")); + this->logger->println(F("Packet ID is not Art-Net")); return OpCode::ParseFailed; } @@ -121,8 +126,8 @@ class Receiver_ break; } default: { - logger->print(F("Unsupported OpCode: ")); - logger->println(this->getOpCode(), HEX); + this->logger->print(F("Unsupported OpCode: ")); + this->logger->println(this->getOpCode(), HEX); op_code = OpCode::Unsupported; break; } @@ -138,15 +143,15 @@ class Receiver_ -> std::enable_if_t::value> { if (net > 0x7F) { - logger->println(F("net should be less than 0x7F")); + this->logger->println(F("net should be less than 0x7F")); return; } if (subnet > 0xF) { - logger->println(F("subnet should be less than 0xF")); + this->logger->println(F("subnet should be less than 0xF")); return; } if (universe > 0xF) { - logger->println(F("universe should be less than 0xF")); + this->logger->println(F("universe should be less than 0xF")); return; } uint16_t u = ((uint16_t)net << 8) | ((uint16_t)subnet << 4) | (uint16_t)universe; @@ -246,11 +251,11 @@ class Receiver_ n = num; } else { n = size / 3; - 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); + this->logger->println(F("WARN: ArtNet packet size is less than requested LED numbers to forward")); + this->logger->print(F(" requested: ")); + this->logger->print(num * 3); + this->logger->print(F(" received : ")); + this->logger->println(size); } for (size_t pixel = 0; pixel < n; ++pixel) { size_t idx = pixel * 3; @@ -263,25 +268,32 @@ class Receiver_ #endif // https://art-net.org.uk/how-it-works/discovery-packets/artpollreply/ - void setArtPollReplyConfigOem(uint16_t oem) { + void setArtPollReplyConfigOem(uint16_t oem) + { this->art_poll_reply_config.oem = oem; } - void setArtPollReplyConfigEstaMan(uint16_t esta_man) { + void setArtPollReplyConfigEstaMan(uint16_t esta_man) + { this->art_poll_reply_config.esta_man = esta_man; } - void setArtPollReplyConfigStatus1(uint8_t status1) { + void setArtPollReplyConfigStatus1(uint8_t status1) + { this->art_poll_reply_config.status1 = status1; } - void setArtPollReplyConfigStatus2(uint8_t status2) { + void setArtPollReplyConfigStatus2(uint8_t status2) + { this->art_poll_reply_config.status2 = status2; } - void setArtPollReplyConfigShortName(const String &short_name) { + void setArtPollReplyConfigShortName(const String &short_name) + { this->art_poll_reply_config.short_name = short_name; } - void setArtPollReplyConfigLongName(const String &long_name) { + void setArtPollReplyConfigLongName(const String &long_name) + { this->art_poll_reply_config.long_name = long_name; } - void setArtPollReplyConfigNodeReport(const String &node_report) { + void setArtPollReplyConfigNodeReport(const String &node_report) + { this->art_poll_reply_config.node_report = node_report; } void setArtPollReplyConfig( @@ -302,8 +314,9 @@ class Receiver_ this->setArtPollReplyConfigNodeReport(node_report); } - void setLogger(Print* dest) { - logger = dest; + void setLogger(Print* logger) + { + this->logger = logger; } protected: @@ -312,11 +325,8 @@ class Receiver_ this->stream = &s; } - 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 ec47b97..942b876 100644 --- a/README.md +++ b/README.md @@ -355,7 +355,14 @@ void forwardArtDmxDataToFastLED(uint16_t universe, CRGB* leds, uint16_t num); // set information for artpollreply // 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 setArtPollReplyConfigOem(uint16_t oem); +void setArtPollReplyConfigEstaMan(uint16_t esta_man); +void setArtPollReplyConfigStatus1(uint8_t status1); +void setArtPollReplyConfigStatus2(uint8_t status2); +void setArtPollReplyConfigShortName(const String &short_name); +void setArtPollReplyConfigLongName(const String &long_name); +void setArtPollReplyConfigNodeReport(const String &node_report); +// Set where debug output should go (e.g. setLogger(&Serial); default is nowhere) void setLogger(Print*); ``` From afb822d2f0047067ceb55db9ad77ce9d860f7a58 Mon Sep 17 00:00:00 2001 From: Hideaki Tai Date: Sun, 7 Jul 2024 00:50:36 +0900 Subject: [PATCH 2/2] chore: bump version v0.7.0 --- library.json | 2 +- library.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/library.json b/library.json index bfdaae6..c321045 100644 --- a/library.json +++ b/library.json @@ -11,7 +11,7 @@ "url": "https://github.com/hideakitai", "maintainer": true }, - "version": "0.6.0", + "version": "0.7.0", "license": "MIT", "frameworks": "*", "platforms": "*", diff --git a/library.properties b/library.properties index ca72ee1..8132a67 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=ArtNet -version=0.6.0 +version=0.7.0 author=hideakitai maintainer=hideakitai sentence=Art-Net Sender/Receiver for Arduino (Ethernet, WiFi)