mirror of
https://github.com/HendrikRauh/dmx-interface.git
synced 2025-12-16 07:34:09 +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>
|
||||
// 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
|
||||
// - - - - -
|
||||
|
|
@ -13,6 +13,9 @@
|
|||
/* ----- LIBRARIES ----- */
|
||||
#include <Arduino.h>
|
||||
#include "ESPDMX.h"
|
||||
#include <vector>
|
||||
|
||||
#define MAX_IDS 3
|
||||
|
||||
#define DMXSPEED 250000
|
||||
#define DMXFORMAT SERIAL_8N2
|
||||
|
|
@ -21,41 +24,45 @@
|
|||
#define SERIALPORT Serial0
|
||||
#define DMXCHANNELS 512
|
||||
|
||||
bool dmxStarted = false;
|
||||
int sendPin = 18;
|
||||
int receivePin = -1;
|
||||
int sendPin[] = {};
|
||||
int recvPin[] = {};
|
||||
|
||||
// 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
|
||||
void DMXESPSerial::init()
|
||||
void DMXESPSerial::init(int id, int pinSend, int pinRecv)
|
||||
{
|
||||
SERIALPORT.begin(DMXSPEED, DMXFORMAT, receivePin, sendPin);
|
||||
pinMode(sendPin, OUTPUT);
|
||||
dmxStarted = true;
|
||||
sendPin[id] = pinSend;
|
||||
recvPin[id] = pinRecv;
|
||||
SERIALPORT.begin(DMXSPEED, DMXFORMAT, recvPin[id], sendPin[id]);
|
||||
pinMode(sendPin[id], OUTPUT);
|
||||
}
|
||||
|
||||
// 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)
|
||||
Channel = 1;
|
||||
if (Channel > DMXCHANNELS)
|
||||
Channel = DMXCHANNELS;
|
||||
return (dmxDataStore[Channel]);
|
||||
return (dmxDataStores[id][Channel]);
|
||||
}
|
||||
|
||||
// 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)
|
||||
init();
|
||||
|
||||
if (Channel < 1)
|
||||
s if (Channel < 1)
|
||||
Channel = 1;
|
||||
if (Channel > DMXCHANNELS)
|
||||
Channel = DMXCHANNELS;
|
||||
|
|
@ -64,33 +71,29 @@ void DMXESPSerial::write(int Channel, uint8_t value)
|
|||
if (value > 255)
|
||||
value = 255;
|
||||
|
||||
dmxDataStore[Channel] = value;
|
||||
dmxDataStores[id][Channel] = value;
|
||||
}
|
||||
|
||||
void DMXESPSerial::end()
|
||||
{
|
||||
SERIALPORT.end();
|
||||
dmxStarted = false;
|
||||
}
|
||||
|
||||
// Function to update the DMX bus
|
||||
void DMXESPSerial::update()
|
||||
void DMXESPSerial::update(int id)
|
||||
{
|
||||
if (dmxStarted == false)
|
||||
init();
|
||||
|
||||
// Send break
|
||||
digitalWrite(sendPin, HIGH);
|
||||
SERIALPORT.begin(BREAKSPEED, BREAKFORMAT, receivePin, sendPin);
|
||||
digitalWrite(sendPin[id], HIGH);
|
||||
SERIALPORT.begin(BREAKSPEED, BREAKFORMAT, recvPin[id], sendPin[id]);
|
||||
SERIALPORT.write(0);
|
||||
SERIALPORT.flush();
|
||||
delay(1);
|
||||
SERIALPORT.end();
|
||||
|
||||
// send data
|
||||
SERIALPORT.begin(DMXSPEED, DMXFORMAT, receivePin, sendPin);
|
||||
digitalWrite(sendPin, LOW);
|
||||
SERIALPORT.write(dmxDataStore, DMXCHANNELS);
|
||||
SERIALPORT.begin(DMXSPEED, DMXFORMAT, recvPin[id], sendPin[id]);
|
||||
digitalWrite(sendPin[id], LOW);
|
||||
SERIALPORT.write(dmxDataStores[id], DMXCHANNELS);
|
||||
SERIALPORT.flush();
|
||||
delay(1);
|
||||
SERIALPORT.end();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue