-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
DMX improvements and configuration option. #5216
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
Open
Stijn-Jacobs
wants to merge
5
commits into
wled:main
Choose a base branch
from
Stijn-Jacobs:dmx-improvements-and-configuration
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+145
−231
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8690657
Improved DMX related code, manually build break signal. Added amount …
Stijn-Jacobs b1664af
Changed comments, related to DMX changes.
Stijn-Jacobs 3e3d6d6
Remove the change detection, from the DMX update code.
Stijn-Jacobs 78a8631
Remove unused defines, no longer used by the DMX sparkfun implementat…
Stijn-Jacobs d2d37e8
Removed sparkfun dmx implementation, and moved to esp_dmx. Improved p…
Stijn-Jacobs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| /****************************************************************************** | ||
| * EspDmxOutput.cpp | ||
| * | ||
| * DMX output via `esp_dmx` on ESP32. | ||
| * Keeps the minimal API WLED uses: initWrite(), write(), update(). | ||
| ******************************************************************************/ | ||
|
|
||
| /* ----- LIBRARIES ----- */ | ||
| #if defined(ARDUINO_ARCH_ESP32) | ||
|
|
||
| #include <Arduino.h> | ||
| #if !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32S2) | ||
|
|
||
| #include "EspDmxOutput.h" | ||
| #include <esp_dmx.h> | ||
|
|
||
| #define dmxMaxChannel 512 | ||
| #define defaultMax 32 | ||
|
|
||
| // Some new MCUs (-S2, -C3) don't have HardwareSerial(2) | ||
| #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 2, 0) | ||
| #if SOC_UART_NUM < 3 | ||
| #error DMX output is not possible on your MCU, as it does not have HardwareSerial(2) | ||
| #endif | ||
| #endif | ||
|
|
||
| static constexpr dmx_port_t dmxPort = DMX_NUM_2; | ||
|
|
||
| // Pin defaults. Change these if needed for your hardware. | ||
| static const int txPin = 2; // transmit DMX data over this pin (default is GPIO2) | ||
| static const int rxPin = DMX_PIN_NO_CHANGE; // RX unused for DMX output | ||
| static const int rtsPin = DMX_PIN_NO_CHANGE; // RS485 DE/RE pin (UART RTS). Set to a GPIO to control transceiver direction. | ||
|
|
||
| // DMX value array and size. Entry 0 holds start code, so we need 512+1 elements. | ||
| static uint8_t dmxData[DMX_PACKET_SIZE] = {0}; | ||
| // Maximum slot count configured by initWrite() (includes start code slot 0). | ||
| static size_t maxSize = 0; | ||
| // Current transmit size (includes start code slot 0). This grows as channels are written. | ||
| static size_t txSize = 1; | ||
| static bool dmxInstalled = false; | ||
|
|
||
| void EspDmxOutput::initWrite(int chanQuant) { | ||
| if (chanQuant > dmxMaxChannel || chanQuant <= 0) chanQuant = defaultMax; | ||
| maxSize = static_cast<size_t>(chanQuant) + 1; // +1 for start code | ||
| txSize = 1; // start with just start code | ||
|
|
||
| // Configure the driver if needed. | ||
| if (!dmx_driver_is_installed(dmxPort)) { | ||
| dmx_config_t config = DMX_CONFIG_DEFAULT; | ||
| dmxInstalled = dmx_driver_install(dmxPort, &config, DMX_INTR_FLAGS_DEFAULT); | ||
| } else { | ||
| dmxInstalled = true; | ||
| } | ||
|
|
||
| if (dmxInstalled) { | ||
| dmx_set_pin(dmxPort, txPin, rxPin, rtsPin); | ||
|
|
||
| // Ensure NULL start code (slot 0). | ||
| dmxData[0] = DMX_SC; | ||
| dmx_write_slot(dmxPort, 0, DMX_SC); | ||
| } | ||
| } | ||
|
|
||
| void EspDmxOutput::write(int Channel, uint8_t value) { | ||
| if (!dmxInstalled) return; | ||
|
|
||
| // Allow slot 0 writes, but start code is enforced in update(). | ||
| if (Channel < 0) Channel = 0; | ||
| if (Channel > dmxMaxChannel) Channel = dmxMaxChannel; | ||
|
|
||
| const size_t neededSize = static_cast<size_t>(Channel) + 1; | ||
| if (neededSize > txSize) txSize = neededSize; | ||
| if (maxSize > 0 && txSize > maxSize) txSize = maxSize; | ||
| if (txSize > DMX_PACKET_SIZE) txSize = DMX_PACKET_SIZE; | ||
|
|
||
| dmxData[Channel] = value; | ||
| dmx_write_slot(dmxPort, static_cast<size_t>(Channel), value); | ||
| } | ||
|
|
||
| void EspDmxOutput::update() { | ||
| if (!dmxInstalled) return; | ||
|
|
||
| // Always send the break signal first | ||
| dmx_write_slot(dmxPort, 0, DMX_SC); | ||
|
|
||
| // Send the frame currently staged in the driver buffer. | ||
| dmx_send(dmxPort, txSize); | ||
| } | ||
|
|
||
| #endif | ||
| #endif | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| /* | ||
| * EspDmxOutput.h | ||
| * | ||
| * WLED DMX output implementation for ESP32 using the `esp_dmx` library. | ||
| */ | ||
| #pragma once | ||
|
|
||
| #include <inttypes.h> | ||
|
|
||
| class EspDmxOutput { | ||
| public: | ||
| void initWrite(int maxChan); | ||
| void write(int channel, uint8_t value); | ||
| void update(); | ||
| }; | ||
|
|
||
|
|
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix boolean logic for dmx_driver_install return value handling.
Line 50 incorrectly assigns
dmx_driver_installreturn value directly todmxInstalled. Sincedmx_driver_installreturnsesp_err_t(whereESP_OK = 0indicates success), successful installation would setdmxInstalled = false, preventing all subsequent DMX operations.🤖 Prompt for AI Agents