Skip to content

Commit

Permalink
assume 0 for all values not sent in transmission (closes #4)
Browse files Browse the repository at this point in the history
  • Loading branch information
DaAwesomeP committed Nov 24, 2017
1 parent aab6896 commit dc2f5cc
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 25 deletions.
15 changes: 6 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,15 @@ Note that mode 0 only responds to ENTTEC label 6 and outputs to universe 0 in th
#### callback (void)
A callback function to call when a DMX transmission is received. This function should have three parameters:
| parameter | description |
|--------------------|----------------------------------------------------------------------------------------------------------------------------|
| int universe | An integer starting at `0` with which universe received the DMX message |
| unsigned int index | The number of channels starting at 0 that received a message where DMX channel 1 is index 0, DMX channel 2 is index 1, etc |
| char buffer[512] | The array of DMX values where the index of the array correponds with the `index` parameter |
| parameter | description |
|--------------------|-------------------------------------------------------------------------|
| int universe | An integer starting at `0` with which universe received the DMX message |
| char buffer[512] | The array of 512 DMX values starting at 0 |
Example function that lights an LED with channel 1 on universe 0:
```cpp
void myDMXCallback(int universe, unsigned int index, char buffer[512]) {
unsigned int count;
count = index;
for (index=0; index <= count; index++) { // for each channel
void myDMXCallback(int universe, char buffer[512]) {
for (int index=0; index < 512; index++) { // for each channel, universe starts at 0
int channel = index + 1; // channel starts at 0, so index 0 is DMX channel 1 and index 511 is DMX channel 512
int value = buffer[index]; // DMX value 0 to 255
if (universe == 0 && channel == 1) analogWrite(LED_PIN, value); // LED on channel 1 on universe 0
Expand Down
9 changes: 3 additions & 6 deletions examples/Simple_Test/Simple_Test.ino
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,8 @@ const byte LED_PIN = 13;
#define BAUDRATE 115200

// receive a DMX transmission
void myDMXCallback(int universe, unsigned int index, char buffer[512]) {
// universe starts at 0
unsigned int count;
count = index;
for (index=0; index <= count; index++) { // for each channel
void myDMXCallback(int universe, char buffer[512]) {
for (int index=0; index < 512; index++) { // for each channel, universe starts at 0
int channel = index + 1; // channel starts at 0, so index 0 is DMX channel 1 and index 511 is DMX channel 512
int value = buffer[index]; // DMX value 0 to 255
if (universe == 0 && channel == 1) analogWrite(LED_PIN, value); // LED on channel 1 on universe 0
Expand All @@ -58,4 +55,4 @@ void setup() {

void loop() {
myDMXUsb.listen();
}
}
16 changes: 8 additions & 8 deletions src/DMXUSB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#define STATE_END 5

// Initialize DMXUSB serial port
DMXUSB::DMXUSB(Stream &serial, int baudrate, int mode, void (*dmxInCallback)(int universe, unsigned int index, char buffer[512])) {
DMXUSB::DMXUSB(Stream &serial, int baudrate, int mode, void (*dmxInCallback)(int universe, char buffer[512])) {
_serial = &serial;
_baudrate = baudrate;
_mode = mode;
Expand Down Expand Up @@ -66,6 +66,7 @@ void DMXUSB::listen() {
// second bit: message label
case STATE_LABEL:
label = b; // record the message label
if (label == 6 || label == 100 || label == 101) for (int i = 0; i < 512; i++) _buffer[i] = (byte)0x00; // set buffer to all zero values if receiving DMX data
state = STATE_LEN_LSB; // move to next bit
break;

Expand Down Expand Up @@ -94,7 +95,6 @@ void DMXUSB::listen() {
}
count = count - 1; // decrease the data count
if (count == 0) {
//for (int i = 512; i >= (index-1); i--) _buffer[i] = (byte)0x00; // set unsent values to 0 // for all unsent values (protocol says 0 values are omitted after last value)
state = STATE_END; // if no more data, move on to last bit
}
break;
Expand Down Expand Up @@ -163,13 +163,13 @@ void DMXUSB::listen() {

else if (label == 6 || label == 100 || label == 101) { // receive DMX message to both universes
//if (index > 1) {
if (label == 6 && _mode == 0) this->DMXUSB::_dmxInCallback(0, index, _buffer); // receive label==6 DMX message to first universe for Enttec-like ultraDMX Micro device
if (label == 6 && _mode == 0) this->DMXUSB::_dmxInCallback(0, _buffer); // receive label==6 DMX message to first universe for Enttec-like ultraDMX Micro device
if (label == 6 && _mode == 1) { // receive label==6 DMX message to both universes for ultraDMX Pro device
this->DMXUSB::_dmxInCallback(0, index, _buffer);
this->DMXUSB::_dmxInCallback(1, index, _buffer);
this->DMXUSB::_dmxInCallback(0, _buffer);
this->DMXUSB::_dmxInCallback(1, _buffer);
}
if (label == 100 || _mode == 1) this->DMXUSB::_dmxInCallback(0, index, _buffer); // receive label==100 DMX message to first universe for ultraDMX Pro device
if (label == 101 || _mode == 1) this->DMXUSB::_dmxInCallback(1, index, _buffer); // receive label==101 DMX message to second universe for ultraDMX Pro device
if (label == 100 || _mode == 1) this->DMXUSB::_dmxInCallback(0, _buffer); // receive label==100 DMX message to first universe for ultraDMX Pro device
if (label == 101 || _mode == 1) this->DMXUSB::_dmxInCallback(1, _buffer); // receive label==101 DMX message to second universe for ultraDMX Pro device
//}
}
}
Expand All @@ -181,4 +181,4 @@ void DMXUSB::listen() {
}
}
}
}
}
4 changes: 2 additions & 2 deletions src/DMXUSB.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@

class DMXUSB {
public:
DMXUSB(Stream &serial, int baudrate, int mode, void (*dmxInCallback)(int universe, unsigned int index, char buffer[512]));
DMXUSB(Stream &serial, int baudrate, int mode, void (*dmxInCallback)(int universe, char buffer[512]));
void listen();
private:
char _buffer[512];
elapsedMillis _timeout;
Stream *_serial;
int _baudrate;
int _mode;
void (*_dmxInCallback)(int universe, unsigned int index, char buffer[512]);
void (*_dmxInCallback)(int universe, char buffer[512]);
};

#endif
Expand Down

0 comments on commit dc2f5cc

Please sign in to comment.