Port over remaining WLEDMM part of DMX Input and adapt for AC

This commit is contained in:
Will Tatam 2025-01-16 12:48:36 +00:00
parent 953e994c88
commit a582786655
6 changed files with 38 additions and 31 deletions

View File

@ -249,6 +249,7 @@
#define REALTIME_MODE_ARTNET 6 #define REALTIME_MODE_ARTNET 6
#define REALTIME_MODE_TPM2NET 7 #define REALTIME_MODE_TPM2NET 7
#define REALTIME_MODE_DDP 8 #define REALTIME_MODE_DDP 8
#define REALTIME_MODE_DMX 9
//realtime override modes //realtime override modes
#define REALTIME_OVERRIDE_NONE 0 #define REALTIME_OVERRIDE_NONE 0

View File

@ -151,17 +151,17 @@ Timeout: <input name="ET" type="number" min="1" max="65000" required> ms<br>
Force max brightness: <input type="checkbox" name="FB"><br> Force max brightness: <input type="checkbox" name="FB"><br>
Disable realtime gamma correction: <input type="checkbox" name="RG"><br> Disable realtime gamma correction: <input type="checkbox" name="RG"><br>
Realtime LED offset: <input name="WO" type="number" min="-255" max="255" required> Realtime LED offset: <input name="WO" type="number" min="-255" max="255" required>
<div id="dmxInput"> <!--WLEDMM--> <div id="dmxInput">
<h4>Wired DMX Input Pins</h4> <h4>Wired DMX Input Pins</h4>
DMX RX: <input name="IDMR" type="number" min="-1" max="99">RO<br/> DMX RX: <input name="IDMR" type="number" min="-1" max="99">RO<br/>
DMX TX: <input name="IDMT" type="number" min="-1" max="99">DI<br/> DMX TX: <input name="IDMT" type="number" min="-1" max="99">DI<br/>
DMX Enable: <input name="IDME" type="number" min="-1" max="99">RE+DE<br/> DMX Enable: <input name="IDME" type="number" min="-1" max="99">RE+DE<br/>
DMX Port: <input name="IDMP" type="number" min="1" max="2"><br/> DMX Port: <input name="IDMP" type="number" min="1" max="2"><br/>
</div> </div>
<div id="dmxInputOff"> <!--WLEDMM--> <div id="dmxInputOff">
<br><em style="color:darkorange">This firmware build does not include DMX Input support. <br></em> <br><em style="color:darkorange">This firmware build does not include DMX Input support. <br></em>
</div> </div>
<div id="dmxOnOff2"> <!--WLEDMM--> <div id="dmxOnOff2">
<br><em style="color:darkorange">This firmware build does not include DMX output support. <br></em> <br><em style="color:darkorange">This firmware build does not include DMX output support. <br></em>
</div> </div>
<hr class="sml"> <hr class="sml">

View File

