Inital code swapping DMX input over to use esp_dmx

This commit is contained in:
Will Tatam
2023-02-18 16:05:42 +00:00
parent a6b52a6e1e
commit 5b76df903f
4 changed files with 73 additions and 8 deletions

View File

@@ -257,6 +257,7 @@ lib_deps =
https://github.com/softhack007/LITTLEFS-threadsafe.git#master
makuna/NeoPixelBus @ 2.6.9
https://github.com/pbolduc/AsyncTCP.git @ 1.2.0
https://github.com/someweisguy/esp_dmx.git ; @ v3.0.2-beta
;; ** For compiling with latest Frameworks (IDF4.4.x and arduino-esp32 v2.0.x) **
;;; standard platform

View File

@@ -99,13 +99,59 @@ void initDMX() {}
#endif
#ifdef WLED_ENABLE_DMX_INPUT
bool dmxIsConnected = false;
unsigned long dmxLastUpdate = 0;
void handleDMXInput() {
dmx.update();
uint8_t data[512] = {};
for(int i=0; i < 512; i++) {
data[i] = dmx.read(i + 1);
byte data[DMX_PACKET_SIZE];
/* 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 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 (dmx_receive(dmxPort, &packet, DMX_TIMEOUT_TICK)) {
/* If this code gets called, it means we've received DMX data! */
/* 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 (!packet.err) {
/* If this is the first DMX data we've received, lets log it! */
if (!dmxIsConnected) {
DEBUG_PRINTLN("DMX is connected!");
dmxIsConnected = true;
}
/* Don't forget we need to actually read the DMX data into our buffer so
that we can print it out. */
dmx_read(dmxPort, data, packet.size);
if (now - dmxLastUpdate > 1000) {
/* Print the received start code - it's usually 0. */
DEBUG_PRINTF("Start code is 0x%02X and slot 1 is 0x%02X\n", data[0],
data[1]);
dmxLastUpdate = 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. */
DEBUG_PRINTLN("A DMX error occurred.");
}
} else if (dmxIsConnected) {
DEBUG_PRINTLN("DMX was disconnected.");
}
if(dmxIsConnected) {
DEBUG_PRINTF("DMX channel 1 = %u\n", data(1)); // TODO: remove from final code
handleDMXData(1, 512, data, 1, REALTIME_MODE_DMX, 0);
}
handleDMXData(1, 512, data, 1, REALTIME_MODE_DMX, 0);
DEBUG_PRINTF("DMX channel 1 = %u\n", dmx.read(1)); // TODO: remove from final code
}
#endif

View File

@@ -618,6 +618,17 @@ void WLED::setup()
}
#endif
#ifdef WLED_ENABLE_DMX_INPUT
/* Set the DMX hardware pins to the pins that we want to use. */
dmx_set_pin(dmxPort, dmxTransmitPin, dmxReceivePin, dmxEnablePin);
/* Now we can install the DMX driver! We'll tell it which DMX port to use and
which interrupt priority it should have. If you aren't sure which interrupt
priority to use, you can use the macro `DMX_DEFAULT_INTR_FLAG` to set the
interrupt to its default settings.*/
dmx_driver_install(dmxPort, DMX_DEFAULT_INTR_FLAGS);
#endif
//#endif
// WLEDMM end
}

View File

@@ -124,7 +124,7 @@
#include "src/dependencies/blynk/BlynkSimpleEsp.h"
#endif
#if defined(WLED_ENABLE_DMX) || defined(WLED_ENABLE_DMX_INPUT)
#if defined(WLED_ENABLE_DMX)
#ifdef ESP8266
#include "src/dependencies/dmx/ESPDMX.h"
#else //ESP32
@@ -135,6 +135,10 @@
#endif
#endif
#ifdef WLED_ENABLE_DMX_INPUT
#include <esp_dmx.h>
#endif
#include "src/dependencies/e131/ESPAsyncE131.h"
#ifdef WLED_ENABLE_MQTT
#include "src/dependencies/async-mqtt-client/AsyncMqttClient.h"
@@ -394,7 +398,7 @@ WLED_GLOBAL bool receiveDirect _INIT(true); // receive UDP
WLED_GLOBAL bool arlsDisableGammaCorrection _INIT(true); // activate if gamma correction is handled by the source
WLED_GLOBAL bool arlsForceMaxBri _INIT(false); // enable to force max brightness if source has very dark colors that would be black
#if defined(WLED_ENABLE_DMX) || defined(WLED_ENABLE_DMX_INPUT)
#ifdef WLED_ENABLE_DMX
#ifdef ESP8266
WLED_GLOBAL DMXESPSerial dmx;
#else //ESP32
@@ -402,6 +406,9 @@ WLED_GLOBAL bool arlsForceMaxBri _INIT(false); // enable to f
#endif
WLED_GLOBAL uint16_t e131ProxyUniverse _INIT(0); // output this E1.31 (sACN) / ArtNet universe via MAX485 (0 = disabled)
#endif
#ifdef WLED_ENABLE_DMX_INPUT
dmx_port_t dmxPort = 1;
#endif
WLED_GLOBAL uint16_t e131Universe _INIT(1); // settings for E1.31 (sACN) protocol (only DMX_MODE_MULTIPLE_* can span over consequtive universes)
WLED_GLOBAL uint16_t e131Port _INIT(5568); // DMX in port. E1.31 default is 5568, Art-Net is 6454
WLED_GLOBAL byte DMXMode _INIT(DMX_MODE_MULTIPLE_RGB); // DMX mode (s.a.)