WLED/wled00/dmx.h

65 lines
1.8 KiB
C
Raw Normal View History

2020-03-28 13:30:51 +01:00
#ifndef WLED_DMX_H
#define WLED_DMX_H
#include "wled.h"
2020-03-28 13:30:51 +01:00
/*
* Support for DMX via MAX485.
* Change the output pin in src/dependencies/ESPDMX.cpp if needed.
* Library from:
2020-03-28 13:30:51 +01:00
* https://github.com/Rickgg/ESP-Dmx
*/
2020-03-30 09:55:44 +02:00
#ifdef WLED_ENABLE_DMX
#include "src/dependencies/dmx/ESPDMX.h"
2020-03-30 09:55:44 +02:00
DMXESPSerial dmx;
void handleDMX()
{
2020-03-30 09:55:44 +02:00
// TODO: calculate brightness manually if no shutter channel is set
2020-03-30 09:55:44 +02:00
uint8_t brightness = strip.getBrightness();
for (int i = 0; i < ledCount; i++) { // uses the amount of LEDs as fixture count
2020-03-30 09:55:44 +02:00
uint32_t in = strip.getPixelColor(i); // time to get the colors for the individual fixtures as suggested by AirCookie at issue #462
2020-03-30 09:55:44 +02:00
byte w = in >> 24 & 0xFF;
byte r = in >> 16 & 0xFF;
byte g = in >> 8 & 0xFF;
byte b = in & 0xFF;
2020-03-30 09:55:44 +02:00
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.
2020-03-30 09:55:44 +02:00
dmx.write(DMXAddr, 0);
break;
case 1: // Red
2020-03-30 09:55:44 +02:00
dmx.write(DMXAddr, r);
break;
case 2: // Green
2020-03-30 09:55:44 +02:00
dmx.write(DMXAddr, g);
break;
case 3: // Blue
2020-03-30 09:55:44 +02:00
dmx.write(DMXAddr, b);
break;
case 4: // White
2020-03-30 09:55:44 +02:00
dmx.write(DMXAddr, w);
break;
case 5: // Shutter channel. Controls the brightness.
2020-03-30 09:55:44 +02:00
dmx.write(DMXAddr, brightness);
break;
case 6: // Sets this channel to 255. Like 0, but more wholesome.
2020-03-30 09:55:44 +02:00
dmx.write(DMXAddr, 255);
break;
}
}
}
dmx.update(); // update the DMX bus
2020-03-30 09:55:44 +02:00
}
#else
void handleDMX() {}
#endif
2020-03-28 13:30:51 +01:00
#endif //WLED_DMX_H