Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor/logger and readme #118

Merged
merged 2 commits into from
Jul 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 39 additions & 29 deletions Artnet/Receiver.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <typename S>
class Receiver_
{
Expand All @@ -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
Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
}
Expand All @@ -138,15 +143,15 @@ class Receiver_
-> std::enable_if_t<arx::is_callable<Fn>::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;
Expand Down Expand Up @@ -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;
Expand All @@ -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(
Expand All @@ -302,8 +314,9 @@ class Receiver_
this->setArtPollReplyConfigNodeReport(node_report);
}

void setLogger(Print* dest) {
logger = dest;
void setLogger(Print* logger)
{
this->logger = logger;
}

protected:
Expand All @@ -312,11 +325,8 @@ class Receiver_
this->stream = &s;
}


private:

Print* logger = &no_log;

bool checkID() const
{
const char* idptr = reinterpret_cast<const char*>(this->packet.data());
Expand Down
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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*);
```

Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"url": "https://github.com/hideakitai",
"maintainer": true
},
"version": "0.6.0",
"version": "0.7.0",
"license": "MIT",
"frameworks": "*",
"platforms": "*",
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
Loading