mirror of
https://github.com/HendrikRauh/dmx-interface.git
synced 2025-07-05 05:38:54 +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>
|
||||
// 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
|
||||
// - - - - -
|
||||
|
@ -14,26 +14,17 @@
|
|||
#include <Arduino.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
|
||||
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
|
||||
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);
|
||||
dmxStarted = true;
|
||||
}
|
||||
|
||||
// Function to read DMX data
|
||||
|
@ -52,6 +43,7 @@ uint8_t DMXESPSerial::read(int channel)
|
|||
// Function to send DMX data
|
||||
void DMXESPSerial::write(int channel, uint8_t value)
|
||||
{
|
||||
|
||||
if (dmxStarted == false)
|
||||
init();
|
||||
|
||||
|
@ -70,25 +62,21 @@ void DMXESPSerial::write(int channel, uint8_t value)
|
|||
void DMXESPSerial::end()
|
||||
{
|
||||
SERIALPORT.end();
|
||||
dmxStarted = false;
|
||||
}
|
||||
|
||||
// Function to update the DMX bus
|
||||
void DMXESPSerial::update()
|
||||
{
|
||||
if (dmxStarted == false)
|
||||
init();
|
||||
|
||||
// Send break
|
||||
digitalWrite(sendPin, HIGH);
|
||||
SERIALPORT.begin(BREAKSPEED, BREAKFORMAT, receivePin, sendPin);
|
||||
SERIALPORT.begin(BREAKSPEED, BREAKFORMAT, recvPin, sendPin);
|
||||
SERIALPORT.write(0);
|
||||
SERIALPORT.flush();
|
||||
delay(1);
|
||||
SERIALPORT.end();
|
||||
|
||||
// send data
|
||||
SERIALPORT.begin(DMXSPEED, DMXFORMAT, receivePin, sendPin);
|
||||
SERIALPORT.begin(DMXSPEED, DMXFORMAT, recvPin, sendPin);
|
||||
digitalWrite(sendPin, LOW);
|
||||
SERIALPORT.write(dmxDataStore, DMXCHANNELS);
|
||||
SERIALPORT.flush();
|
||||
|
|
29
src/ESPDMX.h
29
src/ESPDMX.h
|
@ -5,25 +5,36 @@
|
|||
// Copyright (C) 2015 Rick <ricardogg95@gmail.com>
|
||||
// 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
|
||||
// - - - - -
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
|
||||
#ifndef 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 {
|
||||
public:
|
||||
void init();
|
||||
uint8_t read(int Channel);
|
||||
void write(int channel, uint8_t value);void update();
|
||||
void end();
|
||||
class DMXESPSerial
|
||||
{
|
||||
public:
|
||||
int sendPin;
|
||||
int recvPin;
|
||||
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
|
||||
|
|
|
@ -5,6 +5,9 @@
|
|||
#include <SPIFFS.h>
|
||||
#include "routes/config.h"
|
||||
|
||||
DMXESPSerial dmx1;
|
||||
DMXESPSerial dmx2;
|
||||
|
||||
AsyncWebServer server(80);
|
||||
|
||||
ArtnetWiFi artnet;
|
||||
|
@ -52,17 +55,17 @@ void setup()
|
|||
artnet.begin();
|
||||
|
||||
// Initialize DMX ports
|
||||
dmx.init();
|
||||
dmx1.init(19, -1);
|
||||
|
||||
// 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)
|
||||
{
|
||||
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
|
||||
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