From 45019c6e4c7f175efd9e015235c821e30477b117 Mon Sep 17 00:00:00 2001 From: Hendrik Rauh <114620133+HendrikRauh@users.noreply.github.com> Date: Thu, 17 Oct 2024 20:20:17 +0200 Subject: [PATCH] formatted init commit --- .gitignore | 2 + .vscode/extensions.json | 8 +--- README.md | 5 ++- include/README | 9 ++-- lib/README | 35 ++++++++------- src/ESPDMX.cpp | 99 +++++++++++++++++++++++------------------ src/ESPDMX.h | 11 +++-- src/main.cpp | 80 ++++++++++++++++----------------- 8 files changed, 130 insertions(+), 119 deletions(-) diff --git a/.gitignore b/.gitignore index 89cc49c..691739c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +# Development + .pio .vscode/.browse.c_cpp.db* .vscode/c_cpp_properties.json diff --git a/.vscode/extensions.json b/.vscode/extensions.json index 080e70d..e24696e 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -1,10 +1,6 @@ { // See http://go.microsoft.com/fwlink/?LinkId=827846 // for the documentation about the extensions.json format - "recommendations": [ - "platformio.platformio-ide" - ], - "unwantedRecommendations": [ - "ms-vscode.cpptools-extension-pack" - ] + "recommendations": ["platformio.platformio-ide"], + "unwantedRecommendations": ["ms-vscode.cpptools-extension-pack"] } diff --git a/README.md b/README.md index e750175..07c173a 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,3 @@ -# dmx-interface -Simple DIY DMX-Interface +# DMX / Artnet Interface + +Simple DIY Interface to control diff --git a/include/README b/include/README index 194dcd4..e2d5e38 100644 --- a/include/README +++ b/include/README @@ -1,4 +1,3 @@ - This directory is intended for project header files. 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: -* Include Syntax -* Include Operation -* Once-Only Headers -* Computed Includes +- Include Syntax +- Include Operation +- Once-Only Headers +- Computed Includes https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html diff --git a/lib/README b/lib/README index 2593a33..bc6a01c 100644 --- a/lib/README +++ b/lib/README @@ -1,4 +1,3 @@ - This directory is intended for project specific (private) libraries. PlatformIO will compile them to static libraries and link into executable file. @@ -8,26 +7,27 @@ The source code of each library should be placed in an own separate directory For example, see a structure of the following two libraries `Foo` and `Bar`: |--lib -| | -| |--Bar -| | |--docs -| | |--examples -| | |--src -| | |- Bar.c -| | |- Bar.h -| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html -| | -| |--Foo -| | |- Foo.c -| | |- Foo.h -| | -| |- README --> THIS FILE +| | +| |--Bar +| | |--docs +| | |--examples +| | |--src +| | |- Bar.c +| | |- Bar.h +| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html +| | +| |--Foo +| | |- Foo.c +| | |- Foo.h +| | +| |- README --> THIS FILE | |- platformio.ini |--src - |- main.c +|- main.c and a contents of `src/main.c`: + ``` #include #include @@ -43,4 +43,5 @@ PlatformIO Library Dependency Finder will find automatically dependent libraries scanning project source files. More information about PlatformIO Library Dependency Finder -- https://docs.platformio.org/page/librarymanager/ldf.html + +- https://docs.platformio.org/page/librarymanager/ldf.html diff --git a/src/ESPDMX.cpp b/src/ESPDMX.cpp index 79a05b5..efdc7a2 100644 --- a/src/ESPDMX.cpp +++ b/src/ESPDMX.cpp @@ -14,71 +14,84 @@ #include #include "ESPDMX.h" -#define DMXSPEED 250000 -#define DMXFORMAT SERIAL_8N2 -#define BREAKSPEED 83333 -#define BREAKFORMAT SERIAL_8N1 -#define SERIALPORT Serial0 -#define DMXCHANNELS 512 +#define DMXSPEED 250000 +#define DMXFORMAT SERIAL_8N2 +#define BREAKSPEED 83333 +#define BREAKFORMAT SERIAL_8N1 +#define SERIALPORT Serial0 +#define DMXCHANNELS 512 bool dmxStarted = false; int sendPin = 18; int receivePin = -1; // 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 -void DMXESPSerial::init() { - SERIALPORT.begin(DMXSPEED, DMXFORMAT, receivePin, sendPin); - pinMode(sendPin, OUTPUT); - dmxStarted = true; +void DMXESPSerial::init() +{ + SERIALPORT.begin(DMXSPEED, DMXFORMAT, receivePin, sendPin); + pinMode(sendPin, OUTPUT); + dmxStarted = true; } // Function to read DMX data -uint8_t DMXESPSerial::read(int Channel) { - if (dmxStarted == false) init(); +uint8_t DMXESPSerial::read(int Channel) +{ + if (dmxStarted == false) + init(); - if (Channel < 1) Channel = 1; - if (Channel > DMXCHANNELS) Channel = DMXCHANNELS; - return(dmxDataStore[Channel]); + if (Channel < 1) + Channel = 1; + if (Channel > DMXCHANNELS) + Channel = DMXCHANNELS; + return (dmxDataStore[Channel]); } // Function to send DMX data -void DMXESPSerial::write(int Channel, uint8_t value) { - if (dmxStarted == false) init(); +void DMXESPSerial::write(int Channel, uint8_t value) +{ + if (dmxStarted == false) + init(); - if (Channel < 1) Channel = 1; - if (Channel > DMXCHANNELS) Channel = DMXCHANNELS; - if (value < 0) value = 0; - if (value > 255) value = 255; + if (Channel < 1) + Channel = 1; + if (Channel > DMXCHANNELS) + Channel = DMXCHANNELS; + if (value < 0) + value = 0; + if (value > 255) + value = 255; - dmxDataStore[Channel] = value; + dmxDataStore[Channel] = value; } -void DMXESPSerial::end() { - SERIALPORT.end(); - dmxStarted = false; +void DMXESPSerial::end() +{ + SERIALPORT.end(); + dmxStarted = false; } // Function to update the DMX bus -void DMXESPSerial::update() { - if (dmxStarted == false) init(); +void DMXESPSerial::update() +{ + if (dmxStarted == false) + init(); - //Send break - digitalWrite(sendPin, HIGH); - SERIALPORT.begin(BREAKSPEED, BREAKFORMAT, receivePin, sendPin); - SERIALPORT.write(0); - SERIALPORT.flush(); - delay(1); - SERIALPORT.end(); + // Send break + digitalWrite(sendPin, HIGH); + SERIALPORT.begin(BREAKSPEED, BREAKFORMAT, receivePin, sendPin); + 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.flush(); - delay(1); - SERIALPORT.end(); + // send data + SERIALPORT.begin(DMXSPEED, DMXFORMAT, receivePin, sendPin); + digitalWrite(sendPin, LOW); + SERIALPORT.write(dmxDataStore, DMXCHANNELS); + SERIALPORT.flush(); + delay(1); + SERIALPORT.end(); } \ No newline at end of file diff --git a/src/ESPDMX.h b/src/ESPDMX.h index 1a8cb90..8cdc522 100644 --- a/src/ESPDMX.h +++ b/src/ESPDMX.h @@ -19,12 +19,11 @@ // ---- Methods ---- class DMXESPSerial { -public: - void init(); - uint8_t read(int Channel); - void write(int channel, uint8_t value); - void update(); - void end(); + public: + void init(); + 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 74d591f..f703549 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2,21 +2,21 @@ // 2024-10-17 Patrick Schwarz #include -//#include +// #include #include "ESPDMX.h" // WiFi stuff -const char* ssid = "artnet"; -const char* pwd = "mbgmbgmbg"; +const char *ssid = "artnet"; +const char *pwd = "mbgmbgmbg"; const IPAddress ip(192, 168, 1, 201); const IPAddress gateway(192, 168, 1, 1); const IPAddress subnet(255, 255, 255, 0); // Art-Net stuff ArtnetWiFi artnet; -//const String target_ip = "192.168.1.200"; -uint8_t universe = 1; // 0 - 15 +// const String target_ip = "192.168.1.200"; +uint8_t universe = 1; // 0 - 15 const uint16_t size = 512; uint8_t data[size]; uint8_t value = 0; @@ -24,23 +24,23 @@ uint8_t value = 0; // DMX stuff DMXESPSerial dmx; - -void setup() { +void setup() +{ // Serial console - //Serial.begin(115200); + // Serial.begin(115200); // WiFi stuff - //WiFi.begin(ssid, pwd); + // WiFi.begin(ssid, pwd); WiFi.softAP(ssid, pwd); WiFi.softAPConfig(ip, gateway, subnet); - //WiFi.config(ip, gateway, subnet); - //while (WiFi.status() != WL_CONNECTED) { - // Serial.print("."); - delay(500); + // WiFi.config(ip, gateway, subnet); + // while (WiFi.status() != WL_CONNECTED) { + // Serial.print("."); + delay(500); //} - //Serial.print("WiFi connected, IP = "); - //Serial.println(WiFi.localIP()); + // Serial.print("WiFi connected, IP = "); + // Serial.println(WiFi.localIP()); // Initialize Art-Net artnet.begin(); @@ -49,30 +49,31 @@ void setup() { dmx.init(); // 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) { - /*Serial.print("lambda : artnet data from "); - Serial.print(remote.ip); - Serial.print(":"); - Serial.print(remote.port); - Serial.print(", universe = "); - Serial.print(universe); - Serial.print(", size = "); - Serial.print(size); - Serial.print(") :");*/ + artnet.subscribeArtDmxUniverse(universe, [&](const uint8_t *data, uint16_t size, const ArtDmxMetadata &metadata, const ArtNetRemoteInfo &remote) + { + /*Serial.print("lambda : artnet data from "); + Serial.print(remote.ip); + Serial.print(":"); + Serial.print(remote.port); + Serial.print(", universe = "); + Serial.print(universe); + Serial.print(", size = "); + Serial.print(size); + Serial.print(") :");*/ - for (size_t i = 0; i < size; ++i) { - dmx.write((i+1), data[i]); - // Serial.print(data[i]); - // Serial.print(","); - } - //Serial.println(); + for (size_t i = 0; i < size; ++i) + { + dmx.write((i + 1), data[i]); + // Serial.print(data[i]); + // Serial.print(","); + } + // Serial.println(); - dmx.update(); - - }); + dmx.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) { + artnet.subscribeArtDmx([&](const uint8_t *data, uint16_t size, const ArtDmxMetadata &metadata, const ArtNetRemoteInfo &remote) + { /*Serial.print("received ArtNet data from "); Serial.print(remote.ip); Serial.print(":"); @@ -87,12 +88,12 @@ void setup() { Serial.print(metadata.sequence); Serial.print(", size = "); Serial.print(size); - Serial.println(")");*/ - }); + Serial.println(")");*/ }); } -void loop() { - artnet.parse(); // check if artnet packet has come and execute callback +void loop() +{ + artnet.parse(); // check if artnet packet has come and execute callback /*value = (millis() / 4) % 256; memset(data, value, size); @@ -100,5 +101,4 @@ void loop() { artnet.setArtDmxData(data, size); 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 */ - } \ No newline at end of file