From a5169434cc1fb56546f586aeafa8425a3c1596d2 Mon Sep 17 00:00:00 2001 From: Hendrik Rauh <114620133+HendrikRauh@users.noreply.github.com> Date: Wed, 18 Dec 2024 21:35:17 +0100 Subject: [PATCH 01/11] roughly implemented a dmx endpoint for debug --- src/main.cpp | 4 ++++ src/routes/channels.cpp | 21 +++++++++++++++++++++ src/routes/channels.h | 8 ++++++++ 3 files changed, 33 insertions(+) create mode 100644 src/routes/channels.cpp create mode 100644 src/routes/channels.h diff --git a/src/main.cpp b/src/main.cpp index 40b1153..d307898 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -17,6 +17,7 @@ #include #include "routes/config.h" #include "routes/networks.h" +#include "routes/channels.h" DMXESPSerial dmx1; DMXESPSerial dmx2; @@ -309,6 +310,9 @@ void setup() server.on("/networks", HTTP_GET, [](AsyncWebServerRequest *request) { onGetNetworks(request); }); + server.on("/dmx", HTTP_GET, [](AsyncWebServerRequest *request) + { onGetChannels(request, dmx1, dmx2); }); + server.onRequestBody([](AsyncWebServerRequest *request, uint8_t *data, size_t len, size_t index, size_t total) { if (request->url() == "/config" && request->method() == HTTP_PUT) { diff --git a/src/routes/channels.cpp b/src/routes/channels.cpp new file mode 100644 index 0000000..6f2849c --- /dev/null +++ b/src/routes/channels.cpp @@ -0,0 +1,21 @@ +#include "channels.h" + +void onGetChannels(AsyncWebServerRequest *request, DMXESPSerial dmx1, DMXESPSerial dmx2) +{ + JsonDocument doc; + + for (int channel = 1; channel <= DMXCHANNELS; channel++) + { + doc["dmx1"][channel] = dmx1.read(channel); + } + + for (int channel = 1; channel <= DMXCHANNELS; channel++) + { + doc["dmx2"][channel] = dmx2.read(channel); + } + + String jsonBuffer; + serializeJson(doc, jsonBuffer); + + request->send(200, "application/json", jsonBuffer); +} \ No newline at end of file diff --git a/src/routes/channels.h b/src/routes/channels.h new file mode 100644 index 0000000..bbdec2f --- /dev/null +++ b/src/routes/channels.h @@ -0,0 +1,8 @@ +#include +#include +#include +#include "ESPDMX.h" + +extern Preferences config; + +void onGetChannels(AsyncWebServerRequest *request, DMXESPSerial dmx1, DMXESPSerial dmx2); \ No newline at end of file From a3023faa8c8e7acbcc4a3b4106f64ea2f4298624 Mon Sep 17 00:00:00 2001 From: Hendrik Rauh <114620133+HendrikRauh@users.noreply.github.com> Date: Wed, 18 Dec 2024 21:42:12 +0100 Subject: [PATCH 02/11] removed channel 0 --- src/routes/channels.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/routes/channels.cpp b/src/routes/channels.cpp index 6f2849c..f3bb74d 100644 --- a/src/routes/channels.cpp +++ b/src/routes/channels.cpp @@ -6,12 +6,12 @@ void onGetChannels(AsyncWebServerRequest *request, DMXESPSerial dmx1, DMXESPSeri for (int channel = 1; channel <= DMXCHANNELS; channel++) { - doc["dmx1"][channel] = dmx1.read(channel); + doc["dmx1"][String(channel)] = dmx1.read(channel); } for (int channel = 1; channel <= DMXCHANNELS; channel++) { - doc["dmx2"][channel] = dmx2.read(channel); + doc["dmx2"][String(channel)] = dmx2.read(channel); } String jsonBuffer; From 16c06fd3701e78a5fd55162994df1c145ce880af Mon Sep 17 00:00:00 2001 From: Hendrik Rauh <114620133+HendrikRauh@users.noreply.github.com> Date: Wed, 18 Dec 2024 21:59:56 +0100 Subject: [PATCH 03/11] only sending non 0 values --- src/routes/channels.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/routes/channels.cpp b/src/routes/channels.cpp index f3bb74d..a9b6f5d 100644 --- a/src/routes/channels.cpp +++ b/src/routes/channels.cpp @@ -6,12 +6,20 @@ void onGetChannels(AsyncWebServerRequest *request, DMXESPSerial dmx1, DMXESPSeri for (int channel = 1; channel <= DMXCHANNELS; channel++) { - doc["dmx1"][String(channel)] = dmx1.read(channel); + uint8_t value = dmx1.read(channel); + if (value != 0) + { + doc["dmx1"][String(channel)] = value; + } } for (int channel = 1; channel <= DMXCHANNELS; channel++) { - doc["dmx2"][String(channel)] = dmx2.read(channel); + uint8_t value = dmx2.read(channel); + if (value != 0) + { + doc["dmx2"][String(channel)] = value; + } } String jsonBuffer; From 4b811187f70377517484f2a9017c0ef356f276f5 Mon Sep 17 00:00:00 2001 From: Patrick Schwarz Date: Sat, 1 Feb 2025 22:49:24 +0100 Subject: [PATCH 04/11] halb-broken implementation with other dmx driver. out works only on second port, in works on first port very slowly and on the second port fast --- platformio.ini | 12 ++- src/ESPDMX.cpp | 83 ----------------- src/ESPDMX.h | 37 -------- src/main.cpp | 220 ++++++++++++++++++++++++++++++++++++++------ src/routes/config.h | 1 - 5 files changed, 202 insertions(+), 151 deletions(-) delete mode 100644 src/ESPDMX.cpp delete mode 100644 src/ESPDMX.h diff --git a/platformio.ini b/platformio.ini index 38d1108..606d8f3 100644 --- a/platformio.ini +++ b/platformio.ini @@ -18,6 +18,16 @@ board_build.filesystem = littlefs [env:lolin_s2_mini] platform = espressif32 board = lolin_s2_mini -lib_deps = +lib_deps = bblanchon/ArduinoJson @ ^7.2.0 + someweisguy/esp_dmx extra_scripts = pre:pre_extra_script.py +;build_type = debug +;build_flags = -DCORE_DEBUG_LEVEL=5 +;upload_port = COM4 +monitor_port = COM4 + +[env:esp32_wroom_32] +platform = espressif32 +board = nodemcu-32s +lib_deps = bblanchon/ArduinoJson @ ^7.2.0 diff --git a/src/ESPDMX.cpp b/src/ESPDMX.cpp deleted file mode 100644 index d2e8985..0000000 --- a/src/ESPDMX.cpp +++ /dev/null @@ -1,83 +0,0 @@ -/* ----- LIBRARIES ----- */ -#include -#include "ESPDMX.h" - -// 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]; - -// Set up the DMX-Protocol -void DMXESPSerial::init(int pinSend = DMX_DEFAULT_TX, int pinRecv = DMX_DEFAULT_RX, HardwareSerial& port = DMX_DEFAULT_PORT) -{ - sendPin = pinSend; - recvPin = pinRecv; - _Serial = &port; - _Serial->begin(DMXSPEED, DMXFORMAT, recvPin, sendPin); - Serial.print("Init DMX with pins (TX/RX): "); - Serial.print(sendPin); - Serial.print("/"); - Serial.println(recvPin); - pinMode(sendPin, OUTPUT); - dmxStarted = true; -} - -// Function to read DMX data -uint8_t DMXESPSerial::read(int channel) -{ - if (dmxStarted == false) - init(); - - if (channel < 1) - channel = 1; - if (channel > DMXCHANNELS) - channel = DMXCHANNELS; - return (dmxDataStore[channel]); -} -uint8_t* DMXESPSerial::readAll() -{ - if (dmxStarted == false) - init(); - - return (&dmxDataStore[1]); -} - - -// Function to send DMX data -void DMXESPSerial::write(int channel, uint8_t value) -{ - - if (dmxStarted == false) - init(); - - if (channel < 1) - channel = 1; - if (channel > DMXCHANNELS) - channel = DMXCHANNELS; - - dmxDataStore[channel] = value; -} - -void DMXESPSerial::end() -{ - _Serial->end(); -} - -// Function to update the DMX bus -void DMXESPSerial::update() -{ - // Send break - digitalWrite(sendPin, HIGH); - _Serial->begin(BREAKSPEED, BREAKFORMAT, recvPin, sendPin); - _Serial->write(0); - _Serial->flush(); - delay(1); - _Serial->end(); - - // send data - _Serial->begin(DMXSPEED, DMXFORMAT, recvPin, sendPin); - digitalWrite(sendPin, LOW); - _Serial->write(dmxDataStore, DMXCHANNELS); - _Serial->flush(); - delay(1); - _Serial->end(); -} \ No newline at end of file diff --git a/src/ESPDMX.h b/src/ESPDMX.h deleted file mode 100644 index 4c8e2a2..0000000 --- a/src/ESPDMX.h +++ /dev/null @@ -1,37 +0,0 @@ -#include -#include - -#ifndef ESPDMX_h -#define ESPDMX_h - -#define DMXSPEED 250000 -#define DMXFORMAT SERIAL_8N2 -#define BREAKSPEED 83333 -#define BREAKFORMAT SERIAL_8N1 -#define DMX_DEFAULT_PORT Serial0 -#define DMX_DEFAULT_TX 21 -#define DMX_DEFAULT_RX 33 -#define DMXCHANNELS 512 - -class DMXESPSerial -{ -public: - int sendPin; - int recvPin; - HardwareSerial *port; - bool dmxStarted; - uint8_t dmxDataStore[DMXCHANNELS + 1]; - - void init(int pinSend, int pinRecv, HardwareSerial& port); - uint8_t read(int channel); - uint8_t* readAll(); - void write(int channel, uint8_t value); - void update(); - void end(); - -private: - // Member variables - HardwareSerial* _Serial; -}; - -#endif diff --git a/src/main.cpp b/src/main.cpp index 40b1153..cd2a1f9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,9 @@ #ifdef ESP32 #include #include +//#include +//#include "USBCDC.h" +#include "driver/temp_sensor.h" #elif defined(ESP8266) #include #include @@ -13,13 +16,24 @@ #include #include -#include "ESPDMX.h" +//#include "ESPDMX.h" +#include +#include + #include #include "routes/config.h" #include "routes/networks.h" -DMXESPSerial dmx1; -DMXESPSerial dmx2; +//DMXESPSerial dmx1; +//DMXESPSerial dmx2; +dmx_port_t dmx1 = DMX_NUM_0; // for esp32s2 +dmx_port_t dmx2 = DMX_NUM_1; +byte dmx1_data[DMX_PACKET_SIZE]; +byte dmx2_data[DMX_PACKET_SIZE]; +unsigned long dmx1_lastUpdate = millis(); +unsigned long dmx2_lastUpdate = millis(); +bool dmx1_IsConnected = false; +bool dmx2_IsConnected = false; // Button #define PIN_LED 7 @@ -53,7 +67,7 @@ void IRAM_ATTR onTimer() #define ETH_INT 38 #define ETH_SPI_HOST SPI2_HOST #define ETH_SPI_CLOCK_MHZ 25 -byte mac[6] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; +byte mac[6]; AsyncWebServer server(80); @@ -64,8 +78,6 @@ uint8_t universe1; uint8_t universe2; Direction direction1; Direction direction2; -// const uint16_t size = 512; -// uint8_t data[DMXCHANNELS]; void ledBlink(int ms) { @@ -87,12 +99,36 @@ void ledBlink(int ms) } } +float getTemperature() +{ + float tempC = -1.0f; + temp_sensor_read_celsius(&tempC); + return tempC; +} void setup() { + Serial.begin(9600); // Get ETH mac + delay(1000); + + esp_efuse_mac_get_default(mac); + esp_read_mac(mac, ESP_MAC_ETH); + Serial.printf("%02x:%02x:%02x:%02x:%02x:%02x ESP MAC ETH\n", + mac[0], mac[1], mac[2], + mac[3], mac[4], mac[5]); + + esp_read_mac(mac, ESP_MAC_WIFI_SOFTAP); + Serial.printf("%02x:%02x:%02x:%02x:%02x:%02x ESP MAC SOFTAP\n", + mac[0], mac[1], mac[2], + mac[3], mac[4], mac[5]); + + esp_read_mac(mac, ESP_MAC_WIFI_STA); //ESP_MAC_BASE + Serial.printf("%02x:%02x:%02x:%02x:%02x:%02x ESP MAC BASE\n", + mac[0], mac[1], mac[2], + mac[3], mac[4], mac[5]); // LED config.begin("dmx", true); @@ -186,6 +222,8 @@ void setup() Serial.println(WiFi.localIP()); Serial.print("MAC address: "); Serial.println(WiFi.macAddress()); + Serial.print("Broadcast IP: "); + Serial.println(broadcastIp); break; case Ethernet: @@ -233,6 +271,8 @@ void setup() Serial.println(ETH.dnsIP()); Serial.print("MAC address : "); Serial.println(ETH.macAddress()); + Serial.print("Broadcast IP: "); + Serial.println(broadcastIp); Serial.println("Ethernet Successfully Initialized"); break; } @@ -247,39 +287,86 @@ void setup() Serial.println(WiFi.softAPIP()); Serial.print("MAC address: "); Serial.println(WiFi.softAPmacAddress()); + Serial.print("Broadcast IP: "); + Serial.println(broadcastIp); break; } // Initialize DMX ports Serial.println("Initialize DMX..."); - dmx1.init(21, 33, Serial0); - dmx2.init(17, 18, Serial1); + + #ifdef CONFIG_IDF_TARGET_ESP32S2 + //dmx1.init(21, 33, Serial0); + //dmx2.init(17, 18, Serial1); + + Serial.print("DMX driver 1 installed: "); + Serial.println(dmx_driver_is_installed(dmx1)); + + Serial.print("DMX driver 2 installed: "); + Serial.println(dmx_driver_is_installed(dmx2)); + + + dmx_config_t dmx_config = DMX_CONFIG_DEFAULT; + + dmx_personality_t personalities[] = {}; + /*dmx_personality_t personalities[] = { + {1, "Default Personality"} + };*/ + /*int personality_count = 1;*/ + int personality_count = 0; + dmx_driver_install(dmx1, &dmx_config, personalities, personality_count); + dmx_set_pin(dmx1, 21, 33, -1); + dmx_driver_install(dmx2, &dmx_config, personalities, personality_count); + dmx_set_pin(dmx2, 17, 18, -1); + + Serial.print("DMX driver 1 installed: "); + Serial.println(dmx_driver_is_installed(dmx1)); + + Serial.print("DMX driver 2 installed: "); + Serial.println(dmx_driver_is_installed(dmx2)); + + Serial.print("DMX driver 1 enabled: "); + Serial.println(dmx_driver_is_enabled(dmx1)); + + Serial.print("DMX driver 2 enabled: "); + Serial.println(dmx_driver_is_enabled(dmx2)); + + // TX/RX Pins und Serial0/Serial1 ausgeben + + + /* Now set the DMX hardware pins to the pins that we want to use and setup + will be complete! */ + + #else + dmx1.init(21, 33, Serial1); + dmx2.init(17, 18, Serial2); + #endif // Initialize Art-Net Serial.println("Initialize Art-Net..."); artnet.begin(); // if Artnet packet comes to this universe, this function is called - if (direction1 == Output) + if (direction1 == Output) { + Serial.println("DMX1 as out"); artnet.subscribeArtDmxUniverse(universe1, [&](const uint8_t *data, uint16_t size, const ArtDmxMetadata &metadata, const ArtNetRemoteInfo &remote) - { - for (size_t i = 0; i < size; ++i) - { - dmx1.write((i + 1), data[i]); - } - dmx1.update(); }); + { + dmx_write_offset(dmx1, 1, data, size); + dmx_send(dmx1); + dmx_wait_sent(dmx1, DMX_TIMEOUT_TICK); + }); } if (direction2 == Output) { + Serial.println("DMX2 as out"); artnet.subscribeArtDmxUniverse(universe2, [&](const uint8_t *data, uint16_t size, const ArtDmxMetadata &metadata, const ArtNetRemoteInfo &remote) - { - for (size_t i = 0; i < size; ++i) - { - dmx2.write((i + 1), data[i]); - } - dmx2.update(); }); + { + dmx_write_offset(dmx2, 1, data, size); + dmx_send(dmx2); + dmx_wait_sent(dmx2, DMX_TIMEOUT_TICK); + }); } // if Artnet packet comes, this function is called to every universe @@ -325,6 +412,26 @@ void setup() WiFi.scanNetworks(true); ledBlink(0); + + + // Internal temperature RP2040 + /*float tempC = analogReadTemp(); // Get internal temperature + Serial.print("Temperature Celsius (ºC): "); + Serial.println(tempC);*/ + // Internal temperature ESP32 https://www.espboards.dev/blog/esp32-inbuilt-temperature-sensor/ + Serial.print("Temperature: "); + float result = 0; + temp_sensor_read_celsius(&result); + Serial.print(result); + Serial.println(" °C"); + + Serial.print(getTemperature()); + Serial.println(" °C"); + + Serial.printf("Internal Total heap %d, internal Free Heap %d\n", ESP.getHeapSize(), ESP.getFreeHeap()); + Serial.printf("SPIRam Total heap %d, SPIRam Free Heap %d\n", ESP.getPsramSize(), ESP.getFreePsram()); + Serial.printf("ChipRevision %d, Cpu Freq %d, SDK Version %s\n", ESP.getChipRevision(), ESP.getCpuFreqMHz(), ESP.getSdkVersion()); + Serial.printf("Flash Size %d, Flash Speed %d\n", ESP.getFlashChipSize(), ESP.getFlashChipSpeed()); } void loop() @@ -332,14 +439,69 @@ void loop() // check if artnet packet has come and execute callback artnet.parse(); - // Receive Callback/INT currently not implemented - /*if (direction1 == Input) { - artnet.setArtDmxData(dmx1.readAll(), DMXCHANNELS); - artnet.streamArtDmxTo(broadcastIp, universe1); + + /* We need a place to store information about the DMX packets we receive. We + will use a dmx_packet_t to store that packet information. */ + dmx_packet_t dmx1_packet; + dmx_packet_t dmx2_packet; + + /* And now we wait! The DMX standard defines the amount of time until DMX + officially times out. That amount of time is converted into ESP32 clock + ticks using the constant `DMX_TIMEOUT_TICK`. If it takes longer than that + amount of time to receive data, this if statement will evaluate to false. */ + if (direction1 == Input) { + //Serial.println("Recv DMX1"); + /* If this code gets called, it means we've received DMX data! */ + + dmx_read_offset(dmx1, 1, dmx1_data, 512); + artnet.sendArtDmx(broadcastIp, universe1, dmx1_data, 512); + } - if (direction2 == Input) { - artnet.setArtDmxData(dmx2.readAll(), DMXCHANNELS); - artnet.streamArtDmxTo(broadcastIp, universe2); - }*/ + if (direction2 == Input && dmx_receive(dmx2, &dmx2_packet, DMX_TIMEOUT_TICK)) { + //Serial.println("Recv DMX2"); + /* If this code gets called, it means we've received DMX data! */ + + dmx_read_offset(dmx2, 1, dmx2_data, 512); + artnet.sendArtDmx(broadcastIp, universe2, dmx2_data, 512); + + /* Get the current time since boot in milliseconds so that we can find out + how long it has been since we last updated data and printed to the Serial + Monitor. */ + unsigned long now = millis(); + + /* We should check to make sure that there weren't any DMX errors. */ + if (!dmx2_packet.err) { + /* If this is the first DMX data we've received, lets log it! */ + if (!dmx2_IsConnected) { + Serial.println("DMX2 in is connected!"); + dmx2_IsConnected = true; + } + + /* Don't forget we need to actually read the DMX data into our buffer so + that we can print it out. */ + + /*dmx_read_offset(dmx2, 1, dmx2_data, dmx2_packet.size); + artnet.sendArtDmx(broadcastIp, universe2, dmx2_data, 512);*/ + + if (now - dmx2_lastUpdate > 1000) { + /* Print the received start code - it's usually 0. */ + //Serial.printf("Start code is 0x%02X and slot 1 is 0x%02X\n", dmx2_data[0], dmx2_data[1]); + dmx2_lastUpdate = now; + } + } else { + /* Oops! A DMX error occurred! Don't worry, this can happen when you first + connect or disconnect your DMX devices. If you are consistently getting + DMX errors, then something may have gone wrong with your code or + something is seriously wrong with your DMX transmitter. */ + Serial.println("A DMX 2 error occurred."); + } + } else if (dmx2_IsConnected) { + /* If DMX times out after having been connected, it likely means that the + DMX cable was unplugged. When that happens in this example sketch, we'll + uninstall the DMX driver. */ + Serial.println("DMX 2 was disconnected."); + dmx2_IsConnected = false; + //dmx_driver_delete(dmx2); + } } diff --git a/src/routes/config.h b/src/routes/config.h index bac228d..770cef9 100644 --- a/src/routes/config.h +++ b/src/routes/config.h @@ -1,5 +1,4 @@ #include -#include #include #ifndef CONFIG_h From 1ccf214ddbc3183c7c1410d442547e6c735b58a2 Mon Sep 17 00:00:00 2001 From: RaffaelW Date: Sun, 16 Feb 2025 20:46:06 +0100 Subject: [PATCH 05/11] =?UTF-8?q?fixes=20"Slider=20f=C3=BCr=20Helligkeit?= =?UTF-8?q?=20zeigt=20beim=20ersten=20Laden=2050%=20ist=20aber=20bei=2010%?= =?UTF-8?q?"=20#68?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data/index.html | 2 +- data/range-input.js | 16 +++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/data/index.html b/data/index.html index c6f81ab..330dbee 100644 --- a/data/index.html +++ b/data/index.html @@ -7,11 +7,11 @@ + -
diff --git a/data/range-input.js b/data/range-input.js index 4b31c04..4bc9c62 100644 --- a/data/range-input.js +++ b/data/range-input.js @@ -1,14 +1,20 @@ -document.querySelector("form").addEventListener("input", (event) => { +const form = document.querySelector("form"); + +form.addEventListener("input", (event) => { if (event.target.classList.contains("range")) { updateValue(event.target); } }); +form.addEventListener("change", () => { + console.log("received change event"); + document.querySelectorAll("input[type='range']").forEach((input) => { + updateValue(input); + }); +}); + function updateValue(slider) { + console.log("update slide value"); const percentage = Math.round((slider.value / slider.max) * 100); slider.nextElementSibling.innerText = `${percentage}%`; } - -document.querySelectorAll("input[type='range'].range").forEach((element) => { - updateValue(element); -}); From 836af4ef150925241e69172a4b37bc377d367690 Mon Sep 17 00:00:00 2001 From: Hendrik Rauh <114620133+HendrikRauh@users.noreply.github.com> Date: Thu, 6 Mar 2025 21:23:29 +0100 Subject: [PATCH 06/11] fix: correct typo in interrupt function comment for clarity --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index ad0b20d..2800f00 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -32,7 +32,7 @@ bool status_led; hw_timer_t *timer = NULL; // H/W timer defining (Pointer to the Structure) portMUX_TYPE timerMux = portMUX_INITIALIZER_UNLOCKED; void IRAM_ATTR onTimer() -{ // Defining Inerrupt function with IRAM_ATTR for faster access +{ // Defining interrupt function with IRAM_ATTR for faster access portENTER_CRITICAL_ISR(&timerMux); status_led = !status_led; if (!status_led) From 176a12a9b3201f948914ac216e50cb3ff8ad2131 Mon Sep 17 00:00:00 2001 From: Hendrik Rauh <114620133+HendrikRauh@users.noreply.github.com> Date: Thu, 6 Mar 2025 21:44:55 +0100 Subject: [PATCH 07/11] Revert "Merge branch 'main' into 30-add-dmx-in-capability" This reverts commit b93ae3d68228db008b5a46f8932ceede613a0ae7, reversing changes made to f3ef3aa9b927bc5b06998795f4a23abb9f09a88f. --- data/index.html | 2 +- data/range-input.js | 16 +++++----------- src/main.cpp | 4 ---- src/routes/channels.cpp | 29 ----------------------------- src/routes/channels.h | 8 -------- 5 files changed, 6 insertions(+), 53 deletions(-) delete mode 100644 src/routes/channels.cpp delete mode 100644 src/routes/channels.h diff --git a/data/index.html b/data/index.html index 330dbee..c6f81ab 100644 --- a/data/index.html +++ b/data/index.html @@ -7,11 +7,11 @@ - +
diff --git a/data/range-input.js b/data/range-input.js index 4bc9c62..4b31c04 100644 --- a/data/range-input.js +++ b/data/range-input.js @@ -1,20 +1,14 @@ -const form = document.querySelector("form"); - -form.addEventListener("input", (event) => { +document.querySelector("form").addEventListener("input", (event) => { if (event.target.classList.contains("range")) { updateValue(event.target); } }); -form.addEventListener("change", () => { - console.log("received change event"); - document.querySelectorAll("input[type='range']").forEach((input) => { - updateValue(input); - }); -}); - function updateValue(slider) { - console.log("update slide value"); const percentage = Math.round((slider.value / slider.max) * 100); slider.nextElementSibling.innerText = `${percentage}%`; } + +document.querySelectorAll("input[type='range'].range").forEach((element) => { + updateValue(element); +}); diff --git a/src/main.cpp b/src/main.cpp index 5a9c443..ce64fd4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -23,7 +23,6 @@ #include #include "routes/config.h" #include "routes/networks.h" -#include "routes/channels.h" //DMXESPSerial dmx1; //DMXESPSerial dmx2; @@ -396,9 +395,6 @@ void setup() server.on("/networks", HTTP_GET, [](AsyncWebServerRequest *request) { onGetNetworks(request); }); - server.on("/dmx", HTTP_GET, [](AsyncWebServerRequest *request) - { onGetChannels(request, dmx1, dmx2); }); - server.onRequestBody([](AsyncWebServerRequest *request, uint8_t *data, size_t len, size_t index, size_t total) { if (request->url() == "/config" && request->method() == HTTP_PUT) { diff --git a/src/routes/channels.cpp b/src/routes/channels.cpp deleted file mode 100644 index a9b6f5d..0000000 --- a/src/routes/channels.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#include "channels.h" - -void onGetChannels(AsyncWebServerRequest *request, DMXESPSerial dmx1, DMXESPSerial dmx2) -{ - JsonDocument doc; - - for (int channel = 1; channel <= DMXCHANNELS; channel++) - { - uint8_t value = dmx1.read(channel); - if (value != 0) - { - doc["dmx1"][String(channel)] = value; - } - } - - for (int channel = 1; channel <= DMXCHANNELS; channel++) - { - uint8_t value = dmx2.read(channel); - if (value != 0) - { - doc["dmx2"][String(channel)] = value; - } - } - - String jsonBuffer; - serializeJson(doc, jsonBuffer); - - request->send(200, "application/json", jsonBuffer); -} \ No newline at end of file diff --git a/src/routes/channels.h b/src/routes/channels.h deleted file mode 100644 index bbdec2f..0000000 --- a/src/routes/channels.h +++ /dev/null @@ -1,8 +0,0 @@ -#include -#include -#include -#include "ESPDMX.h" - -extern Preferences config; - -void onGetChannels(AsyncWebServerRequest *request, DMXESPSerial dmx1, DMXESPSerial dmx2); \ No newline at end of file From 3bb630c4ac76f6405275aad0495489471433e66d Mon Sep 17 00:00:00 2001 From: RaffaelW Date: Sun, 13 Apr 2025 21:46:46 +0200 Subject: [PATCH 08/11] remove blinking led that uses a hardware timer --- src/main.cpp | 104 ++++++++++++++++++++++++++------------------------- 1 file changed, 53 insertions(+), 51 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index ce64fd4..7a01321 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,8 +1,8 @@ #ifdef ESP32 #include #include -//#include -//#include "USBCDC.h" +// #include +// #include "USBCDC.h" #include "driver/temp_sensor.h" #elif defined(ESP8266) #include @@ -16,7 +16,7 @@ #include #include -//#include "ESPDMX.h" +// #include "ESPDMX.h" #include #include @@ -24,8 +24,8 @@ #include "routes/config.h" #include "routes/networks.h" -//DMXESPSerial dmx1; -//DMXESPSerial dmx2; +// DMXESPSerial dmx1; +// DMXESPSerial dmx2; dmx_port_t dmx1 = DMX_NUM_0; // for esp32s2 dmx_port_t dmx2 = DMX_NUM_1; byte dmx1_data[DMX_PACKET_SIZE]; @@ -42,7 +42,7 @@ bool dmx2_IsConnected = false; uint8_t brightness_led = 20; bool status_led; -hw_timer_t *timer = NULL; // H/W timer defining (Pointer to the Structure) +/* hw_timer_t *timer = NULL; // H/W timer defining (Pointer to the Structure) portMUX_TYPE timerMux = portMUX_INITIALIZER_UNLOCKED; void IRAM_ATTR onTimer() { // Defining Inerrupt function with IRAM_ATTR for faster access @@ -57,7 +57,7 @@ void IRAM_ATTR onTimer() analogWrite(PIN_LED, 0); } portEXIT_CRITICAL_ISR(&timerMux); -} +} */ // Ethernet stuff #define ETH_SCK 36 @@ -77,7 +77,7 @@ uint8_t universe1; uint8_t universe2; Direction direction1; Direction direction2; - +/* void ledBlink(int ms) { if (timer == NULL) @@ -96,7 +96,7 @@ void ledBlink(int ms) timerAlarmWrite(timer, ms, true); // Match value= 1000000 for 1 sec. delay. timerAlarmEnable(timer); // Enable Timer with interrupt (Alarm Enable) } -} +} */ float getTemperature() { @@ -124,7 +124,7 @@ void setup() mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); - esp_read_mac(mac, ESP_MAC_WIFI_STA); //ESP_MAC_BASE + esp_read_mac(mac, ESP_MAC_WIFI_STA); // ESP_MAC_BASE Serial.printf("%02x:%02x:%02x:%02x:%02x:%02x ESP MAC BASE\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); @@ -139,14 +139,14 @@ void setup() pinMode(PIN_BUTTON, INPUT_PULLUP); if (digitalRead(PIN_BUTTON) == LOW) { - ledBlink(100); + // ledBlink(100); unsigned long startTime = millis(); while (digitalRead(PIN_BUTTON) == LOW && (millis() - startTime <= 3000)) { } if (digitalRead(PIN_BUTTON) == LOW) { - ledBlink(0); + // ledBlink(0); Serial.println("Reset config"); config.begin("dmx", false); config.clear(); @@ -155,7 +155,7 @@ void setup() } } - ledBlink(500); + // ledBlink(500); // wait for serial monitor delay(5000); @@ -271,7 +271,7 @@ void setup() Serial.print("MAC address : "); Serial.println(ETH.macAddress()); Serial.print("Broadcast IP: "); - Serial.println(broadcastIp); + Serial.println(broadcastIp); Serial.println("Ethernet Successfully Initialized"); break; } @@ -294,9 +294,9 @@ void setup() // Initialize DMX ports Serial.println("Initialize DMX..."); - #ifdef CONFIG_IDF_TARGET_ESP32S2 - //dmx1.init(21, 33, Serial0); - //dmx2.init(17, 18, Serial1); +#ifdef CONFIG_IDF_TARGET_ESP32S2 + // dmx1.init(21, 33, Serial0); + // dmx2.init(17, 18, Serial1); Serial.print("DMX driver 1 installed: "); Serial.println(dmx_driver_is_installed(dmx1)); @@ -304,7 +304,6 @@ void setup() Serial.print("DMX driver 2 installed: "); Serial.println(dmx_driver_is_installed(dmx2)); - dmx_config_t dmx_config = DMX_CONFIG_DEFAULT; dmx_personality_t personalities[] = {}; @@ -332,40 +331,37 @@ void setup() // TX/RX Pins und Serial0/Serial1 ausgeben + /* Now set the DMX hardware pins to the pins that we want to use and setup + will be complete! */ - /* Now set the DMX hardware pins to the pins that we want to use and setup - will be complete! */ - - #else +#else dmx1.init(21, 33, Serial1); dmx2.init(17, 18, Serial2); - #endif +#endif // Initialize Art-Net Serial.println("Initialize Art-Net..."); artnet.begin(); // if Artnet packet comes to this universe, this function is called - if (direction1 == Output) + if (direction1 == Output) { Serial.println("DMX1 as out"); artnet.subscribeArtDmxUniverse(universe1, [&](const uint8_t *data, uint16_t size, const ArtDmxMetadata &metadata, const ArtNetRemoteInfo &remote) - { + { dmx_write_offset(dmx1, 1, data, size); dmx_send(dmx1); - dmx_wait_sent(dmx1, DMX_TIMEOUT_TICK); - }); + dmx_wait_sent(dmx1, DMX_TIMEOUT_TICK); }); } if (direction2 == Output) { Serial.println("DMX2 as out"); artnet.subscribeArtDmxUniverse(universe2, [&](const uint8_t *data, uint16_t size, const ArtDmxMetadata &metadata, const ArtNetRemoteInfo &remote) - { + { dmx_write_offset(dmx2, 1, data, size); dmx_send(dmx2); - dmx_wait_sent(dmx2, DMX_TIMEOUT_TICK); - }); + dmx_wait_sent(dmx2, DMX_TIMEOUT_TICK); }); } // if Artnet packet comes, this function is called to every universe @@ -410,9 +406,8 @@ void setup() // scan networks and cache them WiFi.scanNetworks(true); - ledBlink(0); + // ledBlink(0); - // Internal temperature RP2040 /*float tempC = analogReadTemp(); // Get internal temperature Serial.print("Temperature Celsius (ºC): "); @@ -438,7 +433,6 @@ void loop() // check if artnet packet has come and execute callback artnet.parse(); - /* We need a place to store information about the DMX packets we receive. We will use a dmx_packet_t to store that packet information. */ dmx_packet_t dmx1_packet; @@ -448,21 +442,22 @@ void loop() officially times out. That amount of time is converted into ESP32 clock ticks using the constant `DMX_TIMEOUT_TICK`. If it takes longer than that amount of time to receive data, this if statement will evaluate to false. */ - if (direction1 == Input) { - //Serial.println("Recv DMX1"); + if (direction1 == Input) + { + // Serial.println("Recv DMX1"); /* If this code gets called, it means we've received DMX data! */ - dmx_read_offset(dmx1, 1, dmx1_data, 512); - artnet.sendArtDmx(broadcastIp, universe1, dmx1_data, 512); - + dmx_read_offset(dmx1, 1, dmx1_data, 512); + artnet.sendArtDmx(broadcastIp, universe1, dmx1_data, 512); } - if (direction2 == Input && dmx_receive(dmx2, &dmx2_packet, DMX_TIMEOUT_TICK)) { - //Serial.println("Recv DMX2"); + if (direction2 == Input && dmx_receive(dmx2, &dmx2_packet, DMX_TIMEOUT_TICK)) + { + // Serial.println("Recv DMX2"); /* If this code gets called, it means we've received DMX data! */ - dmx_read_offset(dmx2, 1, dmx2_data, 512); - artnet.sendArtDmx(broadcastIp, universe2, dmx2_data, 512); + dmx_read_offset(dmx2, 1, dmx2_data, 512); + artnet.sendArtDmx(broadcastIp, universe2, dmx2_data, 512); /* Get the current time since boot in milliseconds so that we can find out how long it has been since we last updated data and printed to the Serial @@ -470,37 +465,44 @@ void loop() unsigned long now = millis(); /* We should check to make sure that there weren't any DMX errors. */ - if (!dmx2_packet.err) { + if (!dmx2_packet.err) + { /* If this is the first DMX data we've received, lets log it! */ - if (!dmx2_IsConnected) { + if (!dmx2_IsConnected) + { Serial.println("DMX2 in is connected!"); dmx2_IsConnected = true; } /* Don't forget we need to actually read the DMX data into our buffer so that we can print it out. */ - + /*dmx_read_offset(dmx2, 1, dmx2_data, dmx2_packet.size); artnet.sendArtDmx(broadcastIp, universe2, dmx2_data, 512);*/ - if (now - dmx2_lastUpdate > 1000) { + if (now - dmx2_lastUpdate > 1000) + { /* Print the received start code - it's usually 0. */ - //Serial.printf("Start code is 0x%02X and slot 1 is 0x%02X\n", dmx2_data[0], dmx2_data[1]); + // Serial.printf("Start code is 0x%02X and slot 1 is 0x%02X\n", dmx2_data[0], dmx2_data[1]); dmx2_lastUpdate = now; } - } else { + } + else + { /* Oops! A DMX error occurred! Don't worry, this can happen when you first connect or disconnect your DMX devices. If you are consistently getting DMX errors, then something may have gone wrong with your code or something is seriously wrong with your DMX transmitter. */ Serial.println("A DMX 2 error occurred."); - } - } else if (dmx2_IsConnected) { + } + } + else if (dmx2_IsConnected) + { /* If DMX times out after having been connected, it likely means that the DMX cable was unplugged. When that happens in this example sketch, we'll uninstall the DMX driver. */ Serial.println("DMX 2 was disconnected."); dmx2_IsConnected = false; - //dmx_driver_delete(dmx2); + // dmx_driver_delete(dmx2); } } From f0dcabcabcc17c5b83ae4f7ec413e4c0635666cd Mon Sep 17 00:00:00 2001 From: RaffaelW Date: Sun, 13 Apr 2025 22:55:24 +0200 Subject: [PATCH 09/11] use code from input 2 also for input 1 --- src/main.cpp | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index 7a01321..436b0bf 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -449,6 +449,51 @@ void loop() dmx_read_offset(dmx1, 1, dmx1_data, 512); artnet.sendArtDmx(broadcastIp, universe1, dmx1_data, 512); + /* Get the current time since boot in milliseconds so that we can find out + how long it has been since we last updated data and printed to the Serial + Monitor. */ + unsigned long now = millis(); + + /* We should check to make sure that there weren't any DMX errors. */ + if (!dmx1_packet.err) + { + /* If this is the first DMX data we've received, lets log it! */ + if (!dmx1_IsConnected) + { + Serial.println("DMX1 in is connected!"); + dmx1_IsConnected = true; + } + + /* Don't forget we need to actually read the DMX data into our buffer so + that we can print it out. */ + + /*dmx_read_offset(dmx1, 1, dmx1_data, dmx1_packet.size); + artnet.sendArtDmx(broadcastIp, universe1, dmx1_data, 512);*/ + + if (now - dmx1_lastUpdate > 1000) + { + /* Print the received start code - it's usually 0. */ + // Serial.printf("Start code is 0x%02X and slot 1 is 0x%02X\n", dmx1_data[0], dmx1_data[1]); + dmx1_lastUpdate = now; + } + } + else + { + /* Oops! A DMX error occurred! Don't worry, this can happen when you first + connect or disconnect your DMX devices. If you are consistently getting + DMX errors, then something may have gone wrong with your code or + something is seriously wrong with your DMX transmitter. */ + Serial.println("A DMX 1 error occurred."); + } + } + else if (dmx1_IsConnected) + { + /* If DMX times out after having been connected, it likely means that the + DMX cable was unplugged. When that happens in this example sketch, we'll + uninstall the DMX driver. */ + Serial.println("DMX 1 was disconnected."); + dmx1_IsConnected = false; + // dmx_driver_delete(dmx1); } if (direction2 == Input && dmx_receive(dmx2, &dmx2_packet, DMX_TIMEOUT_TICK)) From 678bb047ac6e65ab4d3199bf45c3858072702e45 Mon Sep 17 00:00:00 2001 From: RaffaelW Date: Sun, 13 Apr 2025 23:08:51 +0200 Subject: [PATCH 10/11] fix previous commit --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 436b0bf..44c64f8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -442,7 +442,7 @@ void loop() officially times out. That amount of time is converted into ESP32 clock ticks using the constant `DMX_TIMEOUT_TICK`. If it takes longer than that amount of time to receive data, this if statement will evaluate to false. */ - if (direction1 == Input) + if (direction1 == Input && dmx_receive(dmx2, &dmx2_packet, DMX_TIMEOUT_TICK)) { // Serial.println("Recv DMX1"); /* If this code gets called, it means we've received DMX data! */ From 34575d97dd4cfc67dfa13e70003721cef596b2c7 Mon Sep 17 00:00:00 2001 From: RaffaelW Date: Mon, 14 Apr 2025 21:47:25 +0200 Subject: [PATCH 11/11] made dmx_receive non-blocking --- src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 44c64f8..4cdd7b5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -442,7 +442,7 @@ void loop() officially times out. That amount of time is converted into ESP32 clock ticks using the constant `DMX_TIMEOUT_TICK`. If it takes longer than that amount of time to receive data, this if statement will evaluate to false. */ - if (direction1 == Input && dmx_receive(dmx2, &dmx2_packet, DMX_TIMEOUT_TICK)) + if (direction1 == Input && dmx_receive(dmx1, &dmx1_packet, 0)) { // Serial.println("Recv DMX1"); /* If this code gets called, it means we've received DMX data! */ @@ -496,7 +496,7 @@ void loop() // dmx_driver_delete(dmx1); } - if (direction2 == Input && dmx_receive(dmx2, &dmx2_packet, DMX_TIMEOUT_TICK)) + if (direction2 == Input && dmx_receive(dmx2, &dmx2_packet, 0)) { // Serial.println("Recv DMX2"); /* If this code gets called, it means we've received DMX data! */