-
Notifications
You must be signed in to change notification settings - Fork 235
Dynamic LED Settings, WS2812B output driver #857
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
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
64738bb
Dynamic Settings, WS2812B output driver
davepl 0973c76
Merge main into unified_settings, resolve conflicts
Copilot d0ea5da
Update platformio.ini
davepl afec634
Merge origin/main and add beat detection work
davepl b651e91
Fix PR
davepl ca49a10
Merge branch 'unified_settings' of github.com:PlummersSoftwareLLC/Nig…
davepl 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,6 +32,7 @@ | |
|
|
||
| #include "globals.h" | ||
|
|
||
| #include <array> | ||
| #include <tuple> | ||
| #include <vector> | ||
|
|
||
|
|
@@ -124,6 +125,39 @@ | |
|
|
||
| class DeviceConfig : public IJSONSerializable | ||
| { | ||
| public: | ||
| enum class OutputDriver : uint8_t | ||
| { | ||
| WS281x, | ||
| HUB75 | ||
| }; | ||
|
|
||
| struct RuntimeTopology | ||
| { | ||
| uint16_t width = MATRIX_WIDTH; | ||
| uint16_t height = MATRIX_HEIGHT; | ||
| bool serpentine = true; | ||
|
davepl marked this conversation as resolved.
|
||
| }; | ||
|
|
||
| struct RuntimeOutputs | ||
| { | ||
| OutputDriver driver = | ||
| #if USE_HUB75 | ||
| OutputDriver::HUB75; | ||
| #else | ||
| OutputDriver::WS281x; | ||
| #endif | ||
| size_t channelCount = NUM_CHANNELS; | ||
| std::array<int8_t, NUM_CHANNELS> outputPins{}; | ||
| }; | ||
|
|
||
| struct RuntimeConfig | ||
| { | ||
| RuntimeTopology topology; | ||
| RuntimeOutputs outputs; | ||
| }; | ||
|
|
||
| private: | ||
| // Add variables for additional settings to this list | ||
| String hostname = cszHostname; | ||
| String location = cszLocation; | ||
|
|
@@ -141,12 +175,20 @@ class DeviceConfig : public IJSONSerializable | |
| CRGB globalColor = CRGB::Red; | ||
| bool applyGlobalColors = false; | ||
| CRGB secondColor = CRGB::Red; | ||
| int8_t audioInputPin = AUDIO_INPUT_PIN; | ||
| RuntimeTopology runtimeTopology = {}; | ||
| RuntimeOutputs runtimeOutputs = {}; | ||
|
|
||
| std::vector<SettingSpec, psram_allocator<SettingSpec>> settingSpecs; | ||
| std::vector<std::reference_wrapper<SettingSpec>> settingSpecReferences; | ||
| size_t writerIndex; | ||
|
|
||
| void SaveToJSON() const; | ||
| bool SetTimeZoneInternal(const String& newTimeZone, bool skipWrite); | ||
| static std::array<int8_t, NUM_CHANNELS> GetCompiledWS281xPins(); | ||
| static const char* DriverName(OutputDriver driver); | ||
| static bool IsHub75Build(); | ||
| void LogRuntimeConfig(const char* reason) const; | ||
|
|
||
| template <typename T> | ||
| void SetAndSave(T& target, const T& source) | ||
|
|
@@ -191,6 +233,13 @@ class DeviceConfig : public IJSONSerializable | |
| static constexpr const char * GlobalColorTag = NAME_OF(globalColor); | ||
| static constexpr const char * ApplyGlobalColorsTag = NAME_OF(applyGlobalColors); | ||
| static constexpr const char * SecondColorTag = NAME_OF(secondColor); | ||
| static constexpr const char * MatrixWidthTag = "matrixWidth"; | ||
|
davepl marked this conversation as resolved.
|
||
| static constexpr const char * MatrixHeightTag = "matrixHeight"; | ||
| static constexpr const char * MatrixSerpentineTag = "matrixSerpentine"; | ||
| static constexpr const char * OutputDriverTag = "outputDriver"; | ||
| static constexpr const char * WS281xChannelCountTag = "ws281xChannelCount"; | ||
| static constexpr const char * WS281xPinsTag = "ws281xPins"; | ||
| static constexpr const char * AudioInputPinTag = "audioInputPin"; | ||
|
|
||
| DeviceConfig(); | ||
|
|
||
|
|
@@ -236,13 +285,15 @@ class DeviceConfig : public IJSONSerializable | |
| void SetRememberCurrentEffect(bool newRememberCurrentEffect); | ||
|
|
||
| uint8_t GetBrightness() const { return brightness; } | ||
| static ValidateResponse ValidateBrightness(int newBrightness); | ||
| static ValidateResponse ValidateBrightness(const String& newBrightness); | ||
| void SetBrightness(int newBrightness); | ||
|
|
||
| bool ShowVUMeter() const { return showVUMeter; } | ||
| void SetShowVUMeter(bool newShowVUMeter); | ||
|
|
||
| int GetPowerLimit() const { return powerLimit; } | ||
|
davepl marked this conversation as resolved.
|
||
| static ValidateResponse ValidatePowerLimit(int newPowerLimit); | ||
| static ValidateResponse ValidatePowerLimit(const String& newPowerLimit); | ||
| void SetPowerLimit(int newPowerLimit); | ||
|
|
||
|
|
@@ -257,4 +308,73 @@ class DeviceConfig : public IJSONSerializable | |
|
|
||
| void SetColorSettings(const CRGB& globalColor, const CRGB& secondColor); | ||
| void ApplyColorSettings(std::optional<CRGB> globalColor, std::optional<CRGB> secondColor, bool clearGlobalColor, bool applyGlobalColor); | ||
|
|
||
| static constexpr uint16_t GetCompiledMatrixWidth() { return MATRIX_WIDTH; } | ||
|
davepl marked this conversation as resolved.
|
||
| static constexpr uint16_t GetCompiledMatrixHeight() { return MATRIX_HEIGHT; } | ||
| static constexpr size_t GetCompiledLEDCount() { return NUM_LEDS; } | ||
| static constexpr size_t GetCompiledChannelCount() { return NUM_CHANNELS; } | ||
| static constexpr int GetCompiledAudioInputPin() { return AUDIO_INPUT_PIN; } | ||
| static std::array<int8_t, NUM_CHANNELS> GetCompiledPins() { return GetCompiledWS281xPins(); } | ||
| static OutputDriver GetCompiledOutputDriver() | ||
| { | ||
| #if USE_HUB75 | ||
| return OutputDriver::HUB75; | ||
| #else | ||
| return OutputDriver::WS281x; | ||
| #endif | ||
| } | ||
|
|
||
| RuntimeConfig GetRuntimeConfig() const { return RuntimeConfig{runtimeTopology, runtimeOutputs}; } | ||
| const RuntimeTopology& GetTopology() const { return runtimeTopology; } | ||
| const RuntimeOutputs& GetOutputs() const { return runtimeOutputs; } | ||
| uint16_t GetMatrixWidth() const { return runtimeTopology.width; } | ||
| uint16_t GetMatrixHeight() const { return runtimeTopology.height; } | ||
| bool IsMatrixSerpentine() const { return runtimeTopology.serpentine; } | ||
| size_t GetActiveLEDCount() const { return static_cast<size_t>(runtimeTopology.width) * runtimeTopology.height; } | ||
| int GetAudioInputPin() const { return audioInputPin; } | ||
| OutputDriver GetOutputDriver() const { return runtimeOutputs.driver; } | ||
| size_t GetChannelCount() const { return runtimeOutputs.channelCount; } | ||
| const std::array<int8_t, NUM_CHANNELS>& GetWS281xPins() const { return runtimeOutputs.outputPins; } | ||
| // When runtime output settings still match the compiled WS281x transport, we can keep using the | ||
| // long-proven FastLED controller path and reserve the new runtime manager for true pin/count changes. | ||
| bool UsesCompiledWS281xTransport() const | ||
| { | ||
| return runtimeOutputs.driver == GetCompiledOutputDriver() | ||
| && runtimeOutputs.channelCount == GetCompiledChannelCount() | ||
| && runtimeOutputs.outputPins == GetCompiledPins(); | ||
| } | ||
| bool SupportsLiveTopology() const { return !IsHub75Build() && runtimeOutputs.driver == OutputDriver::WS281x; } | ||
| bool SupportsLiveOutputReconfigure() const { return !IsHub75Build() && runtimeOutputs.driver == OutputDriver::WS281x; } | ||
| bool SupportsConfigurableAudioInputPin() const | ||
| { | ||
| #if ENABLE_AUDIO && !USE_M5 && (USE_I2S_AUDIO || ELECROW) | ||
| return true; | ||
| #else | ||
| return false; | ||
| #endif | ||
| } | ||
| bool SupportsLiveAudioInputReconfigure() const { return false; } | ||
| String GetAudioInputModeName() const | ||
| { | ||
| #if !ENABLE_AUDIO | ||
| return "disabled"; | ||
| #elif USE_M5 | ||
| return "m5_internal"; | ||
| #elif USE_I2S_AUDIO || ELECROW | ||
| return "i2s"; | ||
| #else | ||
| return "adc_fixed"; | ||
| #endif | ||
| } | ||
| bool RequiresRecompileForCurrentRuntimeConfig() const { return runtimeOutputs.driver != GetCompiledOutputDriver(); } | ||
| String GetCompiledDriverName() const { return DriverName(GetCompiledOutputDriver()); } | ||
| String GetRuntimeDriverName() const { return DriverName(runtimeOutputs.driver); } | ||
|
|
||
| ValidateResponse ValidateAudioInputPin(int pin) const; | ||
| ValidateResponse ValidateTopology(uint16_t width, uint16_t height, bool serpentine) const; | ||
| ValidateResponse ValidateOutputDriver(OutputDriver driver) const; | ||
| ValidateResponse ValidateWS281xSettings(size_t channelCount, const std::array<int8_t, NUM_CHANNELS>& pins) const; | ||
| ValidateResponse ValidateRuntimeConfig(const RuntimeConfig& config) const; | ||
| bool SetRuntimeConfig(const RuntimeConfig& config, bool skipWrite = false, String* errorMessage = nullptr); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does SetRuntimeConfig write to errorMessage? Then that String* should be a const String& |
||
| void SetAudioInputPin(int newAudioInputPin); | ||
| }; | ||
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
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.
Uh oh!
There was an error while loading. Please reload this page.