-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #79 from MrFrangipane/main
Create ArtnetEtherENC.h
- Loading branch information
Showing
8 changed files
with
304 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#pragma once | ||
#ifndef ARTNET_ETHER_H | ||
#define ARTNET_ETHER_H | ||
|
||
#define ARTNET_ENABLE_ETHER | ||
|
||
#include <Arduino.h> | ||
#include <ArxTypeTraits.h> | ||
#include <ArxContainer.h> | ||
#include <EthernetENC.h> | ||
#include <EthernetUdp.h> | ||
#include "Artnet/util/TeensyDirtySTLErrorSolution/TeensyDirtySTLErrorSolution.h" | ||
#include "Artnet/Manager.h" | ||
|
||
using Artnet = art_net::Manager<EthernetUDP>; | ||
using ArtnetSender = art_net::Sender<EthernetUDP>; | ||
using ArtnetReceiver = art_net::Receiver<EthernetUDP>; | ||
|
||
#endif // ARTNET_ETHER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#include <FastLED.h> // include FastLED *before* Artnet | ||
#include <ArtnetEtherENC.h> | ||
|
||
|
||
// Ethernet stuff | ||
const IPAddress ip(192, 168, 0, 201); | ||
uint8_t mac[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB}; | ||
|
||
ArtnetReceiver artnet; | ||
uint8_t universe = 1; // 0 - 15 | ||
|
||
// FastLED | ||
#define NUM_LEDS 1 | ||
CRGB leds[NUM_LEDS]; | ||
const uint8_t PIN_LED_DATA = 3; | ||
|
||
void setup() { | ||
Serial.begin(115200); | ||
delay(2000); | ||
|
||
FastLED.addLeds<NEOPIXEL, PIN_LED_DATA>(leds, NUM_LEDS); | ||
|
||
Ethernet.begin(mac, ip); | ||
artnet.begin(); | ||
// artnet.subscribe_net(0); // optionally you can change | ||
// artnet.subscribe_subnet(0); // optionally you can change | ||
|
||
// if Artnet packet comes to this universe, forward them to fastled directly | ||
artnet.forward(universe, leds, NUM_LEDS); | ||
|
||
// this can be achieved manually as follows | ||
// if Artnet packet comes to this universe, this function is called | ||
// artnet.subscribe(universe, [&](const uint8_t* data, const uint16_t size) | ||
// { | ||
// // set led | ||
// // artnet data size per packet is 512 max | ||
// // so there is max 170 pixel per packet (per universe) | ||
// for (size_t pixel = 0; pixel < NUM_LEDS; ++pixel) { | ||
// const size_t idx = pixel * 3; | ||
// leds[pixel].r = data[idx + 0]; | ||
// leds[pixel].g = data[idx + 1]; | ||
// leds[pixel].b = data[idx + 2]; | ||
// } | ||
// }); | ||
} | ||
|
||
void loop() { | ||
artnet.parse(); // check if artnet packet has come and execute callback | ||
FastLED.show(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#include <ArtnetEtherENC.h> | ||
|
||
|
||
// Ethernet stuff | ||
const IPAddress ip(192, 168, 0, 201); | ||
uint8_t mac[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB}; | ||
|
||
ArtnetReceiver artnet; | ||
uint32_t universe1 = 1; // 0 - 15 | ||
uint32_t universe2 = 2; // 0 - 15 | ||
|
||
void callback(const uint8_t* data, const uint16_t size) { | ||
// you can also use pre-defined callbacks | ||
} | ||
|
||
void setup() { | ||
Serial.begin(115200); | ||
|
||
Ethernet.begin(mac, ip); | ||
artnet.begin(); | ||
// artnet.subscribe_net(0); // optionally you can change | ||
// artnet.subscribe_subnet(0); // optionally you can change | ||
|
||
// if Artnet packet comes to this universe, this function is called | ||
artnet.subscribe(universe1, [&](const uint8_t* data, const uint16_t size) { | ||
Serial.print("artnet data (universe : "); | ||
Serial.print(universe1); | ||
Serial.print(", size = "); | ||
Serial.print(size); | ||
Serial.print(") :"); | ||
for (size_t i = 0; i < size; ++i) { | ||
Serial.print(data[i]); | ||
Serial.print(","); | ||
} | ||
Serial.println(); | ||
}); | ||
|
||
// you can also use pre-defined callbacks | ||
artnet.subscribe(universe2, callback); | ||
} | ||
|
||
void loop() { | ||
artnet.parse(); // check if artnet packet has come and execute callback | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#ifdef __AVR__ | ||
#warning THIS EXAMPLE MAY USE TOO MUCH MEMORY FOR AVR. WE RECOMMEND TO USE SENDER OR RECEIVER ONLY. | ||
#endif | ||
|
||
#include <ArtnetEtherENC.h> | ||
|
||
|
||
// Ethernet stuff | ||
const IPAddress ip(192, 168, 0, 201); | ||
uint8_t mac[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB}; | ||
|
||
Artnet artnet; | ||
const String target_ip = "192.168.0.200"; | ||
uint8_t universe = 1; // 0 - 15 | ||
|
||
const uint16_t size = 512; | ||
uint8_t data[size]; | ||
uint8_t value = 0; | ||
|
||
void setup() { | ||
Serial.begin(115200); | ||
delay(2000); | ||
|
||
Ethernet.begin(mac, ip); | ||
artnet.begin(); | ||
// artnet.begin(net, subnet); // optionally you can change | ||
|
||
Serial.println("set subscriber"); | ||
|
||
// if Artnet packet comes to this universe, this function is called | ||
artnet.subscribe(universe, [](const uint8_t* data, const uint16_t size) { | ||
Serial.print("artnet data (universe : "); | ||
Serial.print(universe); | ||
Serial.print(", size = "); | ||
Serial.print(size); | ||
Serial.print(") :"); | ||
for (size_t i = 0; i < size; ++i) { | ||
Serial.print(data[i]); | ||
Serial.print(","); | ||
} | ||
Serial.println(); | ||
}); | ||
|
||
// if Artnet packet comes, this function is called to every universe | ||
artnet.subscribe([&](const uint32_t univ, const uint8_t* data, const uint16_t size) { | ||
Serial.print("ArtNet data has come to universe: "); | ||
Serial.println(univ); | ||
}); | ||
|
||
Serial.println("start"); | ||
} | ||
|
||
void loop() { | ||
artnet.parse(); // check if artnet packet has come and execute callback | ||
|
||
value = (millis() / 4) % 256; | ||
memset(data, value, size); | ||
|
||
artnet.streaming_data(data, size); | ||
artnet.streaming(target_ip, universe); // automatically send set data in 40fps | ||
// artnet.streaming(target_ip, net, subnet, univ); // or you can set net, subnet, and universe | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#include <ArtnetEtherENC.h> | ||
|
||
|
||
// Ethernet stuff | ||
const IPAddress ip(192, 168, 0, 201); | ||
uint8_t mac[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB}; | ||
|
||
ArtnetSender artnet; | ||
const String target_ip = "192.168.0.200"; | ||
uint32_t universe = 1; | ||
|
||
const uint16_t size = 512; | ||
uint8_t data[size]; | ||
uint8_t value = 0; | ||
|
||
void setup() { | ||
Serial.begin(115200); | ||
delay(2000); | ||
|
||
Ethernet.begin(mac, ip); | ||
artnet.begin(); | ||
// artnet.begin(net, subnet); // optionally you can change | ||
|
||
Serial.println("start"); | ||
#ifdef UDP_TX_PACKET_MAX_SIZE | ||
Serial.println(UDP_TX_PACKET_MAX_SIZE); | ||
#endif | ||
} | ||
|
||
void loop() { | ||
value = (millis() / 4) % 256; | ||
memset(data, value, size); | ||
|
||
artnet.streaming_data(data, size); | ||
artnet.streaming(target_ip, universe); // automatically send set data in 40fps | ||
// artnet.streaming(target_ip, net, subnet, univ); // or you can set net, subnet, and universe | ||
} |