diff --git a/src/main.cpp b/src/main.cpp index 7a01321..436b0bf 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -449,6 +449,51 @@ void loop() dmx_read_offset(dmx1, 1, dmx1_data, 512); artnet.sendArtDmx(broadcastIp, universe1, dmx1_data, 512); + /* 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 (!dmx1_packet.err) + { + /* If this is the first DMX data we've received, lets log it! */ + if (!dmx1_IsConnected) + { + Serial.println("DMX1 in is connected!"); + dmx1_IsConnected = true; + } + + /* Don't forget we need to actually read the DMX data into our buffer so + that we can print it out. */ + + /*dmx_read_offset(dmx1, 1, dmx1_data, dmx1_packet.size); + artnet.sendArtDmx(broadcastIp, universe1, dmx1_data, 512);*/ + + if (now - dmx1_lastUpdate > 1000) + { + /* Print the received start code - it's usually 0. */ + // Serial.printf("Start code is 0x%02X and slot 1 is 0x%02X\n", dmx1_data[0], dmx1_data[1]); + dmx1_lastUpdate = 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. */ + Serial.println("A DMX 1 error occurred."); + } + } + else if (dmx1_IsConnected) + { + /* If DMX times out after having been connected, it likely means that the + DMX cable was unplugged. When that happens in this example sketch, we'll + uninstall the DMX driver. */ + Serial.println("DMX 1 was disconnected."); + dmx1_IsConnected = false; + // dmx_driver_delete(dmx1); } if (direction2 == Input && dmx_receive(dmx2, &dmx2_packet, DMX_TIMEOUT_TICK))