diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index bfacece..ca4c1d7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -75,6 +75,7 @@ jobs: - source-path: ./ - name: ArxContainer - name: ArxTypeTraits + - name: PollingTimer - name: WiFi - name: FastLED verbose: true @@ -122,6 +123,7 @@ jobs: - source-path: ./ - name: ArxContainer - name: ArxTypeTraits + - name: PollingTimer - name: WiFiNINA - name: VidorPeripherals - name: FastLED @@ -161,6 +163,7 @@ jobs: - source-path: ./ - name: ArxContainer - name: ArxTypeTraits + - name: PollingTimer verbose: true build-ethernet: @@ -251,6 +254,7 @@ jobs: - source-path: ./ - name: ArxContainer - name: ArxTypeTraits + - name: PollingTimer - name: Ethernet - name: FastLED verbose: true @@ -295,6 +299,7 @@ jobs: - source-path: ./ - name: ArxContainer - name: ArxTypeTraits + - name: PollingTimer - name: FastLED verbose: true @@ -382,6 +387,7 @@ jobs: - source-path: ./ - name: ArxContainer - name: ArxTypeTraits + - name: PollingTimer - name: FastLED - source-url: https://github.com/JAndrassy/EthernetENC.git verbose: true @@ -431,6 +437,7 @@ jobs: - source-path: ./ - name: ArxContainer - name: ArxTypeTraits + - name: PollingTimer - name: WiFi - name: Ethernet verbose: true diff --git a/Artnet/ArtDmx.h b/Artnet/ArtDmx.h index 57b1403..c96483a 100644 --- a/Artnet/ArtDmx.h +++ b/Artnet/ArtDmx.h @@ -38,7 +38,7 @@ using CallbackType = std::function= 201103L // Have libstdc++11 using CallbackMap = std::map; #else -using CallbackMap = arx::stdx::map; +using CallbackMap = arx::stdx::map; #endif inline Metadata generateMetadataFrom(const uint8_t *packet) diff --git a/Artnet/ArtNzs.h b/Artnet/ArtNzs.h index 6c52367..b0447fd 100644 --- a/Artnet/ArtNzs.h +++ b/Artnet/ArtNzs.h @@ -38,7 +38,7 @@ using CallbackType = std::function= 201103L // Have libstdc++11 using CallbackMap = std::map; #else -using CallbackMap = arx::stdx::map; +using CallbackMap = arx::stdx::map; #endif inline Metadata generateMetadataFrom(const uint8_t *packet) diff --git a/Artnet/Common.h b/Artnet/Common.h index db0f414..743e6ea 100644 --- a/Artnet/Common.h +++ b/Artnet/Common.h @@ -57,7 +57,7 @@ constexpr uint16_t PROTOCOL_VER {14}; // 0x000E constexpr uint8_t ID_LENGTH {8}; constexpr char ARTNET_ID[ID_LENGTH] {"Art-Net"}; constexpr float DEFAULT_FPS {40.}; -constexpr uint32_t DEFAULT_INTERVAL_MS {(uint32_t)(1000. / DEFAULT_FPS)}; +constexpr double DEFAULT_INTERVAL_MS {1000. / (double)DEFAULT_FPS}; // ArtDmx, ArtTrigger has same structure constexpr uint16_t HEADER_SIZE {18}; @@ -67,6 +67,7 @@ constexpr uint16_t PACKET_SIZE {530}; template using Array = std::array; #else +constexpr size_t FIXED_CONTAINER_CAPACITY = 3; template using Array = arx::stdx::vector; #endif @@ -122,12 +123,12 @@ inline bool operator==(const Destination &rhs, const Destination &lhs) #if ARX_HAVE_LIBSTDCPLUSPLUS >= 201103L // Have libstdc++11 // sender -using LastSendTimeMsMap = std::map; +using LastSendTimeMsMap = std::map; using SequenceMap = std::map; #else // sender -using LastSendTimeMsMap = arx::stdx::map; -using SequenceMap = arx::stdx::map; +using LastSendTimeMsMap = arx::stdx::map; +using SequenceMap = arx::stdx::map; #endif } // namespace art_net diff --git a/Artnet/Sender.h b/Artnet/Sender.h index f198a7e..d3c7bb5 100644 --- a/Artnet/Sender.h +++ b/Artnet/Sender.h @@ -8,6 +8,7 @@ #include "ArtTrigger.h" #include "ArtSync.h" #include "SenderTraits.h" +#include namespace art_net { @@ -20,6 +21,7 @@ class Sender_ { S* stream; Array packet; + PollingTimer timer; LastSendTimeMsMap last_send_times; SequenceMap dmx_sequences; SequenceMap nzs_sequences; @@ -30,6 +32,7 @@ class Sender_ Sender_() { this->packet.resize(PACKET_SIZE); + this->timer.start(); } #endif @@ -57,9 +60,9 @@ class Sender_ void streamArtDmxTo(const String& ip, uint8_t net, uint8_t subnet, uint8_t universe, uint8_t physical) { Destination dest {ip, net, subnet, universe}; - uint32_t now = millis(); + double now = timer.msec(); if (this->last_send_times.find(dest) == this->last_send_times.end()) { - this->last_send_times.insert(std::make_pair(dest, uint32_t(0))); + this->last_send_times.insert(std::make_pair(dest, 0.0)); } if (now >= this->last_send_times[dest] + DEFAULT_INTERVAL_MS) { this->sendArxDmxInternal(dest, physical); @@ -91,9 +94,9 @@ class Sender_ void streamArtNzsTo(const String& ip, uint8_t net, uint8_t subnet, uint8_t universe, uint8_t start_code) { Destination dest {ip, net, subnet, universe}; - uint32_t now = millis(); + double now = timer.msec(); if (this->last_send_times.find(dest) == this->last_send_times.end()) { - this->last_send_times.insert(std::make_pair(dest, uint32_t(0))); + this->last_send_times.insert(std::make_pair(dest, 0.0)); } if (now >= this->last_send_times[dest] + DEFAULT_INTERVAL_MS) { this->sendArxNzsInternal(dest, start_code); diff --git a/README.md b/README.md index 223d66f..d2d1a8e 100644 --- a/README.md +++ b/README.md @@ -400,6 +400,8 @@ void setLogger(Print*); Some boards without enough memory (e.g. Uno, Nano, etc.) may not be able to use integrated sender/receiver because of the lack of enough memory. Please consider to use more powerful board or to use only sender OR receiver. +In addition, those boards have limitation of the number of callbacks and destinations (see `FIXED_CONTAINER_CAPACITY`) because of the lack of memory. Please consider to reduce the number of callbacks/destinations or to use more powerful board. + ## Reference - [Spec (Art-Net 4)](http://artisticlicence.com/WebSiteMaster/User%20Guides/art-net.pdf) diff --git a/library.json b/library.json index 8fbcf1d..670f91b 100644 --- a/library.json +++ b/library.json @@ -17,6 +17,7 @@ "platforms": "*", "dependencies": { "hideakitai/ArxContainer": ">=0.6.0", - "hideakitai/ArxTypeTraits": ">=0.3.2" + "hideakitai/ArxTypeTraits": ">=0.3.2", + "hideakitai/PollingTimer": "*" } } diff --git a/library.properties b/library.properties index 8c3b95a..f39e746 100644 --- a/library.properties +++ b/library.properties @@ -7,4 +7,4 @@ paragraph=Art-Net Sender/Receiver for Arduino (Ethernet, WiFi) category=Communication url=https://github.com/hideakitai/ArtNet architectures=* -depends=ArxContainer (>=0.6.0), ArxTypeTraits (>=0.3.2) +depends=ArxContainer (>=0.6.0), ArxTypeTraits (>=0.3.2), PollingTimer