From 4157c8a21d122cd3cc56258824bcacbe1cc16cf4 Mon Sep 17 00:00:00 2001 From: Hendrik Rauh <114620133+HendrikRauh@users.noreply.github.com> Date: Sat, 2 Nov 2024 19:34:21 +0100 Subject: [PATCH 1/2] DMX-22 started modification of lib --- src/ESPDMX.cpp | 63 ++++++++++++++++++++++++++------------------------ src/ESPDMX.h | 9 ++++---- src/main.cpp | 12 ++++++---- 3 files changed, 46 insertions(+), 38 deletions(-) diff --git a/src/ESPDMX.cpp b/src/ESPDMX.cpp index efdc7a2..3ac7775 100644 --- a/src/ESPDMX.cpp +++ b/src/ESPDMX.cpp @@ -5,7 +5,7 @@ // Copyright (C) 2015 Rick // This work is licensed under a GNU style license. // -// Last change: Marcel Seerig +// Last change: Hendrik Rauh // // Documentation and samples are available at https://github.com/Rickgg/ESP-Dmx // - - - - - @@ -13,6 +13,9 @@ /* ----- LIBRARIES ----- */ #include #include "ESPDMX.h" +#include + +#define MAX_IDS 3 #define DMXSPEED 250000 #define DMXFORMAT SERIAL_8N2 @@ -21,41 +24,45 @@ #define SERIALPORT Serial0 #define DMXCHANNELS 512 -bool dmxStarted = false; -int sendPin = 18; -int receivePin = -1; +int sendPin[] = {}; +int recvPin[] = {}; // DMX value array and size. Entry 0 will hold startbyte, so we need 512+1 elements -uint8_t dmxDataStore[DMXCHANNELS + 1] = {}; +// std::vector dmxDataStores(MAX_IDS); +// uint8_t dmxDataStores[MAX_IDS][DMXCHANNELS + 1]; + +struct dmxPorts +{ + uint8_t id; + int sendPin; + int recvPin; + bool started; + uint8_t dmxDataStore[DMXCHANNELS + 1]; +}; // Set up the DMX-Protocol -void DMXESPSerial::init() +void DMXESPSerial::init(int id, int pinSend, int pinRecv) { - SERIALPORT.begin(DMXSPEED, DMXFORMAT, receivePin, sendPin); - pinMode(sendPin, OUTPUT); - dmxStarted = true; + sendPin[id] = pinSend; + recvPin[id] = pinRecv; + SERIALPORT.begin(DMXSPEED, DMXFORMAT, recvPin[id], sendPin[id]); + pinMode(sendPin[id], OUTPUT); } // Function to read DMX data -uint8_t DMXESPSerial::read(int Channel) +uint8_t DMXESPSerial::read(int id, int Channel) { - if (dmxStarted == false) - init(); - if (Channel < 1) Channel = 1; if (Channel > DMXCHANNELS) Channel = DMXCHANNELS; - return (dmxDataStore[Channel]); + return (dmxDataStores[id][Channel]); } // Function to send DMX data -void DMXESPSerial::write(int Channel, uint8_t value) +void DMXESPSerial::write(int id, int Channel, uint8_t value) { - if (dmxStarted == false) - init(); - - if (Channel < 1) + s if (Channel < 1) Channel = 1; if (Channel > DMXCHANNELS) Channel = DMXCHANNELS; @@ -64,33 +71,29 @@ void DMXESPSerial::write(int Channel, uint8_t value) if (value > 255) value = 255; - dmxDataStore[Channel] = value; + dmxDataStores[id][Channel] = value; } void DMXESPSerial::end() { SERIALPORT.end(); - dmxStarted = false; } // Function to update the DMX bus -void DMXESPSerial::update() +void DMXESPSerial::update(int id) { - if (dmxStarted == false) - init(); - // Send break - digitalWrite(sendPin, HIGH); - SERIALPORT.begin(BREAKSPEED, BREAKFORMAT, receivePin, sendPin); + digitalWrite(sendPin[id], HIGH); + SERIALPORT.begin(BREAKSPEED, BREAKFORMAT, recvPin[id], sendPin[id]); SERIALPORT.write(0); SERIALPORT.flush(); delay(1); SERIALPORT.end(); // send data - SERIALPORT.begin(DMXSPEED, DMXFORMAT, receivePin, sendPin); - digitalWrite(sendPin, LOW); - SERIALPORT.write(dmxDataStore, DMXCHANNELS); + SERIALPORT.begin(DMXSPEED, DMXFORMAT, recvPin[id], sendPin[id]); + digitalWrite(sendPin[id], LOW); + SERIALPORT.write(dmxDataStores[id], DMXCHANNELS); SERIALPORT.flush(); delay(1); SERIALPORT.end(); diff --git a/src/ESPDMX.h b/src/ESPDMX.h index 8cdc522..748a727 100644 --- a/src/ESPDMX.h +++ b/src/ESPDMX.h @@ -5,7 +5,7 @@ // Copyright (C) 2015 Rick // This work is licensed under a GNU style license. // -// Last change: Marcel Seerig +// Last change: Hendrik Rauh // // Documentation and samples are available at https://github.com/Rickgg/ESP-Dmx // - - - - - @@ -20,10 +20,11 @@ class DMXESPSerial { public: - void init(); - uint8_t read(int Channel); - void write(int channel, uint8_t value);void update(); + void init(int id, int pinSend, int pinRecv); + uint8_t read(int id, int Channel); + void write(int id, int channel, uint8_t value);void update(); void end(); + void update(int id); }; #endif diff --git a/src/main.cpp b/src/main.cpp index eec27b7..91faa1c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -8,7 +8,9 @@ #include Preferences config; -DMXESPSerial dmx; + +DMXESPSerial dmx1; +DMXESPSerial dmx2; AsyncWebServer server(80); @@ -16,6 +18,8 @@ ArtnetWiFi artnet; const uint16_t size = 512; uint8_t data[size]; +int selectedId = 0; + void setup() { Serial.begin(9600); @@ -51,17 +55,17 @@ void setup() artnet.begin(); // Initialize DMX ports - dmx.init(); + dmx.init(0, 19, -1); // 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) { for (size_t i = 0; i < size; ++i) { - dmx.write((i + 1), data[i]); + dmx.write(selectedId, (i + 1), data[i]); } - dmx.update(); }); + dmx.update(selectedId); }); // 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) {}); From ab377defb54de50cc4a55e67ee4b32270d07b46e Mon Sep 17 00:00:00 2001 From: RaffaelW Date: Sat, 2 Nov 2024 20:18:06 +0100 Subject: [PATCH 2/2] finished modification of lob --- src/ESPDMX.cpp | 54 +++++++++++++++----------------------------------- src/ESPDMX.h | 28 +++++++++++++++++--------- src/main.cpp | 8 +++----- 3 files changed, 38 insertions(+), 52 deletions(-) diff --git a/src/ESPDMX.cpp b/src/ESPDMX.cpp index 3ac7775..1d361d9 100644 --- a/src/ESPDMX.cpp +++ b/src/ESPDMX.cpp @@ -13,56 +13,34 @@ /* ----- LIBRARIES ----- */ #include #include "ESPDMX.h" -#include - -#define MAX_IDS 3 - -#define DMXSPEED 250000 -#define DMXFORMAT SERIAL_8N2 -#define BREAKSPEED 83333 -#define BREAKFORMAT SERIAL_8N1 -#define SERIALPORT Serial0 -#define DMXCHANNELS 512 - -int sendPin[] = {}; -int recvPin[] = {}; // DMX value array and size. Entry 0 will hold startbyte, so we need 512+1 elements // std::vector dmxDataStores(MAX_IDS); // uint8_t dmxDataStores[MAX_IDS][DMXCHANNELS + 1]; -struct dmxPorts -{ - uint8_t id; - int sendPin; - int recvPin; - bool started; - uint8_t dmxDataStore[DMXCHANNELS + 1]; -}; - // Set up the DMX-Protocol -void DMXESPSerial::init(int id, int pinSend, int pinRecv) +void DMXESPSerial::init(int pinSend, int pinRecv) { - sendPin[id] = pinSend; - recvPin[id] = pinRecv; - SERIALPORT.begin(DMXSPEED, DMXFORMAT, recvPin[id], sendPin[id]); - pinMode(sendPin[id], OUTPUT); + sendPin = pinSend; + recvPin = pinRecv; + SERIALPORT.begin(DMXSPEED, DMXFORMAT, recvPin, sendPin); + pinMode(sendPin, OUTPUT); } // Function to read DMX data -uint8_t DMXESPSerial::read(int id, int Channel) +uint8_t DMXESPSerial::read(int Channel) { if (Channel < 1) Channel = 1; if (Channel > DMXCHANNELS) Channel = DMXCHANNELS; - return (dmxDataStores[id][Channel]); + return (dmxDataStore[Channel]); } // Function to send DMX data -void DMXESPSerial::write(int id, int Channel, uint8_t value) +void DMXESPSerial::write(int Channel, uint8_t value) { - s if (Channel < 1) + if (Channel < 1) Channel = 1; if (Channel > DMXCHANNELS) Channel = DMXCHANNELS; @@ -71,7 +49,7 @@ void DMXESPSerial::write(int id, int Channel, uint8_t value) if (value > 255) value = 255; - dmxDataStores[id][Channel] = value; + dmxDataStore[Channel] = value; } void DMXESPSerial::end() @@ -80,20 +58,20 @@ void DMXESPSerial::end() } // Function to update the DMX bus -void DMXESPSerial::update(int id) +void DMXESPSerial::update() { // Send break - digitalWrite(sendPin[id], HIGH); - SERIALPORT.begin(BREAKSPEED, BREAKFORMAT, recvPin[id], sendPin[id]); + digitalWrite(sendPin, HIGH); + SERIALPORT.begin(BREAKSPEED, BREAKFORMAT, recvPin, sendPin); SERIALPORT.write(0); SERIALPORT.flush(); delay(1); SERIALPORT.end(); // send data - SERIALPORT.begin(DMXSPEED, DMXFORMAT, recvPin[id], sendPin[id]); - digitalWrite(sendPin[id], LOW); - SERIALPORT.write(dmxDataStores[id], DMXCHANNELS); + SERIALPORT.begin(DMXSPEED, DMXFORMAT, recvPin, sendPin); + digitalWrite(sendPin, LOW); + SERIALPORT.write(dmxDataStore, DMXCHANNELS); SERIALPORT.flush(); delay(1); SERIALPORT.end(); diff --git a/src/ESPDMX.h b/src/ESPDMX.h index 748a727..0be98cf 100644 --- a/src/ESPDMX.h +++ b/src/ESPDMX.h @@ -12,19 +12,29 @@ #include - #ifndef ESPDMX_h #define ESPDMX_h -// ---- Methods ---- +#define DMXSPEED 250000 +#define DMXFORMAT SERIAL_8N2 +#define BREAKSPEED 83333 +#define BREAKFORMAT SERIAL_8N1 +#define SERIALPORT Serial0 +#define DMXCHANNELS 512 -class DMXESPSerial { - public: - void init(int id, int pinSend, int pinRecv); - uint8_t read(int id, int Channel); - void write(int id, int channel, uint8_t value);void update(); - void end(); - void update(int id); +class DMXESPSerial +{ +public: + int sendPin; + int recvPin; + bool started; + uint8_t dmxDataStore[DMXCHANNELS + 1]; + + void init(int pinSend, int pinRecv); + uint8_t read(int Channel); + void write(int channel, uint8_t value); + void update(); + void end(); }; #endif diff --git a/src/main.cpp b/src/main.cpp index 91faa1c..07fd1e1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -18,8 +18,6 @@ ArtnetWiFi artnet; const uint16_t size = 512; uint8_t data[size]; -int selectedId = 0; - void setup() { Serial.begin(9600); @@ -55,17 +53,17 @@ void setup() artnet.begin(); // Initialize DMX ports - dmx.init(0, 19, -1); + dmx1.init(19, -1); // 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) { for (size_t i = 0; i < size; ++i) { - dmx.write(selectedId, (i + 1), data[i]); + dmx1.write((i + 1), data[i]); } - dmx.update(selectedId); }); + dmx1.update(); }); // 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) {});