Inital code swapping DMX input over to use esp_dmx

This commit is contained in:
Will Tatam
2023-02-18 16:05:42 +00:00
parent a6b52a6e1e
commit 5b76df903f
4 changed files with 73 additions and 8 deletions

View File

@@ -99,13 +99,59 @@ void initDMX() {}
#endif
#ifdef WLED_ENABLE_DMX_INPUT
bool dmxIsConnected = false;
unsigned long dmxLastUpdate = 0;
void handleDMXInput() {
dmx.update();
uint8_t data[512] = {};
for(int i=0; i < 512; i++) {
data[i] = dmx.read(i + 1);
byte data[DMX_PACKET_SIZE];
/* We need a place to store information about the DMX packets we receive. We
will use a dmx_packet_t to store that packet information. */
dmx_packet_t packet;
/* And now we wait! The DMX standard defines the amount of time until DMX
officially times out. That amount of time is converted into ESP32 clock
ticks using the constant `DMX_TIMEOUT_TICK`. If it takes longer than that
amount of time to receive data, this if statement will evaluate to false. */
if (dmx_receive(dmxPort, &packet, DMX_TIMEOUT_TICK)) {
/* If this code gets called, it means we've received DMX data! */
/* Get the current time since boot in milliseconds so that we can find out
how long it has been since we last updated data and printed to the Serial
Monitor. */
unsigned long now = millis();
/* We should check to make sure that there weren't any DMX errors. */
if (!packet.err) {
/* If this is the first DMX data we've received, lets log it! */
if (!dmxIsConnected) {
DEBUG_PRINTLN("DMX is connected!");
dmxIsConnected = true;
}
/* Don't forget we need to actually read the DMX data into our buffer so
that we can print it out. */
dmx_read(dmxPort, data, packet.size);
if (now - dmxLastUpdate > 1000) {
/* Print the received start code - it's usually 0. */
DEBUG_PRINTF("Start code is 0x%02X and slot 1 is 0x%02X\n", data[0],
data[1]);
dmxLastUpdate = now;
}
} else {
/* Oops! A DMX error occurred! Don't worry, this can happen when you first
connect or disconnect your DMX devices. If you are consistently getting
DMX errors, then something may have gone wrong with your code or
something is seriously wrong with your DMX transmitter. */
DEBUG_PRINTLN("A DMX error occurred.");
}
} else if (dmxIsConnected) {
DEBUG_PRINTLN("DMX was disconnected.");
}
if(dmxIsConnected) {
DEBUG_PRINTF("DMX channel 1 = %u\n", data(1)); // TODO: remove from final code
handleDMXData(1, 512, data, 1, REALTIME_MODE_DMX, 0);
}
handleDMXData(1, 512, data, 1, REALTIME_MODE_DMX, 0);
DEBUG_PRINTF("DMX channel 1 = %u\n", dmx.read(1)); // TODO: remove from final code
}
#endif