finished modification of lob

This commit is contained in:
RaffaelW 2024-11-02 20:18:06 +01:00
parent 4157c8a21d
commit ab377defb5
3 changed files with 38 additions and 52 deletions

View file

@ -13,56 +13,34 @@
/* ----- LIBRARIES ----- */ /* ----- LIBRARIES ----- */
#include <Arduino.h> #include <Arduino.h>
#include "ESPDMX.h" #include "ESPDMX.h"
#include <vector>
#define MAX_IDS 3
#define DMXSPEED 250000
#define DMXFORMAT SERIAL_8N2
#define BREAKSPEED 83333
#define BREAKFORMAT SERIAL_8N1
#define SERIALPORT Serial0
#define DMXCHANNELS 512
int sendPin[] = {};
int recvPin[] = {};
// 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
// std::vector<uint8_t[DMXCHANNELS + 1]> dmxDataStores(MAX_IDS); // std::vector<uint8_t[DMXCHANNELS + 1]> dmxDataStores(MAX_IDS);
// uint8_t dmxDataStores[MAX_IDS][DMXCHANNELS + 1]; // 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(int id, int pinSend, int pinRecv) void DMXESPSerial::init(int pinSend, int pinRecv)
{ {
sendPin[id] = pinSend; sendPin = pinSend;
recvPin[id] = pinRecv; recvPin = pinRecv;
SERIALPORT.begin(DMXSPEED, DMXFORMAT, recvPin[id], sendPin[id]); SERIALPORT.begin(DMXSPEED, DMXFORMAT, recvPin, sendPin);
pinMode(sendPin[id], OUTPUT); pinMode(sendPin, OUTPUT);
} }
// Function to read DMX data // Function to read DMX data
uint8_t DMXESPSerial::read(int id, int Channel) uint8_t DMXESPSerial::read(int Channel)
{ {
if (Channel < 1) if (Channel < 1)
Channel = 1; Channel = 1;
if (Channel > DMXCHANNELS) if (Channel > DMXCHANNELS)
Channel = DMXCHANNELS; Channel = DMXCHANNELS;
return (dmxDataStores[id][Channel]); return (dmxDataStore[Channel]);
} }
// Function to send DMX data // Function to send DMX data
void DMXESPSerial::write(int id, int Channel, uint8_t value) void DMXESPSerial::write(int Channel, uint8_t value)
{ {
s if (Channel < 1) if (Channel < 1)
Channel = 1; Channel = 1;
if (Channel > DMXCHANNELS) if (Channel > DMXCHANNELS)
Channel = DMXCHANNELS; Channel = DMXCHANNELS;
@ -71,7 +49,7 @@ void DMXESPSerial::write(int id, int Channel, uint8_t value)
if (value > 255) if (value > 255)
value = 255; value = 255;
dmxDataStores[id][Channel] = value; dmxDataStore[Channel] = value;
} }
void DMXESPSerial::end() void DMXESPSerial::end()
@ -80,20 +58,20 @@ void DMXESPSerial::end()
} }
// Function to update the DMX bus // Function to update the DMX bus
void DMXESPSerial::update(int id) void DMXESPSerial::update()
{ {
// Send break // Send break
digitalWrite(sendPin[id], HIGH); digitalWrite(sendPin, HIGH);
SERIALPORT.begin(BREAKSPEED, BREAKFORMAT, recvPin[id], sendPin[id]); 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, recvPin[id], sendPin[id]); SERIALPORT.begin(DMXSPEED, DMXFORMAT, recvPin, sendPin);
digitalWrite(sendPin[id], LOW); digitalWrite(sendPin, LOW);
SERIALPORT.write(dmxDataStores[id], DMXCHANNELS); SERIALPORT.write(dmxDataStore, DMXCHANNELS);
SERIALPORT.flush(); SERIALPORT.flush();
delay(1); delay(1);
SERIALPORT.end(); SERIALPORT.end();

View file

@ -12,19 +12,29 @@
#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(int id, int pinSend, int pinRecv); public:
uint8_t read(int id, int Channel); int sendPin;
void write(int id, int channel, uint8_t value);void update(); int recvPin;
void end(); bool started;
void update(int id); 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

View file

@ -18,8 +18,6 @@ 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);
@ -55,17 +53,17 @@ void setup()
artnet.begin(); artnet.begin();
// Initialize DMX ports // Initialize DMX ports
dmx.init(0, 19, -1); 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(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(selectedId, (i + 1), data[i]); dmx1.write((i + 1), data[i]);
} }
dmx.update(selectedId); }); 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) {});