mirror of
https://github.com/HendrikRauh/dmx-interface.git
synced 2025-05-19 10:32:56 +00:00
Merge pull request #70 from HendrikRauh/debug-dmx
Working DMX input and output
This commit is contained in:
commit
1b86aabf3e
1 changed files with 97 additions and 50 deletions
123
src/main.cpp
123
src/main.cpp
|
@ -1,8 +1,8 @@
|
||||||
#ifdef ESP32
|
#ifdef ESP32
|
||||||
#include <WiFi.h>
|
#include <WiFi.h>
|
||||||
#include <AsyncTCP.h>
|
#include <AsyncTCP.h>
|
||||||
//#include <USB.h>
|
// #include <USB.h>
|
||||||
//#include "USBCDC.h"
|
// #include "USBCDC.h"
|
||||||
#include "driver/temp_sensor.h"
|
#include "driver/temp_sensor.h"
|
||||||
#elif defined(ESP8266)
|
#elif defined(ESP8266)
|
||||||
#include <ESP8266WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
|
@ -16,7 +16,7 @@
|
||||||
#include <ArtnetWiFi.h>
|
#include <ArtnetWiFi.h>
|
||||||
#include <ArduinoJson.h>
|
#include <ArduinoJson.h>
|
||||||
|
|
||||||
//#include "ESPDMX.h"
|
// #include "ESPDMX.h"
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <esp_dmx.h>
|
#include <esp_dmx.h>
|
||||||
|
|
||||||
|
@ -24,8 +24,8 @@
|
||||||
#include "routes/config.h"
|
#include "routes/config.h"
|
||||||
#include "routes/networks.h"
|
#include "routes/networks.h"
|
||||||
|
|
||||||
//DMXESPSerial dmx1;
|
// DMXESPSerial dmx1;
|
||||||
//DMXESPSerial dmx2;
|
// DMXESPSerial dmx2;
|
||||||
dmx_port_t dmx1 = DMX_NUM_0; // for esp32s2
|
dmx_port_t dmx1 = DMX_NUM_0; // for esp32s2
|
||||||
dmx_port_t dmx2 = DMX_NUM_1;
|
dmx_port_t dmx2 = DMX_NUM_1;
|
||||||
byte dmx1_data[DMX_PACKET_SIZE];
|
byte dmx1_data[DMX_PACKET_SIZE];
|
||||||
|
@ -42,7 +42,7 @@ bool dmx2_IsConnected = false;
|
||||||
uint8_t brightness_led = 20;
|
uint8_t brightness_led = 20;
|
||||||
bool status_led;
|
bool status_led;
|
||||||
|
|
||||||
hw_timer_t *timer = NULL; // H/W timer defining (Pointer to the Structure)
|
/* hw_timer_t *timer = NULL; // H/W timer defining (Pointer to the Structure)
|
||||||
portMUX_TYPE timerMux = portMUX_INITIALIZER_UNLOCKED;
|
portMUX_TYPE timerMux = portMUX_INITIALIZER_UNLOCKED;
|
||||||
void IRAM_ATTR onTimer()
|
void IRAM_ATTR onTimer()
|
||||||
{ // Defining interrupt function with IRAM_ATTR for faster access
|
{ // Defining interrupt function with IRAM_ATTR for faster access
|
||||||
|
@ -57,7 +57,7 @@ void IRAM_ATTR onTimer()
|
||||||
analogWrite(PIN_LED, 0);
|
analogWrite(PIN_LED, 0);
|
||||||
}
|
}
|
||||||
portEXIT_CRITICAL_ISR(&timerMux);
|
portEXIT_CRITICAL_ISR(&timerMux);
|
||||||
}
|
} */
|
||||||
|
|
||||||
// Ethernet stuff
|
// Ethernet stuff
|
||||||
#define ETH_SCK 36
|
#define ETH_SCK 36
|
||||||
|
@ -77,7 +77,7 @@ uint8_t universe1;
|
||||||
uint8_t universe2;
|
uint8_t universe2;
|
||||||
Direction direction1;
|
Direction direction1;
|
||||||
Direction direction2;
|
Direction direction2;
|
||||||
|
/*
|
||||||
void ledBlink(int ms)
|
void ledBlink(int ms)
|
||||||
{
|
{
|
||||||
if (timer == NULL)
|
if (timer == NULL)
|
||||||
|
@ -96,7 +96,7 @@ void ledBlink(int ms)
|
||||||
timerAlarmWrite(timer, ms, true); // Match value= 1000000 for 1 sec. delay.
|
timerAlarmWrite(timer, ms, true); // Match value= 1000000 for 1 sec. delay.
|
||||||
timerAlarmEnable(timer); // Enable Timer with interrupt (Alarm Enable)
|
timerAlarmEnable(timer); // Enable Timer with interrupt (Alarm Enable)
|
||||||
}
|
}
|
||||||
}
|
} */
|
||||||
|
|
||||||
float getTemperature()
|
float getTemperature()
|
||||||
{
|
{
|
||||||
|
@ -124,7 +124,7 @@ void setup()
|
||||||
mac[0], mac[1], mac[2],
|
mac[0], mac[1], mac[2],
|
||||||
mac[3], mac[4], mac[5]);
|
mac[3], mac[4], mac[5]);
|
||||||
|
|
||||||
esp_read_mac(mac, ESP_MAC_WIFI_STA); //ESP_MAC_BASE
|
esp_read_mac(mac, ESP_MAC_WIFI_STA); // ESP_MAC_BASE
|
||||||
Serial.printf("%02x:%02x:%02x:%02x:%02x:%02x ESP MAC BASE\n",
|
Serial.printf("%02x:%02x:%02x:%02x:%02x:%02x ESP MAC BASE\n",
|
||||||
mac[0], mac[1], mac[2],
|
mac[0], mac[1], mac[2],
|
||||||
mac[3], mac[4], mac[5]);
|
mac[3], mac[4], mac[5]);
|
||||||
|
@ -139,14 +139,14 @@ void setup()
|
||||||
pinMode(PIN_BUTTON, INPUT_PULLUP);
|
pinMode(PIN_BUTTON, INPUT_PULLUP);
|
||||||
if (digitalRead(PIN_BUTTON) == LOW)
|
if (digitalRead(PIN_BUTTON) == LOW)
|
||||||
{
|
{
|
||||||
ledBlink(100);
|
// ledBlink(100);
|
||||||
unsigned long startTime = millis();
|
unsigned long startTime = millis();
|
||||||
while (digitalRead(PIN_BUTTON) == LOW && (millis() - startTime <= 3000))
|
while (digitalRead(PIN_BUTTON) == LOW && (millis() - startTime <= 3000))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
if (digitalRead(PIN_BUTTON) == LOW)
|
if (digitalRead(PIN_BUTTON) == LOW)
|
||||||
{
|
{
|
||||||
ledBlink(0);
|
// ledBlink(0);
|
||||||
Serial.println("Reset config");
|
Serial.println("Reset config");
|
||||||
config.begin("dmx", false);
|
config.begin("dmx", false);
|
||||||
config.clear();
|
config.clear();
|
||||||
|
@ -155,7 +155,7 @@ void setup()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ledBlink(500);
|
// ledBlink(500);
|
||||||
|
|
||||||
// wait for serial monitor
|
// wait for serial monitor
|
||||||
delay(5000);
|
delay(5000);
|
||||||
|
@ -294,9 +294,9 @@ void setup()
|
||||||
// Initialize DMX ports
|
// Initialize DMX ports
|
||||||
Serial.println("Initialize DMX...");
|
Serial.println("Initialize DMX...");
|
||||||
|
|
||||||
#ifdef CONFIG_IDF_TARGET_ESP32S2
|
#ifdef CONFIG_IDF_TARGET_ESP32S2
|
||||||
//dmx1.init(21, 33, Serial0);
|
// dmx1.init(21, 33, Serial0);
|
||||||
//dmx2.init(17, 18, Serial1);
|
// dmx2.init(17, 18, Serial1);
|
||||||
|
|
||||||
Serial.print("DMX driver 1 installed: ");
|
Serial.print("DMX driver 1 installed: ");
|
||||||
Serial.println(dmx_driver_is_installed(dmx1));
|
Serial.println(dmx_driver_is_installed(dmx1));
|
||||||
|
@ -304,7 +304,6 @@ void setup()
|
||||||
Serial.print("DMX driver 2 installed: ");
|
Serial.print("DMX driver 2 installed: ");
|
||||||
Serial.println(dmx_driver_is_installed(dmx2));
|
Serial.println(dmx_driver_is_installed(dmx2));
|
||||||
|
|
||||||
|
|
||||||
dmx_config_t dmx_config = DMX_CONFIG_DEFAULT;
|
dmx_config_t dmx_config = DMX_CONFIG_DEFAULT;
|
||||||
|
|
||||||
dmx_personality_t personalities[] = {};
|
dmx_personality_t personalities[] = {};
|
||||||
|
@ -332,14 +331,13 @@ void setup()
|
||||||
|
|
||||||
// TX/RX Pins und Serial0/Serial1 ausgeben
|
// TX/RX Pins und Serial0/Serial1 ausgeben
|
||||||
|
|
||||||
|
|
||||||
/* Now set the DMX hardware pins to the pins that we want to use and setup
|
/* Now set the DMX hardware pins to the pins that we want to use and setup
|
||||||
will be complete! */
|
will be complete! */
|
||||||
|
|
||||||
#else
|
#else
|
||||||
dmx1.init(21, 33, Serial1);
|
dmx1.init(21, 33, Serial1);
|
||||||
dmx2.init(17, 18, Serial2);
|
dmx2.init(17, 18, Serial2);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Initialize Art-Net
|
// Initialize Art-Net
|
||||||
Serial.println("Initialize Art-Net...");
|
Serial.println("Initialize Art-Net...");
|
||||||
|
@ -353,8 +351,7 @@ void setup()
|
||||||
{
|
{
|
||||||
dmx_write_offset(dmx1, 1, data, size);
|
dmx_write_offset(dmx1, 1, data, size);
|
||||||
dmx_send(dmx1);
|
dmx_send(dmx1);
|
||||||
dmx_wait_sent(dmx1, DMX_TIMEOUT_TICK);
|
dmx_wait_sent(dmx1, DMX_TIMEOUT_TICK); });
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (direction2 == Output)
|
if (direction2 == Output)
|
||||||
|
@ -364,8 +361,7 @@ void setup()
|
||||||
{
|
{
|
||||||
dmx_write_offset(dmx2, 1, data, size);
|
dmx_write_offset(dmx2, 1, data, size);
|
||||||
dmx_send(dmx2);
|
dmx_send(dmx2);
|
||||||
dmx_wait_sent(dmx2, DMX_TIMEOUT_TICK);
|
dmx_wait_sent(dmx2, DMX_TIMEOUT_TICK); });
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// if Artnet packet comes, this function is called to every universe
|
// if Artnet packet comes, this function is called to every universe
|
||||||
|
@ -410,8 +406,7 @@ void setup()
|
||||||
// scan networks and cache them
|
// scan networks and cache them
|
||||||
WiFi.scanNetworks(true);
|
WiFi.scanNetworks(true);
|
||||||
|
|
||||||
ledBlink(0);
|
// ledBlink(0);
|
||||||
|
|
||||||
|
|
||||||
// Internal temperature RP2040
|
// Internal temperature RP2040
|
||||||
/*float tempC = analogReadTemp(); // Get internal temperature
|
/*float tempC = analogReadTemp(); // Get internal temperature
|
||||||
|
@ -438,7 +433,6 @@ void loop()
|
||||||
// check if artnet packet has come and execute callback
|
// check if artnet packet has come and execute callback
|
||||||
artnet.parse();
|
artnet.parse();
|
||||||
|
|
||||||
|
|
||||||
/* We need a place to store information about the DMX packets we receive. We
|
/* 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. */
|
will use a dmx_packet_t to store that packet information. */
|
||||||
dmx_packet_t dmx1_packet;
|
dmx_packet_t dmx1_packet;
|
||||||
|
@ -448,17 +442,63 @@ void loop()
|
||||||
officially times out. That amount of time is converted into ESP32 clock
|
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
|
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. */
|
amount of time to receive data, this if statement will evaluate to false. */
|
||||||
if (direction1 == Input) {
|
if (direction1 == Input && dmx_receive(dmx1, &dmx1_packet, 0))
|
||||||
//Serial.println("Recv DMX1");
|
{
|
||||||
|
// Serial.println("Recv DMX1");
|
||||||
/* If this code gets called, it means we've received DMX data! */
|
/* If this code gets called, it means we've received DMX data! */
|
||||||
|
|
||||||
dmx_read_offset(dmx1, 1, dmx1_data, 512);
|
dmx_read_offset(dmx1, 1, dmx1_data, 512);
|
||||||
artnet.sendArtDmx(broadcastIp, universe1, 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (direction2 == Input && dmx_receive(dmx2, &dmx2_packet, DMX_TIMEOUT_TICK)) {
|
/* Don't forget we need to actually read the DMX data into our buffer so
|
||||||
//Serial.println("Recv DMX2");
|
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, 0))
|
||||||
|
{
|
||||||
|
// Serial.println("Recv DMX2");
|
||||||
/* If this code gets called, it means we've received DMX data! */
|
/* If this code gets called, it means we've received DMX data! */
|
||||||
|
|
||||||
dmx_read_offset(dmx2, 1, dmx2_data, 512);
|
dmx_read_offset(dmx2, 1, dmx2_data, 512);
|
||||||
|
@ -470,9 +510,11 @@ void loop()
|
||||||
unsigned long now = millis();
|
unsigned long now = millis();
|
||||||
|
|
||||||
/* We should check to make sure that there weren't any DMX errors. */
|
/* We should check to make sure that there weren't any DMX errors. */
|
||||||
if (!dmx2_packet.err) {
|
if (!dmx2_packet.err)
|
||||||
|
{
|
||||||
/* If this is the first DMX data we've received, lets log it! */
|
/* If this is the first DMX data we've received, lets log it! */
|
||||||
if (!dmx2_IsConnected) {
|
if (!dmx2_IsConnected)
|
||||||
|
{
|
||||||
Serial.println("DMX2 in is connected!");
|
Serial.println("DMX2 in is connected!");
|
||||||
dmx2_IsConnected = true;
|
dmx2_IsConnected = true;
|
||||||
}
|
}
|
||||||
|
@ -483,24 +525,29 @@ void loop()
|
||||||
/*dmx_read_offset(dmx2, 1, dmx2_data, dmx2_packet.size);
|
/*dmx_read_offset(dmx2, 1, dmx2_data, dmx2_packet.size);
|
||||||
artnet.sendArtDmx(broadcastIp, universe2, dmx2_data, 512);*/
|
artnet.sendArtDmx(broadcastIp, universe2, dmx2_data, 512);*/
|
||||||
|
|
||||||
if (now - dmx2_lastUpdate > 1000) {
|
if (now - dmx2_lastUpdate > 1000)
|
||||||
|
{
|
||||||
/* Print the received start code - it's usually 0. */
|
/* Print the received start code - it's usually 0. */
|
||||||
//Serial.printf("Start code is 0x%02X and slot 1 is 0x%02X\n", dmx2_data[0], dmx2_data[1]);
|
// Serial.printf("Start code is 0x%02X and slot 1 is 0x%02X\n", dmx2_data[0], dmx2_data[1]);
|
||||||
dmx2_lastUpdate = now;
|
dmx2_lastUpdate = now;
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
/* Oops! A DMX error occurred! Don't worry, this can happen when you first
|
/* 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
|
connect or disconnect your DMX devices. If you are consistently getting
|
||||||
DMX errors, then something may have gone wrong with your code or
|
DMX errors, then something may have gone wrong with your code or
|
||||||
something is seriously wrong with your DMX transmitter. */
|
something is seriously wrong with your DMX transmitter. */
|
||||||
Serial.println("A DMX 2 error occurred.");
|
Serial.println("A DMX 2 error occurred.");
|
||||||
}
|
}
|
||||||
} else if (dmx2_IsConnected) {
|
}
|
||||||
|
else if (dmx2_IsConnected)
|
||||||
|
{
|
||||||
/* If DMX times out after having been connected, it likely means that the
|
/* 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
|
DMX cable was unplugged. When that happens in this example sketch, we'll
|
||||||
uninstall the DMX driver. */
|
uninstall the DMX driver. */
|
||||||
Serial.println("DMX 2 was disconnected.");
|
Serial.println("DMX 2 was disconnected.");
|
||||||
dmx2_IsConnected = false;
|
dmx2_IsConnected = false;
|
||||||
//dmx_driver_delete(dmx2);
|
// dmx_driver_delete(dmx2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue