Skip to content

Commit a582786

Browse files
author
Will Tatam
committed
Port over remaining WLEDMM part of DMX Input and adapt for AC
1 parent 953e994 commit a582786

File tree

6 files changed

+38
-31
lines changed

6 files changed

+38
-31
lines changed

wled00/const.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@
249249
#define REALTIME_MODE_ARTNET 6
250250
#define REALTIME_MODE_TPM2NET 7
251251
#define REALTIME_MODE_DDP 8
252+
#define REALTIME_MODE_DMX 9
252253

253254
//realtime override modes
254255
#define REALTIME_OVERRIDE_NONE 0

wled00/data/settings_sync.htm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,17 +151,17 @@ <h3>Realtime</h3>
151151
Force max brightness: <input type="checkbox" name="FB"><br>
152152
Disable realtime gamma correction: <input type="checkbox" name="RG"><br>
153153
Realtime LED offset: <input name="WO" type="number" min="-255" max="255" required>
154-
<div id="dmxInput"> <!--WLEDMM-->
154+
<div id="dmxInput">
155155
<h4>Wired DMX Input Pins</h4>
156156
DMX RX: <input name="IDMR" type="number" min="-1" max="99">RO<br/>
157157
DMX TX: <input name="IDMT" type="number" min="-1" max="99">DI<br/>
158158
DMX Enable: <input name="IDME" type="number" min="-1" max="99">RE+DE<br/>
159159
DMX Port: <input name="IDMP" type="number" min="1" max="2"><br/>
160160
</div>
161-
<div id="dmxInputOff"> <!--WLEDMM-->
161+
<div id="dmxInputOff">
162162
<br><em style="color:darkorange">This firmware build does not include DMX Input support. <br></em>
163163
</div>
164-
<div id="dmxOnOff2"> <!--WLEDMM-->
164+
<div id="dmxOnOff2">
165165
<br><em style="color:darkorange">This firmware build does not include DMX output support. <br></em>
166166
</div>
167167
<hr class="sml">

wled00/dmx_input.cpp

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ void rdmPersonalityChangedCb(dmx_port_t dmxPort, const rdm_header_t *header,
1515
DMXInput *dmx = static_cast<DMXInput *>(context);
1616

1717
if (!dmx) {
18-
USER_PRINTLN("DMX: Error: no context in rdmPersonalityChangedCb");
18+
DEBUG_PRINTLN("DMX: Error: no context in rdmPersonalityChangedCb");
1919
return;
2020
}
2121

2222
if (header->cc == RDM_CC_SET_COMMAND_RESPONSE) {
2323
const uint8_t personality = dmx_get_current_personality(dmx->inputPortNum);
2424
DMXMode = std::min(DMX_MODE_PRESET, std::max(DMX_MODE_SINGLE_RGB, int(personality)));
2525
doSerializeConfig = true;
26-
USER_PRINTF("DMX personality changed to to: %d\n", DMXMode);
26+
DEBUG_PRINTF("DMX personality changed to to: %d\n", DMXMode);
2727
}
2828
}
2929

@@ -33,15 +33,15 @@ void rdmAddressChangedCb(dmx_port_t dmxPort, const rdm_header_t *header,
3333
DMXInput *dmx = static_cast<DMXInput *>(context);
3434

3535
if (!dmx) {
36-
USER_PRINTLN("DMX: Error: no context in rdmAddressChangedCb");
36+
DEBUG_PRINTLN("DMX: Error: no context in rdmAddressChangedCb");
3737
return;
3838
}
3939

4040
if (header->cc == RDM_CC_SET_COMMAND_RESPONSE) {
4141
const uint16_t addr = dmx_get_start_address(dmx->inputPortNum);
4242
DMXAddress = std::min(512, int(addr));
4343
doSerializeConfig = true;
44-
USER_PRINTF("DMX start addr changed to: %d\n", DMXAddress);
44+
DEBUG_PRINTF("DMX start addr changed to: %d\n", DMXAddress);
4545
}
4646
}
4747

