mirror of
https://github.com/HendrikRauh/dmx-interface.git
synced 2025-07-05 21:58:53 +00:00
Merge pull request #6 from HendrikRauh/DMX-22-Modify-ESPDMX
Dmx 22 modify espdmx
This commit is contained in:
commit
06fbe3280a
3 changed files with 36 additions and 34 deletions
|
@ -5,7 +5,7 @@
|
||||||
// Copyright (C) 2015 Rick <ricardogg95@gmail.com>
|
// Copyright (C) 2015 Rick <ricardogg95@gmail.com>
|
||||||
// This work is licensed under a GNU style license.
|
// This work is licensed under a GNU style license.
|
||||||
//
|
//
|
||||||
// Last change: Marcel Seerig <https://github.com/mseerig>
|
// Last change: Hendrik Rauh <https://github.com/hendrikrauh>
|
||||||
//
|
//
|
||||||
// Documentation and samples are available at https://github.com/Rickgg/ESP-Dmx
|
// Documentation and samples are available at https://github.com/Rickgg/ESP-Dmx
|
||||||
// - - - - -
|
// - - - - -
|
||||||
|
@ -14,26 +14,17 @@
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include "ESPDMX.h"
|
#include "ESPDMX.h"
|
||||||
|
|
||||||
#define DMXSPEED 250000
|
|
||||||
#define DMXFORMAT SERIAL_8N2
|
|
||||||
#define BREAKSPEED 83333
|
|
||||||
#define BREAKFORMAT SERIAL_8N1
|
|
||||||
#define SERIALPORT Serial0
|
|
||||||
#define DMXCHANNELS 512
|
|
||||||
|
|
||||||
bool dmxStarted = false;
|
|
||||||
int sendPin = 18;
|
|
||||||
int receivePin = -1;
|
|
||||||
|
|
||||||
// DMX value array and size. Entry 0 will hold startbyte, so we need 512+1 elements
|
// DMX value array and size. Entry 0 will hold startbyte, so we need 512+1 elements
|
||||||
uint8_t dmxDataStore[DMXCHANNELS + 1] = {};
|
// std::vector<uint8_t[DMXCHANNELS + 1]> dmxDataStores(MAX_IDS);
|
||||||
|
// uint8_t dmxDataStores[MAX_IDS][DMXCHANNELS + 1];
|
||||||
|
|
||||||
// Set up the DMX-Protocol
|
// Set up the DMX-Protocol
|
||||||
void DMXESPSerial::init()
|
void DMXESPSerial::init(int pinSend, int pinRecv)
|
||||||
{
|
{
|
||||||
SERIALPORT.begin(DMXSPEED, DMXFORMAT, receivePin, sendPin);
|
sendPin = pinSend;
|
||||||
|
recvPin = pinRecv;
|
||||||
|
SERIALPORT.begin(DMXSPEED, DMXFORMAT, recvPin, sendPin);
|
||||||
pinMode(sendPin, OUTPUT);
|
pinMode(sendPin, OUTPUT);
|
||||||
dmxStarted = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Function to read DMX data
|
// Function to read DMX data
|
||||||
|
@ -52,6 +43,7 @@ uint8_t DMXESPSerial::read(int channel)
|
||||||
// Function to send DMX data
|
// Function to send DMX data
|
||||||
void DMXESPSerial::write(int channel, uint8_t value)
|
void DMXESPSerial::write(int channel, uint8_t value)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (dmxStarted == false)
|
if (dmxStarted == false)
|
||||||
init();
|
init();
|
||||||
|
|
||||||
|
@ -70,25 +62,21 @@ void DMXESPSerial::write(int channel, uint8_t value)
|
||||||
void DMXESPSerial::end()
|
void DMXESPSerial::end()
|
||||||
{
|
{
|
||||||
SERIALPORT.end();
|
SERIALPORT.end();
|
||||||
dmxStarted = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Function to update the DMX bus
|
// Function to update the DMX bus
|
||||||
void DMXESPSerial::update()
|
void DMXESPSerial::update()
|
||||||
{
|
{
|
||||||
if (dmxStarted == false)
|
|
||||||
init();
|
|
||||||
|
|
||||||
// Send break
|
// Send break
|
||||||
digitalWrite(sendPin, HIGH);
|
digitalWrite(sendPin, HIGH);
|
||||||
SERIALPORT.begin(BREAKSPEED, BREAKFORMAT, receivePin, sendPin);
|
SERIALPORT.begin(BREAKSPEED, BREAKFORMAT, recvPin, sendPin);
|
||||||
SERIALPORT.write(0);
|
SERIALPORT.write(0);
|
||||||
SERIALPORT.flush();
|
SERIALPORT.flush();
|
||||||
delay(1);
|
delay(1);
|
||||||
SERIALPORT.end();
|
SERIALPORT.end();
|
||||||
|
|
||||||
// send data
|
// send data
|
||||||
SERIALPORT.begin(DMXSPEED, DMXFORMAT, receivePin, sendPin);
|
SERIALPORT.begin(DMXSPEED, DMXFORMAT, recvPin, sendPin);
|
||||||
digitalWrite(sendPin, LOW);
|
digitalWrite(sendPin, LOW);
|
||||||
SERIALPORT.write(dmxDataStore, DMXCHANNELS);
|
SERIALPORT.write(dmxDataStore, DMXCHANNELS);
|
||||||
SERIALPORT.flush();
|
SERIALPORT.flush();
|
||||||
|
|
29
src/ESPDMX.h
29
src/ESPDMX.h
|
@ -5,25 +5,36 @@
|
||||||
// Copyright (C) 2015 Rick <ricardogg95@gmail.com>
|
// Copyright (C) 2015 Rick <ricardogg95@gmail.com>
|
||||||
// This work is licensed under a GNU style license.
|
// This work is licensed under a GNU style license.
|
||||||
//
|
//
|
||||||
// Last change: Marcel Seerig <https://github.com/mseerig>
|
// Last change: Hendrik Rauh <https://github.com/Hendrik Rauh>
|
||||||
//
|
//
|
||||||
// Documentation and samples are available at https://github.com/Rickgg/ESP-Dmx
|
// Documentation and samples are available at https://github.com/Rickgg/ESP-Dmx
|
||||||
// - - - - -
|
// - - - - -
|
||||||
|
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
|
|
||||||
|
|
||||||
#ifndef ESPDMX_h
|
#ifndef ESPDMX_h
|
||||||
#define ESPDMX_h
|
#define ESPDMX_h
|
||||||
|
|
||||||
// ---- Methods ----
|
#define DMXSPEED 250000
|
||||||
|
#define DMXFORMAT SERIAL_8N2
|
||||||
|
#define BREAKSPEED 83333
|
||||||
|
#define BREAKFORMAT SERIAL_8N1
|
||||||
|
#define SERIALPORT Serial0
|
||||||
|
#define DMXCHANNELS 512
|
||||||
|
|
||||||
class DMXESPSerial {
|
class DMXESPSerial
|
||||||
public:
|
{
|
||||||
void init();
|
public:
|
||||||
uint8_t read(int Channel);
|
int sendPin;
|
||||||
void write(int channel, uint8_t value);void update();
|
int recvPin;
|
||||||
void end();
|
bool started;
|
||||||
|
uint8_t dmxDataStore[DMXCHANNELS + 1];
|
||||||
|
|
||||||
|
void init(int pinSend, int pinRecv);
|
||||||
|
uint8_t read(int Channel);
|
||||||
|
void write(int channel, uint8_t value);
|
||||||
|
void update();
|
||||||
|
void end();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -5,6 +5,9 @@
|
||||||
#include <SPIFFS.h>
|
#include <SPIFFS.h>
|
||||||
#include "routes/config.h"
|
#include "routes/config.h"
|
||||||
|
|
||||||
|
DMXESPSerial dmx1;
|
||||||
|
DMXESPSerial dmx2;
|
||||||
|
|
||||||
AsyncWebServer server(80);
|
AsyncWebServer server(80);
|
||||||
|
|
||||||
ArtnetWiFi artnet;
|
ArtnetWiFi artnet;
|
||||||
|
@ -52,17 +55,17 @@ void setup()
|
||||||
artnet.begin();
|
artnet.begin();
|
||||||
|
|
||||||
// Initialize DMX ports
|
// Initialize DMX ports
|
||||||
dmx.init();
|
dmx1.init(19, -1);
|
||||||
|
|
||||||
// if Artnet packet comes to this universe, this function is called
|
// if Artnet packet comes to this universe, this function is called
|
||||||
artnet.subscribeArtDmxUniverse(universe1, [&](const uint8_t *data, uint16_t size, const ArtDmxMetadata &metadata, const ArtNetRemoteInfo &remote)
|
artnet.subscribeArtDmxUniverse(universe1, [&](const uint8_t *data, uint16_t size, const ArtDmxMetadata &metadata, const ArtNetRemoteInfo &remote)
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < size; ++i)
|
for (size_t i = 0; i < size; ++i)
|
||||||
{
|
{
|
||||||
dmx.write((i + 1), data[i]);
|
dmx1.write((i + 1), data[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
dmx.update(); });
|
dmx1.update(); });
|
||||||
|
|
||||||
// if Artnet packet comes, this function is called to every universe
|
// if Artnet packet comes, this function is called to every universe
|
||||||
artnet.subscribeArtDmx([&](const uint8_t *data, uint16_t size, const ArtDmxMetadata &metadata, const ArtNetRemoteInfo &remote) {});
|
artnet.subscribeArtDmx([&](const uint8_t *data, uint16_t size, const ArtDmxMetadata &metadata, const ArtNetRemoteInfo &remote) {});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue