From 9c7f43f3e60950e2268e19753a6bc39aeb00b879 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anton=20Luka=20=C5=A0ijanec?= Date: Mon, 31 Oct 2022 17:59:40 +0100 Subject: revert changes from impure_wilhelmina, added dnbk.qxw, dmx2artnet in sw --- sw/dmx2artnet/README.txt | 19 +++++++++++ sw/dmx2artnet/src/main.cpp | 85 ++++++++++++++++++++++++++++++++++++---------- 2 files changed, 87 insertions(+), 17 deletions(-) create mode 100644 sw/dmx2artnet/README.txt (limited to 'sw') diff --git a/sw/dmx2artnet/README.txt b/sw/dmx2artnet/README.txt new file mode 100644 index 0000000..5aebdef --- /dev/null +++ b/sw/dmx2artnet/README.txt @@ -0,0 +1,19 @@ +nodemcu: connect D4 to TX + D7 to RXD (the pin that transmits, weird, right?) of UART-RS485 + G to GND of UART-RS485 + 3V to VCC of UART-RS485 +plug in nodemcu to computer via usb +pio run --target upload + +SLIP: +slattach -vdp slip -s 115200 /dev/ttyUSB0 +ifconfig sl0 up +ip addr add dev sl0 2.0.0.1/8 +use artnet on 2.0.0.1 as input in qlc+, set in artnet config universe to 0, instead of default 1 + +WIFI: +add #define DO_WIFI to source and change ssid to connect to in setup() +use artnet on wifi iface as input in qlc+, set in artnet config universe to 0, instead of default 1 + +hacks: +connect D6 to GND to enable flash suppression hack - flash (dmx 255) will be replaced with the last known value instead diff --git a/sw/dmx2artnet/src/main.cpp b/sw/dmx2artnet/src/main.cpp index 2da28ae..21ddd18 100644 --- a/sw/dmx2artnet/src/main.cpp +++ b/sw/dmx2artnet/src/main.cpp @@ -1,12 +1,16 @@ +#define DO_SLIP 1 +#define DO_WIFI 1 #include #include +#ifdef DO_WIFI #include #include +WiFiUDP u; +#endif #define END 0xc0 #define ESC 0xdb #define ESC_END 0xdc #define ESC_ESC 0xdd -WiFiUDP u; struct artnet { char name[8]; // Art-Net\0 char opcode[2]; // 0x5000 in LE: { 0x00, 0x50 } @@ -63,18 +67,47 @@ struct artnet_over_slip { struct artnet artnet; } __attribute__((packed)); struct artnet_over_slip p; -unsigned w = 0; unsigned long č = 0; -unsigned char t; + +volatile unsigned w = 0; +/* volatile unsigned long last_fall = 0; +volatile unsigned long mark_after_break = 0; +volatile unsigned char led = 0; +// volatile unsigned send = 0; +IRAM_ATTR void isr () { + if (digitalRead(D6) == LOW) { + if (mark_after_break) { + // mark_after_break = 0; + // send = w-1; + // w = 0; + mark_after_break = w = 0; + +#ifndef DO_SLIP + digitalWrite(D4, led++ % 2); +#endif + } + last_fall = micros(); + } else { + if (micros() - last_fall > 87) + mark_after_break++; + } +} */ + void setup () { - pinMode(D0, OUTPUT); + pinMode(D6, INPUT_PULLUP); Serial.begin(250000, SERIAL_8N2); Serial.swap(); +#ifdef DO_SLIP Serial1.begin(/* MONITOR_SPEED */ 115200); +#else + pinMode(D4, OUTPUT); +#endif +#ifdef DO_WIFI // WiFi.softAP("dmx2artnet", NULL, 11, 0, 8); - WiFi.begin("OpenWrt", NULL); - // WiFi.begin("Hell Patrol", WIFI_PW); + // WiFi.begin("OpenWrt", NULL); + WiFi.begin("Hell Patrol", WIFI_PW); u.begin(6454); +#endif sprintf(p.artnet.name, "Art-Net"); p.artnet.opcode[0] = 0x00; p.artnet.opcode[1] = 0x50; @@ -84,7 +117,10 @@ void setup () { p.artnet.physical = 0; p.artnet.sub_uni = 0; p.artnet.net = 0; - p.udp.srcport = p.udp.dstport = htons(6454); + if (digitalRead(D6) == LOW) + p.udp.srcport = p.udp.dstport = htons(6455); + else + p.udp.srcport = p.udp.dstport = htons(6454); p.udp.checksum = 0; p.ip.headlen = HEADLENOR | 5; p.ip.srvtype = 0; @@ -96,53 +132,67 @@ void setup () { p.ip.src[2] = (ESP.getChipId() & 0xff00) >> 8; p.ip.src[3] = (ESP.getChipId() & 0xff); memset(p.ip.dst, 255, 4); + // attachInterrupt(digitalPinToInterrupt(D6), isr, CHANGE); } -char slip_buf[sizeof p * 2 + 1]; unsigned char recording[sizeof p.artnet.data * 2]; +#ifdef DO_SLIP +char slip_buf[sizeof p * 2 + 1]; unsigned slip_off = 0; unsigned slip_len = 0; +#endif #define SLIP Serial1 void loop () { +#ifdef DO_SLIP unsigned avail = SLIP.availableForWrite(); if (slip_off < slip_len && avail) { if (avail > slip_len-slip_off) avail = slip_len-slip_off; slip_off += SLIP.write(slip_buf+slip_off, avail); } +#endif if (Serial.available()) { - č = millis(); + č = micros(); if (w < sizeof p.artnet.data * 2) recording[w++] = Serial.read(); else Serial.read(); } - if (č + 1 < millis() && w) { - unsigned T; - for (T = 0; T < w; T++) // prvi kanal ne sme biti 0, tako zaznamo začetek paketa + if (č + 200 < micros() && w) { + // if (send) { + unsigned t = 0; + if (w == sizeof p.artnet.data) // če smo break zaznali kot bajt, ga odstranimo + t = 1; + unsigned l = w-t-1; // en je tip + /* for (T = 0; T < w; T++) // prvi kanal ne sme biti 0, tako zaznamo začetek paketa if (recording[T] > 1) - break; - memcpy(p.artnet.data, recording + T, sizeof p.artnet.data); - unsigned l = w-T; + break; */ + /* for (unsigned i = 0; i < sizeof p.artnet.data; i++) // takes too long??? + if (!(hack_for_midi_flash && recording[t + 1] == 255)) + p.artnet.data[i] = recording[t + 1]; */ + memcpy(p.artnet.data, recording + t + 1, sizeof p.artnet.data); if (l > sizeof p.artnet.data) l = sizeof p.artnet.data; /* l++; while (--l) if (p.data[l-1]) break; */ - if (!t) { + if (!recording[t]) { p.artnet.length_hi = l / 256; p.artnet.length_lo = l % 256; +#ifdef DO_WIFI IPAddress b(255, 255, 255, 255); u.beginPacket(b, 6454); u.write((unsigned char *) &p.artnet, sizeof p.artnet - sizeof p.artnet.data + l); u.endPacket(); +#endif +#ifdef DO_SLIP if (slip_off >= slip_len) { p.ip.identifier = htons(millis()); p.udp.length = htons(sizeof p.udp + sizeof p.artnet - sizeof p.artnet.data + l); p.ip.length = htons(sizeof p - sizeof p.artnet.data + l); p.ip.checksum = 0; uint32_t sum = 0; - for (unsigned i = 0; i < sizeof p/2+sizeof p%2; i++) + for (unsigned i = 0; i < sizeof p.ip/2+sizeof p.ip%2; i++) sum += ntohs(((uint16_t *) &p)[i]); while (sum >> 16) sum = (sum >> 16) + sum % 65536; @@ -167,6 +217,7 @@ void loop () { } slip_buf[slip_len++] = END; } +#endif } /* Serial1.println("dolžina podatkov " + String(w-T) + ", tip: " + String(t)); -- cgit v1.2.3