@ -15,7 +15,7 @@ void rdmPersonalityChangedCb(dmx_port_t dmxPort, const rdm_header_t *header,
DMXInput *dmx = static_cast<DMXInput *>(context); DMXInput *dmx = static_cast<DMXInput *>(context);
if (!dmx) { if (!dmx) {
USER_PRINTLN("DMX: Error: no context in rdmPersonalityChangedCb"); DEBUG_PRINTLN("DMX: Error: no context in rdmPersonalityChangedCb");
return; return;
} }
@ -23,7 +23,7 @@ void rdmPersonalityChangedCb(dmx_port_t dmxPort, const rdm_header_t *header,
const uint8_t personality = dmx_get_current_personality(dmx->inputPortNum); const uint8_t personality = dmx_get_current_personality(dmx->inputPortNum);
DMXMode = std::min(DMX_MODE_PRESET, std::max(DMX_MODE_SINGLE_RGB, int(personality))); DMXMode = std::min(DMX_MODE_PRESET, std::max(DMX_MODE_SINGLE_RGB, int(personality)));
doSerializeConfig = true; doSerializeConfig = true;
USER_PRINTF("DMX personality changed to to: %d\n", DMXMode); DEBUG_PRINTF("DMX personality changed to to: %d\n", DMXMode);
} }
} }
@ -33,7 +33,7 @@ void rdmAddressChangedCb(dmx_port_t dmxPort, const rdm_header_t *header,
DMXInput *dmx = static_cast<DMXInput *>(context); DMXInput *dmx = static_cast<DMXInput *>(context);
if (!dmx) { if (!dmx) {
USER_PRINTLN("DMX: Error: no context in rdmAddressChangedCb"); DEBUG_PRINTLN("DMX: Error: no context in rdmAddressChangedCb");
return; return;
} }
@ -41,7 +41,7 @@ void rdmAddressChangedCb(dmx_port_t dmxPort, const rdm_header_t *header,
const uint16_t addr = dmx_get_start_address(dmx->inputPortNum); const uint16_t addr = dmx_get_start_address(dmx->inputPortNum);
DMXAddress = std::min(512, int(addr)); DMXAddress = std::min(512, int(addr));
doSerializeConfig = true; doSerializeConfig = true;
USER_PRINTF("DMX start addr changed to: %d\n", DMXAddress); DEBUG_PRINTF("DMX start addr changed to: %d\n", DMXAddress);
} }
} }
@ -105,15 +105,15 @@ bool DMXInput::installDriver()
{ {
const auto config = createConfig(); const auto config = createConfig();
USER_PRINTF("DMX port: %u\n", inputPortNum); DEBUG_PRINTF("DMX port: %u\n", inputPortNum);
if (!dmx_driver_install(inputPortNum, &config, DMX_INTR_FLAGS_DEFAULT)) { if (!dmx_driver_install(inputPortNum, &config, DMX_INTR_FLAGS_DEFAULT)) {
USER_PRINTF("Error: Failed to install dmx driver\n"); DEBUG_PRINTF("Error: Failed to install dmx driver\n");
return false; return false;
} }
USER_PRINTF("Listening for DMX on pin %u\n", rxPin); DEBUG_PRINTF("Listening for DMX on pin %u\n", rxPin);
USER_PRINTF("Sending DMX on pin %u\n", txPin); DEBUG_PRINTF("Sending DMX on pin %u\n", txPin);
USER_PRINTF("DMX enable pin is: %u\n", enPin); DEBUG_PRINTF("DMX enable pin is: %u\n", enPin);
dmx_set_pin(inputPortNum, txPin, rxPin, enPin); dmx_set_pin(inputPortNum, txPin, rxPin, enPin);
rdm_register_dmx_start_address(inputPortNum, rdmAddressChangedCb, this); rdm_register_dmx_start_address(inputPortNum, rdmAddressChangedCb, this);
@ -129,7 +129,7 @@ void DMXInput::init(uint8_t rxPin, uint8_t txPin, uint8_t enPin, uint8_t inputPo
//TODO add again once dmx output has been merged //TODO add again once dmx output has been merged
// if(inputPortNum == dmxOutputPort) // if(inputPortNum == dmxOutputPort)
// { // {
// USER_PRINTF("DMXInput: Error: Input port == output port"); // DEBUG_PRINTF("DMXInput: Error: Input port == output port");
// return; // return;
// } // }
#endif #endif
@ -138,7 +138,7 @@ void DMXInput::init(uint8_t rxPin, uint8_t txPin, uint8_t enPin, uint8_t inputPo
this->inputPortNum = inputPortNum; this->inputPortNum = inputPortNum;
} }
else { else {
USER_PRINTF("DMXInput: Error: invalid inputPortNum: %d\n", inputPortNum); DEBUG_PRINTF("DMXInput: Error: invalid inputPortNum: %d\n", inputPortNum);
return; return;
} }
@ -148,12 +148,12 @@ void DMXInput::init(uint8_t rxPin, uint8_t txPin, uint8_t enPin, uint8_t inputPo
{(int8_t)txPin, false}, // these are not used as gpio pins, thus isOutput is always false. {(int8_t)txPin, false}, // these are not used as gpio pins, thus isOutput is always false.
{(int8_t)rxPin, false}, {(int8_t)rxPin, false},
{(int8_t)enPin, false}}; {(int8_t)enPin, false}};
const bool pinsAllocated = pinManager.allocateMultiplePins(pins, 3, PinOwner::DMX_INPUT); const bool pinsAllocated = PinManager::allocateMultiplePins(pins, 3, PinOwner::DMX_INPUT);
if (!pinsAllocated) { if (!pinsAllocated) {
USER_PRINTF("DMXInput: Error: Failed to allocate pins for DMX_INPUT. Pins already in use:\n"); DEBUG_PRINTF("DMXInput: Error: Failed to allocate pins for DMX_INPUT. Pins already in use:\n");
USER_PRINTF("rx in use by: %s\n", pinManager.getPinOwnerText(rxPin).c_str()); DEBUG_PRINTF("rx in use by: %s\n", pinManager.getPinOwnerText(rxPin).c_str());
USER_PRINTF("tx in use by: %s\n", pinManager.getPinOwnerText(txPin).c_str()); DEBUG_PRINTF("tx in use by: %s\n", pinManager.getPinOwnerText(txPin).c_str());
USER_PRINTF("en in use by: %s\n", pinManager.getPinOwnerText(enPin).c_str()); DEBUG_PRINTF("en in use by: %s\n", pinManager.getPinOwnerText(enPin).c_str());
return; return;
} }
@ -165,11 +165,11 @@ void DMXInput::init(uint8_t rxPin, uint8_t txPin, uint8_t enPin, uint8_t inputPo
// pin to core 0 because wled is running on core 1 // pin to core 0 because wled is running on core 1
xTaskCreatePinnedToCore(dmxReceiverTask, "DMX_RCV_TASK", 10240, this, 2, &task, 0); xTaskCreatePinnedToCore(dmxReceiverTask, "DMX_RCV_TASK", 10240, this, 2, &task, 0);
if (!task) { if (!task) {
USER_PRINTF("Error: Failed to create dmx rcv task"); DEBUG_PRINTF("Error: Failed to create dmx rcv task");
} }
} }
else { else {
USER_PRINTLN("DMX input disabled due to rxPin, enPin or txPin not set"); DEBUG_PRINTLN("DMX input disabled due to rxPin, enPin or txPin not set");
return; return;
} }
} }
@ -187,7 +187,7 @@ void DMXInput::updateInternal()
if (dmx_receive(inputPortNum, &packet, DMX_TIMEOUT_TICK)) { if (dmx_receive(inputPortNum, &packet, DMX_TIMEOUT_TICK)) {
if (!packet.err) { if (!packet.err) {
if(!connected) { if(!connected) {
USER_PRINTLN("DMX Input - connected"); DEBUG_PRINTLN("DMX Input - connected");
} }
connected = true; connected = true;
identify = isIdentifyOn(); identify = isIdentifyOn();
@ -202,7 +202,7 @@ void DMXInput::updateInternal()
} }
else { else {
if(connected) { if(connected) {
USER_PRINTLN("DMX Input - disconnected"); DEBUG_PRINTLN("DMX Input - disconnected");
} }
connected = false; connected = false;
} }

View File

@ -116,6 +116,11 @@ void handleE131Packet(e131_packet_t* p, IPAddress clientIP, byte protocol){
// update status info // update status info
realtimeIP = clientIP; realtimeIP = clientIP;
handleDMXData(uni, dmxChannels, e131_data, mde, previousUniverses);
}
void handleDMXData(uint16_t uni, uint16_t dmxChannels, uint8_t* e131_data, uint8_t mde, uint8_t previousUniverses) {
byte wChannel = 0; byte wChannel = 0;
unsigned totalLen = strip.getLengthTotal(); unsigned totalLen = strip.getLengthTotal();
unsigned availDMXLen = 0; unsigned availDMXLen = 0;
@ -130,7 +135,7 @@ void handleE131Packet(e131_packet_t* p, IPAddress clientIP, byte protocol){
} }
// DMX data in Art-Net packet starts at index 0, for E1.31 at index 1 // DMX data in Art-Net packet starts at index 0, for E1.31 at index 1
if (protocol == P_ARTNET && dataOffset > 0) { if (mde == REALTIME_MODE_ARTNET && dataOffset > 0) {
dataOffset--; dataOffset--;
} }
@ -211,7 +216,7 @@ void handleE131Packet(e131_packet_t* p, IPAddress clientIP, byte protocol){
else else
dataOffset = DMXAddress; dataOffset = DMXAddress;
// Modify address for Art-Net data // Modify address for Art-Net data
if (protocol == P_ARTNET && dataOffset > 0) if (mde == REALTIME_MODE_ARTNET && dataOffset > 0)
dataOffset--; dataOffset--;
// Skip out of universe addresses // Skip out of universe addresses
if (dataOffset > dmxChannels - dmxEffectChannels + 1) if (dataOffset > dmxChannels - dmxEffectChannels + 1)
@ -285,7 +290,7 @@ void handleE131Packet(e131_packet_t* p, IPAddress clientIP, byte protocol){
} }
} else { } else {
// All subsequent universes start at the first channel. // All subsequent universes start at the first channel.
dmxOffset = (protocol == P_ARTNET) ? 0 : 1; dmxOffset = (mde == REALTIME_MODE_ARTNET) ? 0 : 1;
const unsigned dimmerOffset = (DMXMode == DMX_MODE_MULTIPLE_DRGB) ? 1 : 0; const unsigned dimmerOffset = (DMXMode == DMX_MODE_MULTIPLE_DRGB) ? 1 : 0;
unsigned ledsInFirstUniverse = (((MAX_CHANNELS_PER_UNIVERSE - DMXAddress) + dmxLenOffset) - dimmerOffset) / dmxChannelsPerLed; unsigned ledsInFirstUniverse = (((MAX_CHANNELS_PER_UNIVERSE - DMXAddress) + dmxLenOffset) - dimmerOffset) / dmxChannelsPerLed;
previousLeds = ledsInFirstUniverse + (previousUniverses - 1) * ledsPerUniverse; previousLeds = ledsInFirstUniverse + (previousUniverses - 1) * ledsPerUniverse;

View File

@ -193,6 +193,7 @@ void handleDMXInput();
//e131.cpp //e131.cpp
void handleE131Packet(e131_packet_t* p, IPAddress clientIP, byte protocol); void handleE131Packet(e131_packet_t* p, IPAddress clientIP, byte protocol);
void handleDMXData(uint16_t uni, uint16_t dmxChannels, uint8_t* e131_data, uint8_t mde, uint8_t previousUniverses);
void handleArtnetPollReply(IPAddress ipAddress); void handleArtnetPollReply(IPAddress ipAddress);
void prepareArtnetPollReply(ArtPollReply* reply); void prepareArtnetPollReply(ArtPollReply* reply);
void sendArtnetPollReply(ArtPollReply* reply, IPAddress ipAddress, uint16_t portAddress); void sendArtnetPollReply(ArtPollReply* reply, IPAddress ipAddress, uint16_t portAddress);

View File

@ -442,11 +442,11 @@ void getSettingsJS(byte subPage, Print& settingsScript)
#ifndef WLED_ENABLE_DMX_INPUT #ifndef WLED_ENABLE_DMX_INPUT
settingsScript.print(SET_F("hideDMXInput();")); // hide "dmx input" settings settingsScript.print(SET_F("hideDMXInput();")); // hide "dmx input" settings
#else #else
settingsScript.print(SET_F("hideNoDMXInput();")); //hide "not comp iled in" message settingsScript.print(SET_F("hideNoDMXInput();")); //hide "not compiled in" message
sappend('v',SET_F("IDMT"),dmxInputTransmitPin); printSetFormValue(settingsScript,SET_F("IDMT"),dmxInputTransmitPin);
sappend('v',SET_F("IDMR"),dmxInputReceivePin); printSetFormValue(settingsScript,SET_F("IDMR"),dmxInputReceivePin);
sappend('v',SET_F("IDME"),dmxInputEnablePin); printSetFormValue(settingsScript,SET_F("IDME"),dmxInputEnablePin);
sappend('v',SET_F("IDMP"),dmxInputPort); printSetFormValue(settingsScript,SET_F("IDMP"),dmxInputPort);
#endif #endif
printSetFormValue(settingsScript,PSTR("DA"),DMXAddress); printSetFormValue(settingsScript,PSTR("DA"),DMXAddress);
printSetFormValue(settingsScript,PSTR("XX"),DMXSegmentSpacing); printSetFormValue(settingsScript,PSTR("XX"),DMXSegmentSpacing);