WLED/wled00/wled21_dmx.ino
jwingefeld 8be72f6f23
DMX Support for WLED (#704)
* initial dmx setup

* adds support for multiple fixtures, addr gaps, start addresses and all that good DMX stuff

* removes init function. do not need.

* adds some comments, removes others. words.

* added menu entry and dummy HTML

* added server request handler

* cloned options page UI for DMX

* only add code when DMX is enabled

* added infobutton to HTML

* DMX settings form

* procedurally generated HTML form. OBACHT: Values still not coming from the EEPROM.

* upped eeprom version to 15

* changed index for set to 255 to 6 because web interface wants it that way

* gets values for XML from actual settings

* changes the default values for dmx to blanks

* reads and writes DMX settings from EEPROM (2550 - 2569)

* fixes addressing bug in DMX EEPROM read

* saves settings from WebUI to memory

* disables DMX by default

* changed a comment in the ENABLE_DMX line

* makes the display of the DMX entry in settings dependant on WLED_DMX_ENABLE

* adds the server listener for the DMX map

* fixes a bug when selecting 255 for a channel at the dmx settings page

* now actually reads the DMX settings back to the HTML UI.

* cleans up a little

* adds a warning message to the HTML UI when setting up defunct DMX settings

* changed DMX EEPROM addressing to close a gap

* basic DMX map

* fixes a few styling flaws and bugs in the DMX map

* changes config variables to uint16_t

Co-authored-by: Aircoookie <cschwinne@gmail.com>
2020-02-23 22:24:51 +01:00

56 lines
1.6 KiB
C++

/*
* Support for DMX via MAX485.
* Needs the espdmx library. You might have to change the output pin within the library. Sketchy, i know.
* https://github.com/Rickgg/ESP-Dmx
*/
#ifdef WLED_ENABLE_DMX
void handleDMX() {
// TODO: calculate brightness manually if no shutter channel is set
uint8_t brightness = strip.getBrightness();
for (int i = 0; i < ledCount; i++) { // uses the amount of LEDs as fixture count
uint32_t in = strip.getPixelColor(i); // time to get the colors for the individual fixtures as suggested by AirCookie at issue #462
byte w = in >> 24 & 0xFF;
byte r = in >> 16 & 0xFF;
byte g = in >> 8 & 0xFF;
byte b = in & 0xFF;
int DMXFixtureStart = DMXStart + (DMXGap * i);
for (int j = 0; j < DMXChannels; j++) {
int DMXAddr = DMXFixtureStart + j;
switch (DMXFixtureMap[j]) {
case 0: // Set this channel to 0. Good way to tell strobe- and fade-functions to fuck right off.
dmx.write(DMXAddr, 0);
break;
case 1: // Red
dmx.write(DMXAddr, r);
break;
case 2: // Green
dmx.write(DMXAddr, g);
break;
case 3: // Blue
dmx.write(DMXAddr, b);
break;
case 4: // White
dmx.write(DMXAddr, w);
break;
case 5: // Shutter channel. Controls the brightness.
dmx.write(DMXAddr, brightness);
break;
case 6:// Sets this channel to 255. Like 0, but more wholesome.
dmx.write(DMXAddr, 255);
break;
}
}
}
dmx.update(); // update the DMX bus
}
#else
void handleDMX() {}
#endif