Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Off-by-one error case for channel? #25

Open
Simon-L opened this issue Apr 8, 2024 · 2 comments
Open

Off-by-one error case for channel? #25

Simon-L opened this issue Apr 8, 2024 · 2 comments

Comments

@Simon-L
Copy link

Simon-L commented Apr 8, 2024

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

@netmindz
Copy link

What value are you using for init, by default it's only 32

//dmx.init(512) // initialization for complete bus

@Simon-L
Copy link
Author

Simon-L commented Apr 10, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants