Adapt to new api of esp_dmx v3.1

This commit is contained in:
Arne 2023-08-14 13:38:04 +02:00 committed by Will Tatam
parent 702d085117
commit 9e2268bd74

View File

@ -1,7 +1,7 @@
#include "wled.h"
/*
* Support for DMX Output via MAX485.
* Support for DMX input and output via MAX485.
* Change the output pin in src/dependencies/ESPDMX.cpp, if needed (ESP8266)
* Change the output pin in src/dependencies/SparkFunDMX.cpp, if needed (ESP32)
* ESP8266 Library from:
@ -83,36 +83,61 @@ void initDMX() {
#include <esp_dmx.h>
dmx_port_t dmxPort = 2;
static dmx_port_t dmxInputPort = 2; //TODO make this configurable
bool dmxInputInitialized = false; //true once initDmx finished successfully
void initDMX() {
/* Set the DMX hardware pins to the pins that we want to use. */
if(dmxInputReceivePin > 0) {
if(dmxInputReceivePin > 0 && dmxInputEnablePin > 0 && dmxInputTransmitPin > 0)
{
dmx_config_t config{
255, /*alloc_size*/
0, /*model_id*/
RDM_PRODUCT_CATEGORY_FIXTURE, /*product_category*/
VERSION, /*software_version_id*/
"undefined", /*software_version_label*/
1, /*current_personality*/
{{15, "WLED Effect Mode"}}, /*personalities*/
1, /*personality_count*/
1, /*dmx_start_address*/
};
const std::string versionString = "WLED_V" + std::to_string(VERSION);
strncpy(config.software_version_label, versionString.c_str(), 32);
config.software_version_label[32] = '\0';//zero termination in case our string was longer than 32 chars
if(!dmx_driver_install(dmxInputPort, &config, DMX_INTR_FLAGS_DEFAULT))
{
USER_PRINTF("Error: Failed to install dmx driver\n");
return;
}
USER_PRINTF("Listening for DMX on pin %u\n", dmxInputReceivePin);
dmx_set_pin(dmxPort, dmxInputTransmitPin, dmxInputReceivePin, dmxInputEnablePin);
USER_PRINTF("Sending DMX on pin %u\n", dmxInputTransmitPin);
USER_PRINTF("DMX enable pin is: %u\n", dmxInputEnablePin);
dmx_set_pin(dmxInputPort, dmxInputTransmitPin, dmxInputReceivePin, dmxInputEnablePin);
dmxInputInitialized = true;
}
else {
USER_PRINTLN("DMX input disabled due to dmxReceivePin not being set");
else
{
USER_PRINTLN("DMX input disabled due to dmxInputReceivePin, dmxInputEnablePin or dmxInputTransmitPin not set");
return;
}
/* 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, ESP_INTR_FLAG_LEVEL3);
}
bool dmxIsConnected = false;
unsigned long dmxLastUpdate = 0;
void handleDMXInput() {
if(dmxInputReceivePin < 1) {
if(!dmxInputInitialized) {
return;
}
byte dmxdata[DMX_PACKET_SIZE];
dmx_packet_t packet;
unsigned long now = millis();
if (dmx_receive(dmxPort, &packet, 0)) {
if (dmx_receive(dmxInputPort, &packet, 0)) {
/* We should check to make sure that there weren't any DMX errors. */
if (!packet.err) {
@ -122,7 +147,7 @@ void handleDMXInput() {
dmxIsConnected = true;
}
dmx_read(dmxPort, dmxdata, packet.size);
dmx_read(dmxInputPort, dmxdata, packet.size);
handleDMXData(1, 512, dmxdata, REALTIME_MODE_DMX, 0);
dmxLastUpdate = now;