@@ -105,15 +105,15 @@ bool DMXInput::installDriver()
105105
{
106106

107107
const auto config = createConfig();
108-
USER_PRINTF("DMX port: %u\n", inputPortNum);
108+
DEBUG_PRINTF("DMX port: %u\n", inputPortNum);
109109
if (!dmx_driver_install(inputPortNum, &config, DMX_INTR_FLAGS_DEFAULT)) {
110-
USER_PRINTF("Error: Failed to install dmx driver\n");
110+
DEBUG_PRINTF("Error: Failed to install dmx driver\n");
111111
return false;
112112
}
113113

114-
USER_PRINTF("Listening for DMX on pin %u\n", rxPin);
115-
USER_PRINTF("Sending DMX on pin %u\n", txPin);
116-
USER_PRINTF("DMX enable pin is: %u\n", enPin);
114+
DEBUG_PRINTF("Listening for DMX on pin %u\n", rxPin);
115+
DEBUG_PRINTF("Sending DMX on pin %u\n", txPin);
116+
DEBUG_PRINTF("DMX enable pin is: %u\n", enPin);
117117
dmx_set_pin(inputPortNum, txPin, rxPin, enPin);
118118

119119
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
129129
//TODO add again once dmx output has been merged
130130
// if(inputPortNum == dmxOutputPort)
131131
// {
132-
// USER_PRINTF("DMXInput: Error: Input port == output port");
132+
// DEBUG_PRINTF("DMXInput: Error: Input port == output port");
133133
// return;
134134
// }
135135
#endif
@@ -138,7 +138,7 @@ void DMXInput::init(uint8_t rxPin, uint8_t txPin, uint8_t enPin, uint8_t inputPo
138138
this->inputPortNum = inputPortNum;
139139
}
140140
else {
141-
USER_PRINTF("DMXInput: Error: invalid inputPortNum: %d\n", inputPortNum);
141+
DEBUG_PRINTF("DMXInput: Error: invalid inputPortNum: %d\n", inputPortNum);
142142
return;
143143
}
144144

@@ -148,12 +148,12 @@ void DMXInput::init(uint8_t rxPin, uint8_t txPin, uint8_t enPin, uint8_t inputPo
148148
{(int8_t)txPin, false}, // these are not used as gpio pins, thus isOutput is always false.
149149
{(int8_t)rxPin, false},
150150
{(int8_t)enPin, false}};
151-
const bool pinsAllocated = pinManager.allocateMultiplePins(pins, 3, PinOwner::DMX_INPUT);
151+
const bool pinsAllocated = PinManager::allocateMultiplePins(pins, 3, PinOwner::DMX_INPUT);
152152
if (!pinsAllocated) {
153-
USER_PRINTF("DMXInput: Error: Failed to allocate pins for DMX_INPUT. Pins already in use:\n");
154-
USER_PRINTF("rx in use by: %s\n", pinManager.getPinOwnerText(rxPin).c_str());
155-
USER_PRINTF("tx in use by: %s\n", pinManager.getPinOwnerText(txPin).c_str());
156-
USER_PRINTF("en in use by: %s\n", pinManager.getPinOwnerText(enPin).c_str());
153+
DEBUG_PRINTF("DMXInput: Error: Failed to allocate pins for DMX_INPUT. Pins already in use:\n");
154+
DEBUG_PRINTF("rx in use by: %s\n", pinManager.getPinOwnerText(rxPin).c_str());
155+
DEBUG_PRINTF("tx in use by: %s\n", pinManager.getPinOwnerText(txPin).c_str());
156+
DEBUG_PRINTF("en in use by: %s\n", pinManager.getPinOwnerText(enPin).c_str());
157157
return;
158158
}
159159

@@ -165,11 +165,11 @@ void DMXInput::init(uint8_t rxPin, uint8_t txPin, uint8_t enPin, uint8_t inputPo
165165
// pin to core 0 because wled is running on core 1
166166
xTaskCreatePinnedToCore(dmxReceiverTask, "DMX_RCV_TASK", 10240, this, 2, &task, 0);
167167
if (!task) {
168-
USER_PRINTF("Error: Failed to create dmx rcv task");
168+
DEBUG_PRINTF("Error: Failed to create dmx rcv task");
169169
}
170170
}
171171
else {
172-
USER_PRINTLN("DMX input disabled due to rxPin, enPin or txPin not set");
172+
DEBUG_PRINTLN("DMX input disabled due to rxPin, enPin or txPin not set");
173173
return;
174174
}
175175
}
@@ -187,7 +187,7 @@ void DMXInput::updateInternal()
187187
if (dmx_receive(inputPortNum, &packet, DMX_TIMEOUT_TICK)) {
188188
if (!packet.err) {
189189
if(!connected) {
190-
USER_PRINTLN("DMX Input - connected");
190+
DEBUG_PRINTLN("DMX Input - connected");
191191
}
192192
connected = true;
193193
identify = isIdentifyOn();
@@ -202,7 +202,7 @@ void DMXInput::updateInternal()
202202
}
203203
else {
204204
if(connected) {
205-
USER_PRINTLN("DMX Input - disconnected");
205+
DEBUG_PRINTLN("DMX Input - disconnected");
206206
}
207207
connected = false;
208208
}

wled00/e131.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@ void handleE131Packet(e131_packet_t* p, IPAddress clientIP, byte protocol){
116116

117117
// update status info
118118
realtimeIP = clientIP;
119+
120+
handleDMXData(uni, dmxChannels, e131_data, mde, previousUniverses);
121+
}
122+
123+
void handleDMXData(uint16_t uni, uint16_t dmxChannels, uint8_t* e131_data, uint8_t mde, uint8_t previousUniverses) {
119124
byte wChannel = 0;
120125
unsigned totalLen = strip.getLengthTotal();
121126
unsigned availDMXLen = 0;
@@ -130,7 +135,7 @@ void handleE131Packet(e131_packet_t* p, IPAddress clientIP, byte protocol){
130135
}
131136

132137
// DMX data in Art-Net packet starts at index 0, for E1.31 at index 1
133-
if (protocol == P_ARTNET && dataOffset > 0) {
138+
if (mde == REALTIME_MODE_ARTNET && dataOffset > 0) {
134139
dataOffset--;
135140
}
136141

@@ -211,7 +216,7 @@ void handleE131Packet(e131_packet_t* p, IPAddress clientIP, byte protocol){
211216
else
212217
dataOffset = DMXAddress;
213218
// Modify address for Art-Net data
214-
if (protocol == P_ARTNET && dataOffset > 0)
219+
if (mde == REALTIME_MODE_ARTNET && dataOffset > 0)
215220
dataOffset--;
216221
// Skip out of universe addresses
217222
if (dataOffset > dmxChannels - dmxEffectChannels + 1)
@@ -285,7 +290,7 @@ void handleE131Packet(e131_packet_t* p, IPAddress clientIP, byte protocol){
285290
}
286291
} else {
287292
// All subsequent universes start at the first channel.
288-
dmxOffset = (protocol == P_ARTNET) ? 0 : 1;
293+
dmxOffset = (mde == REALTIME_MODE_ARTNET) ? 0 : 1;
289294
const unsigned dimmerOffset = (DMXMode == DMX_MODE_MULTIPLE_DRGB) ? 1 : 0;
290295
unsigned ledsInFirstUniverse = (((MAX_CHANNELS_PER_UNIVERSE - DMXAddress) + dmxLenOffset) - dimmerOffset) / dmxChannelsPerLed;
291296
previousLeds = ledsInFirstUniverse + (previousUniverses - 1) * ledsPerUniverse;

wled00/fcn_declare.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ void handleDMXInput();
193193

194194
//e131.cpp
195195
void handleE131Packet(e131_packet_t* p, IPAddress clientIP, byte protocol);
196+
void handleDMXData(uint16_t uni, uint16_t dmxChannels, uint8_t* e131_data, uint8_t mde, uint8_t previousUniverses);
196197
void handleArtnetPollReply(IPAddress ipAddress);
197198
void prepareArtnetPollReply(ArtPollReply* reply);
198199
void sendArtnetPollReply(ArtPollReply* reply, IPAddress ipAddress, uint16_t portAddress);

wled00/xml.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -442,11 +442,11 @@ void getSettingsJS(byte subPage, Print& settingsScript)
442442
#ifndef WLED_ENABLE_DMX_INPUT
443443
settingsScript.print(SET_F("hideDMXInput();")); // hide "dmx input" settings
444444
#else
445-
settingsScript.print(SET_F("hideNoDMXInput();")); //hide "not comp iled in" message
446-
sappend('v',SET_F("IDMT"),dmxInputTransmitPin);
447-
sappend('v',SET_F("IDMR"),dmxInputReceivePin);
448-
sappend('v',SET_F("IDME"),dmxInputEnablePin);
449-
sappend('v',SET_F("IDMP"),dmxInputPort);
445+
settingsScript.print(SET_F("hideNoDMXInput();")); //hide "not compiled in" message
446+
printSetFormValue(settingsScript,SET_F("IDMT"),dmxInputTransmitPin);
447+
printSetFormValue(settingsScript,SET_F("IDMR"),dmxInputReceivePin);
448+
printSetFormValue(settingsScript,SET_F("IDME"),dmxInputEnablePin);
449+
printSetFormValue(settingsScript,SET_F("IDMP"),dmxInputPort);
450450
#endif
451451
printSetFormValue(settingsScript,PSTR("DA"),DMXAddress);
452452
printSetFormValue(settingsScript,PSTR("XX"),DMXSegmentSpacing);

0 commit comments

Comments
 (0)