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 ----- */
#include <Arduino.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
// 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
void DMXESPSerial::init(int id, int pinSend, int pinRecv)
void DMXESPSerial::init(int pinSend, int pinRecv)
{
sendPin[id] = pinSend;
recvPin[id] = pinRecv;
SERIALPORT.begin(DMXSPEED, DMXFORMAT, recvPin[id], sendPin[id]);
pinMode(sendPin[id], OUTPUT);
sendPin = pinSend;
recvPin = pinRecv;
SERIALPORT.begin(DMXSPEED, DMXFORMAT, recvPin, sendPin);
pinMode(sendPin, OUTPUT);
}
// Function to read DMX data
uint8_t DMXESPSerial::read(int id, int Channel)
uint8_t DMXESPSerial::read(int Channel)
{
if (Channel < 1)
Channel = 1;
if (Channel > DMXCHANNELS)
Channel = DMXCHANNELS;
return (dmxDataStores[id][Channel]);
return (dmxDataStore[Channel]);
}
// 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;
if (Channel > DMXCHANNELS)
Channel = DMXCHANNELS;
@ -71,7 +49,7 @@ void DMXESPSerial::write(int id, int Channel, uint8_t value)
if (value > 255)
value = 255;
dmxDataStores[id][Channel] = value;
dmxDataStore[Channel] = value;
}
void DMXESPSerial::end()
@ -80,20 +58,20 @@ void DMXESPSerial::end()
}
// Function to update the DMX bus
void DMXESPSerial::update(int id)
void DMXESPSerial::update()
{
// Send break
digitalWrite(sendPin[id], HIGH);
SERIALPORT.begin(BREAKSPEED, BREAKFORMAT, recvPin[id], sendPin[id]);
digitalWrite(sendPin, HIGH);
SERIALPORT.begin(BREAKSPEED, BREAKFORMAT, recvPin, sendPin);
SERIALPORT.write(0);
SERIALPORT.flush();
delay(1);
SERIALPORT.end();
// send data
SERIALPORT.begin(DMXSPEED, DMXFORMAT, recvPin[id], sendPin[id]);
digitalWrite(sendPin[id], LOW);
SERIALPORT.write(dmxDataStores[id], DMXCHANNELS);
SERIALPORT.begin(DMXSPEED, DMXFORMAT, recvPin, sendPin);
digitalWrite(sendPin, LOW);
SERIALPORT.write(dmxDataStore, DMXCHANNELS);
SERIALPORT.flush();
delay(1);
SERIALPORT.end();