2020-04-10 12:30:08 +02:00
|
|
|
#include "wled.h"
|
|
|
|
|
|
|
|
/*
|
2022-05-05 02:28:09 +02:00
|
|
|
* Support for DMX 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:
|
2020-04-10 12:30:08 +02:00
|
|
|
* https://github.com/Rickgg/ESP-Dmx
|
2022-05-05 02:28:09 +02:00
|
|
|
* ESP32 Library from:
|
|
|
|
* https://github.com/sparkfun/SparkFunDMX
|
2020-04-10 12:30:08 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef WLED_ENABLE_DMX
|
|
|
|
|
|
|
|
void handleDMX()
|
|
|
|
{
|
2020-04-21 22:56:14 +02:00
|
|
|
// don't act, when in DMX Proxy mode
|
|
|
|
if (e131ProxyUniverse != 0) return;
|
|
|
|
|
2020-04-10 12:30:08 +02:00
|
|
|
uint8_t brightness = strip.getBrightness();
|
|
|
|
|
2022-05-05 02:28:09 +02:00
|
|
|
bool calc_brightness = true;
|
|
|
|
|
|
|
|
// check if no shutter channel is set
|
|
|
|
for (byte i = 0; i < DMXChannels; i++)
|
|
|
|
{
|
|
|
|
if (DMXFixtureMap[i] == 5) calc_brightness = false;
|
|
|
|
}
|
|
|
|
|
2021-10-31 11:57:41 +01:00
|
|
|
uint16_t len = strip.getLengthTotal();
|
|
|
|
for (int i = DMXStartLED; i < len; i++) { // uses the amount of LEDs as fixture count
|
2020-04-10 12:30:08 +02:00
|
|
|
|
|
|
|
uint32_t in = strip.getPixelColor(i); // get the colors for the individual fixtures as suggested by Aircoookie in issue #462
|
2021-10-26 19:17:42 +02:00
|
|
|
byte w = W(in);
|
|
|
|
byte r = R(in);
|
|
|
|
byte g = G(in);
|
|
|
|
byte b = B(in);
|
2020-04-10 12:30:08 +02:00
|
|
|
|
|
|
|
int DMXFixtureStart = DMXStart + (DMXGap * (i - DMXStartLED));
|
|
|
|
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
|
2022-05-05 02:28:09 +02:00
|
|
|
dmx.write(DMXAddr, calc_brightness ? (r * brightness) / 255 : r);
|
2020-04-10 12:30:08 +02:00
|
|
|
break;
|
|
|
|
case 2: // Green
|
2022-05-05 02:28:09 +02:00
|
|
|
dmx.write(DMXAddr, calc_brightness ? (g * brightness) / 255 : g);
|
2020-04-10 12:30:08 +02:00
|
|
|
break;
|
|
|
|
case 3: // Blue
|
2022-05-05 02:28:09 +02:00
|
|
|
dmx.write(DMXAddr, calc_brightness ? (b * brightness) / 255 : b);
|
2020-04-10 12:30:08 +02:00
|
|
|
break;
|
|
|
|
case 4: // White
|
2022-05-05 02:28:09 +02:00
|
|
|
dmx.write(DMXAddr, calc_brightness ? (w * brightness) / 255 : w);
|
2020-04-10 12:30:08 +02:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
void initDMX() {
|
2022-05-05 02:28:09 +02:00
|
|
|
#ifdef ESP8266
|
2020-04-10 12:30:08 +02:00
|
|
|
dmx.init(512); // initialize with bus length
|
2022-05-05 02:28:09 +02:00
|
|
|
#else
|
|
|
|
dmx.initWrite(512); // initialize with bus length
|
2023-01-06 09:24:29 +01:00
|
|
|
#endif
|
2020-04-10 12:30:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
void handleDMX() {}
|
|
|
|
void initDMX() {}
|
|
|
|
#endif
|