ESP-Dmx
ESP-Dmx copied to clipboard
Off-by-one error case for channel?
Hello, I had problems using ESP-Dmx in combination with https://github.com/DaAwesomeP/dmxusb on an ESP8266 NodeMCU, working with qlcplus on the host computer. The issue was to address fixtures > 32.
It seems there might be an off-by-one error induced here:
void DMXESPSerial::write(int Channel, uint8_t value) {
if (dmxStarted == false) init();
if (Channel < 1) Channel = 1; // Channel should be allowed to be equal to zero
// Next line: Channel should *never* be > index 511 (512th element in dmxData)
if (Channel > chanSize) Channel = chanSize;
if (value < 0) value = 0;
if (value > 255) value = 255;
dmxData[Channel] = value; // undefined for Channel == 512
}
Skimming over a few issues I think this might have been the cause.
For faster/easier access I simply added a buffer() function to write directly to dmxData: https://github.com/Simon-L/mpdmx/blob/main/mpdmx_1/ESPDMX.cpp#L35
What value are you using for init, by default it's only 32
https://github.com/Rickgg/ESP-Dmx/blob/224e1834e15c1f0b320b4d28604209d2bd40d0e7/examples/DMX_Send/DMX_Send.ino#L20
I am using 512: https://github.com/Simon-L/mpdmx/blob/main/mpdmx_1/mpdmx_1.ino#L73
I did some more tests today and I might still have an off-by-one error, that has to be on my end though.
In the meantime I have also confirmed the issue reported here: when addressing 512, which makes sense as 1 is seemingly used as first channel as per the example and code, it overflows into chanSize which is located next in the memory, effectively overwriting it and preventing to address higher channels.