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

dmx_receive blocking #58

Closed
netmindz opened this issue Mar 23, 2023 · 6 comments
Closed

dmx_receive blocking #58

netmindz opened this issue Mar 23, 2023 · 6 comments

Comments

@netmindz
Copy link

If you are trying to write code that optionally expects DMX data, how can you prevent the code from being blocked while waiting for DMX timeout?

Most DMX libraries I've worked with before allow you simple

void loop() {
Dmx.loop();
if (Dmx.newFrame()) {
}
}

@someweisguy
Copy link
Owner

someweisguy commented Mar 23, 2023

The last argument of dmx_receive() is the maximum block time in FreeRTOS ticks. If you set this argument to 0, the function will not block and will return the number of DMX packet slots received.

dmx_packet_t packet;
if (dmx_receive(DMX_NUM_2, &packet, 0)) {
  // Do work if packet is received
}

As a side note, dmx_receive() will only return the number of slots received for a NEW packet. If you call dmx_receive() again with a block time of zero and before a new packet is received, it will return 0.

This is a relatively new feature so let me know if this is not the behavior you see!

@netmindz
Copy link
Author

Thanks for the very prompt response, using 0 does resolve my blocking issue. However, I'm now seeing some rather odd glitches with WLEDs output when DMX is active if I then use that.

Is 0 a magic value to trigger a different behavior?

So with the blocking, all is fine when I have DMX, but no signal blocks my main loop for the timeout.
With no blocking, when no DMX all is fine, but when receiving I get very erratic behavior of the WLED output

@someweisguy
Copy link
Owner

someweisguy commented Mar 24, 2023

Setting the block time to 0 should not cause another behavior.

What do you mean by erratic behavior? Do you mind sharing your code?

@netmindz
Copy link
Author

The LEDs star showing incorrect values, I wondered if we were seeing clashing interrupts

https://github.com/netmindz/WLED/blob/DMX-Input-esp_dmx/wled00/dmx.cpp

@someweisguy
Copy link
Owner

someweisguy commented Mar 26, 2023

Thanks for the code link. It is possible that this is related to interrupts clashing. It should be possible to check this by adjusting the DMX driver interrupt priority. The constant ESP_INTR_FLAG_LEVEL3 should work when installing your DMX driver. In other words, instead of calling dmx_driver_install(dmx_num, DMX_DEFAULT_INTR_FLAGS), try calling dmx_driver_install(dmx_num, ESP_INTR_FLAG_LEVEL3).

You should also check to ensure that your other components are using lower level interrupts.

@netmindz
Copy link
Author

That seems to be working nicely, thank you

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