Skip to content

Commit

Permalink
Merge pull request #122 from hideakitai/fix/swin-and-swout
Browse files Browse the repository at this point in the history
Fix/swin and swout
  • Loading branch information
hideakitai authored Aug 1, 2024
2 parents 9a3d20c + 34dac19 commit 151eede
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 10 deletions.
19 changes: 17 additions & 2 deletions Artnet/ArtPollReply.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,18 @@ struct Config
String short_name {"Arduino ArtNet"};
String long_name {"Ardino ArtNet Protocol by hideakitai/ArtNet"};
String node_report {""};
// Four universes from Device to Controller
// NOTE: Only low 4 bits of the universes
// NOTE: Upper 11 bits of the universes will be
// shared with the subscribed universe (net, subnet)
// e.g.) If you have subscribed universe 0x1234,
// you can set the device to controller universes
// from 0x1230 to 0x123F (sw_in will be from 0x0 to 0xF).
// So, I recommned subscribing only in the range of
// 0x1230 to 0x123F if you want to set the sw_in.
// REF: Please refer the Art-Net spec for the detail.
// https://art-net.org.uk/downloads/art-net.pdf
uint8_t sw_in[4] {0};
};

inline Packet generatePacketFrom(const IPAddress &my_ip, const uint8_t my_mac[6], uint16_t universe, const Config &metadata)
Expand Down Expand Up @@ -105,8 +117,11 @@ inline Packet generatePacketFrom(const IPAddress &my_ip, const uint8_t my_mac[6]
r.net_sw = (universe >> 8) & 0x7F;
r.sub_sw = (universe >> 4) & 0x0F;
// https://github.com/hideakitai/ArtNet/issues/81
r.sw_in[0] = (universe >> 0) & 0x0F;
r.sw_out[0] = 0; // dummy: output port is flexible
// https://github.com/hideakitai/ArtNet/issues/121
r.sw_out[0] = (universe >> 0) & 0x0F;
for (size_t i = 0; i < 4; ++i) {
r.sw_in[i] = metadata.sw_in[i] & 0x0F;
}
r.port_types[0] = 0xC0; // I/O available by DMX512
r.good_input[0] = 0x80; // Data received without error
r.good_output[0] = 0x80; // Data transmitted without error
Expand Down
27 changes: 26 additions & 1 deletion Artnet/Receiver.h
Original file line number Diff line number Diff line change
Expand Up @@ -296,14 +296,34 @@ class Receiver_
{
this->art_poll_reply_config.node_report = node_report;
}
void setArtPollReplyConfigSwIn(size_t index, uint8_t sw_in)
{
if (index < 4) {
this->art_poll_reply_config.sw_in[index] = sw_in;
}
}
void setArtPollReplyConfigSwIn(uint8_t sw_in[4])
{
for (size_t i = 0; i < 4; ++i) {
this->art_poll_reply_config.sw_in[i] = sw_in[i];
}
}
void setArtPollReplyConfigSwIn(uint8_t sw_in_0, uint8_t sw_in_1, uint8_t sw_in_2, uint8_t sw_in_3)
{
this->setArtPollReplyConfigSwIn(0, sw_in_0);
this->setArtPollReplyConfigSwIn(1, sw_in_1);
this->setArtPollReplyConfigSwIn(2, sw_in_2);
this->setArtPollReplyConfigSwIn(3, sw_in_3);
}
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
const String &node_report,
uint8_t sw_in[4]
) {
this->setArtPollReplyConfigOem(oem);
this->setArtPollReplyConfigEstaMan(esta_man);
Expand All @@ -312,6 +332,11 @@ class Receiver_
this->setArtPollReplyConfigShortName(short_name);
this->setArtPollReplyConfigLongName(long_name);
this->setArtPollReplyConfigNodeReport(node_report);
this->setArtPollReplyConfigSwIn(sw_in);
}
void setArtPollReplyConfig(const ArtPollReplyConfig &cfg)
{
this->art_poll_reply_config = cfg;
}

