Skip to content

Commit 381d9b2

Browse files
committed
Fix DMX reads to disallow ASC packets
ASC is "Alternate Start Code".
1 parent d080f09 commit 381d9b2

File tree

2 files changed

+15
-17
lines changed

2 files changed

+15
-17
lines changed

Deevstock/DSGrid/control_tdmx.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
CMSGEQ7<true, MSGEQ7_RESET_PIN, MSGEQ7_STROBE_PIN, AUDIO_LEFT_PIN, AUDIO_RIGHT_PIN> MSGEQ7;
1616

1717
qindesign::teensydmx::Receiver dmxRx{Serial1};
18-
uint8_t dmxRxBuf[512]; // Buffer up to 512 channels
18+
uint8_t dmxRxBuf[513]; // Buffer up to 513 channels, including the start code
1919

2020
void InitMSGEQ7() {
2121
MSGEQ7.begin();
@@ -33,7 +33,7 @@ void controlSetup() {
3333
}
3434

3535
int getValue(int chan, int minV, int maxV) {
36-
return map(dmxRxBuf[(chan - 1)], 0, 255, minV, maxV);
36+
return map(dmxRxBuf[chan], 0, 255, minV, maxV);
3737
}
3838

3939

@@ -58,10 +58,9 @@ int right[7];
5858
void controlLoop() {
5959
int gPatternCount = 32; // FIXME
6060

61-
// Read up to 4 bytes (3rd param) starting from channel 1 (2nd param)
62-
// Channel 0 is the start code
63-
int read = dmxRx.read(dmxRxBuf, 1, 4);
64-
if (read == 4) {
61+
// Read up to 5 bytes (4 channels) starting from channel 0 (start code)
62+
int read = dmxRx.read(dmxRxBuf, 0, 5);
63+
if (read == 5 && dmxRxBuf[0] == 0) { // Ensure start code is zero
6564
EVERY_N_SECONDS( 2 ) {
6665
Serial.printf("Brighness: %u\n", getValue(1, 0, 255)); // Dimmer data for Channel 1
6766
}

Deevstock/DeevstockDMX/DeevstockDMX.ino

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const bool kMatrixSerpentineLayout = true;
3737
// **********************************************************************************************************
3838

3939
qindesign::teensydmx::Receiver dmxRx{Serial1};
40-
uint8_t dmxRxBuf[6]; // Buffer up to 512 channels
40+
uint8_t dmxRxBuf[513]; // Buffer up to 513 channels, including the start code
4141

4242
CRGB leds[NUM_LEDS];
4343
CRGB ledsAudio[NUM_AUDIO_LEDS];
@@ -239,30 +239,29 @@ elapsedMillis elapsed;
239239
int pattern = 0;
240240
void loop()
241241
{
242-
// Read up to 6 bytes (3rd param) starting from channel 1 (2nd param)
243-
// Channel 0 is the start code
244-
int read = dmxRx.readPacket(dmxRxBuf, 1, 6);
245-
if (read == 6) {
242+
// Read up to 7 bytes (6 channels) starting from channel 0 (start code)
243+
int read = dmxRx.readPacket(dmxRxBuf, 0, 7);
244+
if (read == 7 && dmxRxBuf[0] == 0) { // Ensure start code is zero
246245
led = !led;
247246
digitalWrite(LED_BUILTIN, led);
248-
int b = dmxRxBuf[0]; // brightness = 1
247+
int b = dmxRxBuf[1]; // brightness = 1
249248
if (b != BRIGHTNESS) {
250249
BRIGHTNESS = b;
251250
FastLED.setBrightness(BRIGHTNESS);
252251
Serial.printf("Brightness: %u\n", BRIGHTNESS);
253252
}
254-
STEPS = dmxRxBuf[1]; // steps = 2
255-
SPEEDO = dmxRxBuf[2]; //speed = 3
256-
FADE = dmxRxBuf[3]; // fade = 4
257-
int p = dmxRxBuf[4]; // pattern = 5
253+
STEPS = dmxRxBuf[2]; // steps = 2
254+
SPEEDO = dmxRxBuf[3]; //speed = 3
255+
FADE = dmxRxBuf[4]; // fade = 4
256+
int p = dmxRxBuf[5]; // pattern = 5
258257
pattern = map(p, 0, 255, 0, (gPatternCount - 1));
259258
if(p > (gPatternCount - 1)) {
260259
p = 0;
261260
}
262261
else {
263262
pattern = p;
264263
}
265-
currentPalette = palettes[map(dmxRxBuf[5], 0, 255, 0, (paletteCount - 1))]; // channel 6
264+
currentPalette = palettes[map(dmxRxBuf[6], 0, 255, 0, (paletteCount - 1))]; // channel 6
266265
// EVERY_N_SECONDS( 2 ) {
267266
// Serial.println(p);
268267
// Serial.print("b=");

0 commit comments

Comments
 (0)