mirror of
https://github.com/HendrikRauh/dmx-interface.git
synced 2025-05-19 10:32:56 +00:00
formatted init commit
This commit is contained in:
parent
b1454a5c5f
commit
45019c6e4c
8 changed files with 130 additions and 119 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,3 +1,5 @@
|
||||||
|
# Development
|
||||||
|
|
||||||
.pio
|
.pio
|
||||||
.vscode/.browse.c_cpp.db*
|
.vscode/.browse.c_cpp.db*
|
||||||
.vscode/c_cpp_properties.json
|
.vscode/c_cpp_properties.json
|
||||||
|
|
8
.vscode/extensions.json
vendored
8
.vscode/extensions.json
vendored
|
@ -1,10 +1,6 @@
|
||||||
{
|
{
|
||||||
// See http://go.microsoft.com/fwlink/?LinkId=827846
|
// See http://go.microsoft.com/fwlink/?LinkId=827846
|
||||||
// for the documentation about the extensions.json format
|
// for the documentation about the extensions.json format
|
||||||
"recommendations": [
|
"recommendations": ["platformio.platformio-ide"],
|
||||||
"platformio.platformio-ide"
|
"unwantedRecommendations": ["ms-vscode.cpptools-extension-pack"]
|
||||||
],
|
|
||||||
"unwantedRecommendations": [
|
|
||||||
"ms-vscode.cpptools-extension-pack"
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,2 +1,3 @@
|
||||||
# dmx-interface
|
# DMX / Artnet Interface
|
||||||
Simple DIY DMX-Interface
|
|
||||||
|
Simple DIY Interface to control
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
This directory is intended for project header files.
|
This directory is intended for project header files.
|
||||||
|
|
||||||
A header file is a file containing C declarations and macro definitions
|
A header file is a file containing C declarations and macro definitions
|
||||||
|
@ -31,9 +30,9 @@ header file names, and at most one dot.
|
||||||
|
|
||||||
Read more about using header files in official GCC documentation:
|
Read more about using header files in official GCC documentation:
|
||||||
|
|
||||||
* Include Syntax
|
- Include Syntax
|
||||||
* Include Operation
|
- Include Operation
|
||||||
* Once-Only Headers
|
- Once-Only Headers
|
||||||
* Computed Includes
|
- Computed Includes
|
||||||
|
|
||||||
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html
|
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
This directory is intended for project specific (private) libraries.
|
This directory is intended for project specific (private) libraries.
|
||||||
PlatformIO will compile them to static libraries and link into executable file.
|
PlatformIO will compile them to static libraries and link into executable file.
|
||||||
|
|
||||||
|
@ -25,9 +24,10 @@ For example, see a structure of the following two libraries `Foo` and `Bar`:
|
||||||
|
|
|
|
||||||
|- platformio.ini
|
|- platformio.ini
|
||||||
|--src
|
|--src
|
||||||
|- main.c
|
|- main.c
|
||||||
|
|
||||||
and a contents of `src/main.c`:
|
and a contents of `src/main.c`:
|
||||||
|
|
||||||
```
|
```
|
||||||
#include <Foo.h>
|
#include <Foo.h>
|
||||||
#include <Bar.h>
|
#include <Bar.h>
|
||||||
|
@ -43,4 +43,5 @@ PlatformIO Library Dependency Finder will find automatically dependent
|
||||||
libraries scanning project source files.
|
libraries scanning project source files.
|
||||||
|
|
||||||
More information about PlatformIO Library Dependency Finder
|
More information about PlatformIO Library Dependency Finder
|
||||||
|
|
||||||
- https://docs.platformio.org/page/librarymanager/ldf.html
|
- https://docs.platformio.org/page/librarymanager/ldf.html
|
||||||
|
|
|
@ -26,47 +26,60 @@ int sendPin = 18;
|
||||||
int receivePin = -1;
|
int receivePin = -1;
|
||||||
|
|
||||||
// DMX value array and size. Entry 0 will hold startbyte, so we need 512+1 elements
|
// DMX value array and size. Entry 0 will hold startbyte, so we need 512+1 elements
|
||||||
uint8_t dmxDataStore[DMXCHANNELS+1] = {};
|
uint8_t dmxDataStore[DMXCHANNELS + 1] = {};
|
||||||
|
|
||||||
|
|
||||||
// Set up the DMX-Protocol
|
// Set up the DMX-Protocol
|
||||||
void DMXESPSerial::init() {
|
void DMXESPSerial::init()
|
||||||
|
{
|
||||||
SERIALPORT.begin(DMXSPEED, DMXFORMAT, receivePin, sendPin);
|
SERIALPORT.begin(DMXSPEED, DMXFORMAT, receivePin, sendPin);
|
||||||
pinMode(sendPin, OUTPUT);
|
pinMode(sendPin, OUTPUT);
|
||||||
dmxStarted = true;
|
dmxStarted = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Function to read DMX data
|
// Function to read DMX data
|
||||||
uint8_t DMXESPSerial::read(int Channel) {
|
uint8_t DMXESPSerial::read(int Channel)
|
||||||
if (dmxStarted == false) init();
|
{
|
||||||
|
if (dmxStarted == false)
|
||||||
|
init();
|
||||||
|
|
||||||
if (Channel < 1) Channel = 1;
|
if (Channel < 1)
|
||||||
if (Channel > DMXCHANNELS) Channel = DMXCHANNELS;
|
Channel = 1;
|
||||||
return(dmxDataStore[Channel]);
|
if (Channel > DMXCHANNELS)
|
||||||
|
Channel = DMXCHANNELS;
|
||||||
|
return (dmxDataStore[Channel]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Function to send DMX data
|
// Function to send DMX data
|
||||||
void DMXESPSerial::write(int Channel, uint8_t value) {
|
void DMXESPSerial::write(int Channel, uint8_t value)
|
||||||
if (dmxStarted == false) init();
|
{
|
||||||
|
if (dmxStarted == false)
|
||||||
|
init();
|
||||||
|
|
||||||
if (Channel < 1) Channel = 1;
|
if (Channel < 1)
|
||||||
if (Channel > DMXCHANNELS) Channel = DMXCHANNELS;
|
Channel = 1;
|
||||||
if (value < 0) value = 0;
|
if (Channel > DMXCHANNELS)
|
||||||
if (value > 255) value = 255;
|
Channel = DMXCHANNELS;
|
||||||
|
if (value < 0)
|
||||||
|
value = 0;
|
||||||
|
if (value > 255)
|
||||||
|
value = 255;
|
||||||
|
|
||||||
dmxDataStore[Channel] = value;
|
dmxDataStore[Channel] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DMXESPSerial::end() {
|
void DMXESPSerial::end()
|
||||||
|
{
|
||||||
SERIALPORT.end();
|
SERIALPORT.end();
|
||||||
dmxStarted = false;
|
dmxStarted = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Function to update the DMX bus
|
// Function to update the DMX bus
|
||||||
void DMXESPSerial::update() {
|
void DMXESPSerial::update()
|
||||||
if (dmxStarted == false) init();
|
{
|
||||||
|
if (dmxStarted == false)
|
||||||
|
init();
|
||||||
|
|
||||||
//Send break
|
// Send break
|
||||||
digitalWrite(sendPin, HIGH);
|
digitalWrite(sendPin, HIGH);
|
||||||
SERIALPORT.begin(BREAKSPEED, BREAKFORMAT, receivePin, sendPin);
|
SERIALPORT.begin(BREAKSPEED, BREAKFORMAT, receivePin, sendPin);
|
||||||
SERIALPORT.write(0);
|
SERIALPORT.write(0);
|
||||||
|
@ -74,7 +87,7 @@ void DMXESPSerial::update() {
|
||||||
delay(1);
|
delay(1);
|
||||||
SERIALPORT.end();
|
SERIALPORT.end();
|
||||||
|
|
||||||
//send data
|
// send data
|
||||||
SERIALPORT.begin(DMXSPEED, DMXFORMAT, receivePin, sendPin);
|
SERIALPORT.begin(DMXSPEED, DMXFORMAT, receivePin, sendPin);
|
||||||
digitalWrite(sendPin, LOW);
|
digitalWrite(sendPin, LOW);
|
||||||
SERIALPORT.write(dmxDataStore, DMXCHANNELS);
|
SERIALPORT.write(dmxDataStore, DMXCHANNELS);
|
||||||
|
|
|
@ -19,11 +19,10 @@
|
||||||
// ---- Methods ----
|
// ---- Methods ----
|
||||||
|
|
||||||
class DMXESPSerial {
|
class DMXESPSerial {
|
||||||
public:
|
public:
|
||||||
void init();
|
void init();
|
||||||
uint8_t read(int Channel);
|
uint8_t read(int Channel);
|
||||||
void write(int channel, uint8_t value);
|
void write(int channel, uint8_t value);void update();
|
||||||
void update();
|
|
||||||
void end();
|
void end();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
48
src/main.cpp
48
src/main.cpp
|
@ -2,20 +2,20 @@
|
||||||
// 2024-10-17 Patrick Schwarz
|
// 2024-10-17 Patrick Schwarz
|
||||||
|
|
||||||
#include <ArtnetWiFi.h>
|
#include <ArtnetWiFi.h>
|
||||||
//#include <ArtnetEther.h>
|
// #include <ArtnetEther.h>
|
||||||
|
|
||||||
#include "ESPDMX.h"
|
#include "ESPDMX.h"
|
||||||
|
|
||||||
// WiFi stuff
|
// WiFi stuff
|
||||||
const char* ssid = "artnet";
|
const char *ssid = "artnet";
|
||||||
const char* pwd = "mbgmbgmbg";
|
const char *pwd = "mbgmbgmbg";
|
||||||
const IPAddress ip(192, 168, 1, 201);
|
const IPAddress ip(192, 168, 1, 201);
|
||||||
const IPAddress gateway(192, 168, 1, 1);
|
const IPAddress gateway(192, 168, 1, 1);
|
||||||
const IPAddress subnet(255, 255, 255, 0);
|
const IPAddress subnet(255, 255, 255, 0);
|
||||||
|
|
||||||
// Art-Net stuff
|
// Art-Net stuff
|
||||||
ArtnetWiFi artnet;
|
ArtnetWiFi artnet;
|
||||||
//const String target_ip = "192.168.1.200";
|
// const String target_ip = "192.168.1.200";
|
||||||
uint8_t universe = 1; // 0 - 15
|
uint8_t universe = 1; // 0 - 15
|
||||||
const uint16_t size = 512;
|
const uint16_t size = 512;
|
||||||
uint8_t data[size];
|
uint8_t data[size];
|
||||||
|
@ -24,23 +24,23 @@ uint8_t value = 0;
|
||||||
// DMX stuff
|
// DMX stuff
|
||||||
DMXESPSerial dmx;
|
DMXESPSerial dmx;
|
||||||
|
|
||||||
|
void setup()
|
||||||
void setup() {
|
{
|
||||||
|
|
||||||
// Serial console
|
// Serial console
|
||||||
//Serial.begin(115200);
|
// Serial.begin(115200);
|
||||||
|
|
||||||
// WiFi stuff
|
// WiFi stuff
|
||||||
//WiFi.begin(ssid, pwd);
|
// WiFi.begin(ssid, pwd);
|
||||||
WiFi.softAP(ssid, pwd);
|
WiFi.softAP(ssid, pwd);
|
||||||
WiFi.softAPConfig(ip, gateway, subnet);
|
WiFi.softAPConfig(ip, gateway, subnet);
|
||||||
//WiFi.config(ip, gateway, subnet);
|
// WiFi.config(ip, gateway, subnet);
|
||||||
//while (WiFi.status() != WL_CONNECTED) {
|
// while (WiFi.status() != WL_CONNECTED) {
|
||||||
// Serial.print(".");
|
// Serial.print(".");
|
||||||
delay(500);
|
delay(500);
|
||||||
//}
|
//}
|
||||||
//Serial.print("WiFi connected, IP = ");
|
// Serial.print("WiFi connected, IP = ");
|
||||||
//Serial.println(WiFi.localIP());
|
// Serial.println(WiFi.localIP());
|
||||||
|
|
||||||
// Initialize Art-Net
|
// Initialize Art-Net
|
||||||
artnet.begin();
|
artnet.begin();
|
||||||
|
@ -49,7 +49,8 @@ void setup() {
|
||||||
dmx.init();
|
dmx.init();
|
||||||
|
|
||||||
// if Artnet packet comes to this universe, this function is called
|
// if Artnet packet comes to this universe, this function is called
|
||||||
artnet.subscribeArtDmxUniverse(universe, [&](const uint8_t *data, uint16_t size, const ArtDmxMetadata& metadata, const ArtNetRemoteInfo& remote) {
|
artnet.subscribeArtDmxUniverse(universe, [&](const uint8_t *data, uint16_t size, const ArtDmxMetadata &metadata, const ArtNetRemoteInfo &remote)
|
||||||
|
{
|
||||||
/*Serial.print("lambda : artnet data from ");
|
/*Serial.print("lambda : artnet data from ");
|
||||||
Serial.print(remote.ip);
|
Serial.print(remote.ip);
|
||||||
Serial.print(":");
|
Serial.print(":");
|
||||||
|
@ -60,19 +61,19 @@ void setup() {
|
||||||
Serial.print(size);
|
Serial.print(size);
|
||||||
Serial.print(") :");*/
|
Serial.print(") :");*/
|
||||||
|
|
||||||
for (size_t i = 0; i < size; ++i) {
|
for (size_t i = 0; i < size; ++i)
|
||||||
dmx.write((i+1), data[i]);
|
{
|
||||||
|
dmx.write((i + 1), data[i]);
|
||||||
// Serial.print(data[i]);
|
// Serial.print(data[i]);
|
||||||
// Serial.print(",");
|
// Serial.print(",");
|
||||||
}
|
}
|
||||||
//Serial.println();
|
// Serial.println();
|
||||||
|
|
||||||
dmx.update();
|
dmx.update(); });
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
// if Artnet packet comes, this function is called to every universe
|
// if Artnet packet comes, this function is called to every universe
|
||||||
artnet.subscribeArtDmx([&](const uint8_t *data, uint16_t size, const ArtDmxMetadata& metadata, const ArtNetRemoteInfo& remote) {
|
artnet.subscribeArtDmx([&](const uint8_t *data, uint16_t size, const ArtDmxMetadata &metadata, const ArtNetRemoteInfo &remote)
|
||||||
|
{
|
||||||
/*Serial.print("received ArtNet data from ");
|
/*Serial.print("received ArtNet data from ");
|
||||||
Serial.print(remote.ip);
|
Serial.print(remote.ip);
|
||||||
Serial.print(":");
|
Serial.print(":");
|
||||||
|
@ -87,11 +88,11 @@ void setup() {
|
||||||
Serial.print(metadata.sequence);
|
Serial.print(metadata.sequence);
|
||||||
Serial.print(", size = ");
|
Serial.print(", size = ");
|
||||||
Serial.print(size);
|
Serial.print(size);
|
||||||
Serial.println(")");*/
|
Serial.println(")");*/ });
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop()
|
||||||
|
{
|
||||||
artnet.parse(); // check if artnet packet has come and execute callback
|
artnet.parse(); // check if artnet packet has come and execute callback
|
||||||
|
|
||||||
/*value = (millis() / 4) % 256;
|
/*value = (millis() / 4) % 256;
|
||||||
|
@ -100,5 +101,4 @@ void loop() {
|
||||||
artnet.setArtDmxData(data, size);
|
artnet.setArtDmxData(data, size);
|
||||||
artnet.streamArtDmxTo(target_ip, universe); // automatically send set data in 40fps
|
artnet.streamArtDmxTo(target_ip, universe); // automatically send set data in 40fps
|
||||||
// artnet.streamArtDmxTo(target_ip, net, subnet, univ); // or you can set net, subnet, and universe */
|
// artnet.streamArtDmxTo(target_ip, net, subnet, univ); // or you can set net, subnet, and universe */
|
||||||
|
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue