mirror of
https://github.com/HendrikRauh/dmx-interface.git
synced 2025-05-19 10:32:56 +00:00
DMX-22 started modification of lib
This commit is contained in:
parent
d8f1bf9111
commit
4157c8a21d
3 changed files with 46 additions and 38 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
|
||||||
// - - - - -
|
// - - - - -
|
||||||
|
@ -13,6 +13,9 @@
|
||||||
/* ----- LIBRARIES ----- */
|
/* ----- LIBRARIES ----- */
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include "ESPDMX.h"
|
#include "ESPDMX.h"
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#define MAX_IDS 3
|
||||||
|
|
||||||
#define DMXSPEED 250000
|
#define DMXSPEED 250000
|
||||||
#define DMXFORMAT SERIAL_8N2
|
#define DMXFORMAT SERIAL_8N2
|
||||||
|
@ -21,41 +24,45 @@
|
||||||
#define SERIALPORT Serial0
|
#define SERIALPORT Serial0
|
||||||
#define DMXCHANNELS 512
|
#define DMXCHANNELS 512
|
||||||
|
|
||||||
bool dmxStarted = false;
|
int sendPin[] = {};
|
||||||
int sendPin = 18;
|
int recvPin[] = {};
|
||||||
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];
|
||||||
|
|
||||||
|
struct dmxPorts
|
||||||
|
{
|
||||||
|
uint8_t id;
|
||||||
|
int sendPin;
|
||||||
|
int recvPin;
|
||||||
|
bool started;
|
||||||
|
uint8_t dmxDataStore[DMXCHANNELS + 1];
|
||||||
|
};
|
||||||
|
|
||||||
// Set up the DMX-Protocol
|
// Set up the DMX-Protocol
|
||||||
void DMXESPSerial::init()
|
void DMXESPSerial::init(int id, int pinSend, int pinRecv)
|
||||||
{
|
{
|
||||||
SERIALPORT.begin(DMXSPEED, DMXFORMAT, receivePin, sendPin);
|
sendPin[id] = pinSend;
|
||||||
pinMode(sendPin, OUTPUT);
|
recvPin[id] = pinRecv;
|
||||||
dmxStarted = true;
|
SERIALPORT.begin(DMXSPEED, DMXFORMAT, recvPin[id], sendPin[id]);
|
||||||
|
pinMode(sendPin[id], OUTPUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Function to read DMX data
|
// Function to read DMX data
|
||||||
uint8_t DMXESPSerial::read(int Channel)
|
uint8_t DMXESPSerial::read(int id, int Channel)
|
||||||
{
|
{
|
||||||
if (dmxStarted == false)
|
|
||||||
init();
|
|
||||||
|
|
||||||
if (Channel < 1)
|
if (Channel < 1)
|
||||||
Channel = 1;
|
Channel = 1;
|
||||||
if (Channel > DMXCHANNELS)
|
if (Channel > DMXCHANNELS)
|
||||||
Channel = DMXCHANNELS;
|
Channel = DMXCHANNELS;
|
||||||
return (dmxDataStore[Channel]);
|
return (dmxDataStores[id][Channel]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Function to send DMX data
|
// Function to send DMX data
|
||||||
void DMXESPSerial::write(int Channel, uint8_t value)
|
void DMXESPSerial::write(int id, int Channel, uint8_t value)
|
||||||
{
|
{
|
||||||
if (dmxStarted == false)
|
s if (Channel < 1)
|
||||||
init();
|
|
||||||
|
|
||||||
if (Channel < 1)
|
|
||||||
Channel = 1;
|
Channel = 1;
|
||||||
if (Channel > DMXCHANNELS)
|
if (Channel > DMXCHANNELS)
|
||||||
Channel = DMXCHANNELS;
|
Channel = DMXCHANNELS;
|
||||||
|
@ -64,33 +71,29 @@ void DMXESPSerial::write(int Channel, uint8_t value)
|
||||||
if (value > 255)
|
if (value > 255)
|
||||||
value = 255;
|
value = 255;
|
||||||
|
|
||||||
dmxDataStore[Channel] = value;
|
dmxDataStores[id][Channel] = 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(int id)
|
||||||
{
|
{
|
||||||
if (dmxStarted == false)
|
|
||||||
init();
|
|
||||||
|
|
||||||
// Send break
|
// Send break
|
||||||
digitalWrite(sendPin, HIGH);
|
digitalWrite(sendPin[id], HIGH);
|
||||||
SERIALPORT.begin(BREAKSPEED, BREAKFORMAT, receivePin, sendPin);
|
SERIALPORT.begin(BREAKSPEED, BREAKFORMAT, recvPin[id], sendPin[id]);
|
||||||
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[id], sendPin[id]);
|
||||||
digitalWrite(sendPin, LOW);
|
digitalWrite(sendPin[id], LOW);
|
||||||
SERIALPORT.write(dmxDataStore, DMXCHANNELS);
|
SERIALPORT.write(dmxDataStores[id], DMXCHANNELS);
|
||||||
SERIALPORT.flush();
|
SERIALPORT.flush();
|
||||||
delay(1);
|
delay(1);
|
||||||
SERIALPORT.end();
|
SERIALPORT.end();
|
||||||
|
|
|
@ -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/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
|
||||||
// - - - - -
|
// - - - - -
|
||||||
|
@ -20,10 +20,11 @@
|
||||||
|
|
||||||
class DMXESPSerial {
|
class DMXESPSerial {
|
||||||
public:
|
public:
|
||||||
void init();
|
void init(int id, int pinSend, int pinRecv);
|
||||||
uint8_t read(int Channel);
|
uint8_t read(int id, int Channel);
|
||||||
void write(int channel, uint8_t value);void update();
|
void write(int id, int channel, uint8_t value);void update();
|
||||||
void end();
|
void end();
|
||||||
|
void update(int id);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
12
src/main.cpp
12
src/main.cpp
|
@ -8,7 +8,9 @@
|
||||||
#include <Preferences.h>
|
#include <Preferences.h>
|
||||||
|
|
||||||
Preferences config;
|
Preferences config;
|
||||||
DMXESPSerial dmx;
|
|
||||||
|
DMXESPSerial dmx1;
|
||||||
|
DMXESPSerial dmx2;
|
||||||
|
|
||||||
AsyncWebServer server(80);
|
AsyncWebServer server(80);
|
||||||
|
|
||||||
|
@ -16,6 +18,8 @@ ArtnetWiFi artnet;
|
||||||
const uint16_t size = 512;
|
const uint16_t size = 512;
|
||||||
uint8_t data[size];
|
uint8_t data[size];
|
||||||
|
|
||||||
|
int selectedId = 0;
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
|
@ -51,17 +55,17 @@ void setup()
|
||||||
artnet.begin();
|
artnet.begin();
|
||||||
|
|
||||||
// Initialize DMX ports
|
// Initialize DMX ports
|
||||||
dmx.init();
|
dmx.init(0, 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(universe, [&](const uint8_t *data, uint16_t size, const ArtDmxMetadata &metadata, const ArtNetRemoteInfo &remote)
|
artnet.subscribeArtDmxUniverse(universe, [&](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]);
|
dmx.write(selectedId, (i + 1), data[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
dmx.update(); });
|
dmx.update(selectedId); });
|
||||||
|
|
||||||
// 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
Reference in a new issue