void setLogger(Print* logger)
Expand Down
43 changes: 38 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,15 +230,15 @@ void loop() {
- The relationship of Net (0-127), Sub-Net (0-15), 4-bit Universe (0-15) and 15-bit Universe (0-32767) is `universe15bit = (net << 8) | (subnet << 4) | universe4bit`
- You can subscribe ArtDmx data for Net (0-127), Sub-Net (0-15), and 4-bit Universe (0-15) like `artnet.subscribeArtDmxUniverse(net, subnet, universe, callback)`
- Or you can use 15-bit Universe (0-32767) can be set lnke `artnet.subscribeArtDmxUniverse(universe, callback)`
- Subscribed universes (targets of the callbacks) are automatically reflected to `net_sw` `sub_sw` `sw_in` in `ArtPollreply`
- Subscribed universes (targets of the callbacks) are automatically reflected to `net_sw` `sub_sw` `sw_out` in `ArtPollreply`

### ArtPollReply Configuration

- This library supports `ArtPoll` and `ArtPollReply`
- `ArtPoll` is automatically parsed and sends `ArtPollReply`
- You can configure the following information of by `setArtPollReplyConfig()`
- Other settings are set automatically based on registerd callbacks
- Please refer [here](https://art-net.org.uk/how-it-works/discovery-packets/artpollreply/) for more information
- Please refer [here](https://art-net.org.uk/downloads/art-net.pdf) for more information

```C++
struct ArtPollReplyMetadata
Expand All @@ -250,9 +250,38 @@ struct ArtPollReplyMetadata
String short_name {"Arduino ArtNet"};
String long_name {"Ardino ArtNet Protocol by hideakitai/ArtNet"};
String node_report {""};
// Four universes from Device to Controller
// NOTE: Only low 4 bits of the universes
// NOTE: Upper 11 bits of the universes will be
// shared with the subscribed universe (net, subnet)
// e.g.) If you have subscribed universe 0x1234,
// you can set the device to controller universes
// from 0x1230 to 0x123F (sw_in will be from 0x0 to 0xF).
// So, I recommned subscribing only in the range of
// 0x1230 to 0x123F if you want to set the sw_in.
// REF: Please refer the Art-Net spec for the detail.
// https://art-net.org.uk/downloads/art-net.pdf
uint8_t sw_in[4] {0};
};
```

```c++
// set information for artpollreply individually
// https://art-net.org.uk/downloads/art-net.pdf
void setArtPollReplyConfig(const ArtPollReplyConfig &cfg);
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, uint8_t sw_in[4]);
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);
void setArtPollReplyConfigSwIn(size_t index, uint8_t sw_in);
void setArtPollReplyConfigSwIn(uint8_t sw_in[4]);
void setArtPollReplyConfigSwIn(uint8_t sw_in_0, uint8_t sw_in_1, uint8_t sw_in_2, uint8_t sw_in_3);
```
## ArtTrigger
You can send/subscribe `ArtTrigger` using the follwing APIs. Please refer [here](https://art-net.org.uk/how-it-works/time-keeping-triggering/arttrigger/) for more information.
Expand Down Expand Up @@ -352,16 +381,20 @@ void unsubscribeArtTrigger();
// set artdmx data to CRGB (FastLED) directly
void forwardArtDmxDataToFastLED(uint8_t net, uint8_t subnet, uint8_t universe, CRGB* leds, uint16_t num);
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 information for artpollreply individually
// https://art-net.org.uk/downloads/art-net.pdf
void setArtPollReplyConfig(const ArtPollReplyConfig &cfg);
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, uint8_t sw_in[4]);
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);
void setArtPollReplyConfigSwIn(size_t index, uint8_t sw_in);
void setArtPollReplyConfigSwIn(uint8_t sw_in[4]);
void setArtPollReplyConfigSwIn(uint8_t sw_in_0, uint8_t sw_in_1, uint8_t sw_in_2, uint8_t sw_in_3);
// 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.7.1",
"version": "0.8.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.7.1
version=0.8.0
author=hideakitai
maintainer=hideakitai
sentence=Art-Net Sender/Receiver for Arduino (Ethernet, WiFi)
Expand Down

0 comments on commit 151eede

Please sign in to comment.