PoC for refactoring to be OO library#8
Draft
netmindz wants to merge 14 commits into
Draft
Conversation
…analog ADC - createAudioSource: add analog ADC (I2SAdcSource) case, per-case delay(100) before initialize(), delay(250) after switch, I2C global pin alignment for codec types (ES7243/ES8388/WM8978/AC101/ES8311), SCK==-1->PDM51 auto-detect, and case 254/255 now forces disableSoundProcessing+audioSyncEnabled=REC - configureAudioLibraries: use bandpass filter (mode 1) for analog ADC mic, matching main's useInputFilter=1 for dmType==0 - updateGlobalVariables: remove raw soundPressure/agcSensitivity assignments that bypassed the loop()'s exponential smoothing (matches main:2319-2332) - audio_processor.h: add attackTime to Config (was using decayTime for both), filterTime to Stats, hasNewFFTResult/clearNewFFTResult/getFFTCalc/getFFTAvg/ getMajorPeakSmooth getters, m_fftMajorPeakSmth and m_haveNewFFTResult fields - audio_processor.cpp: fix limitSampleDynamics to use attackTime for attack and decayTime for decay separately; add fftTaskCycle/sampleTime/filterTime stats instrumentation; set m_haveNewFFTResult after each FFT cycle; smooth m_fftMajorPeakSmth in fftTask; set m_haveNewFFTResult in processSamples - setup: move delay into createAudioSource, add FFT task failure->enabled=false, verbose init log messages, explicit disableSoundProcessing=false on success - addToJsonState: add !enabled guard to match main:2764
…Source interface, ERR codes - Move DEBUGSR/ERRORSR/USER/PLOT macro block before #include "audio_source.h" in audio_reactive.h — audio_source.h used these macros before they were defined - Remove stray #endif (orphaned from old #ifndef guard, now using #pragma once) - Add fallback #defines for ERR_REBOOT_NEEDED / ERR_POWEROFF_NEEDED which are MoonModules-only constants absent from standard wled/WLED const.h - Replace AudioSource* forward declaration in audio_processor.h with ISampleSource abstract interface (getSamples only); AudioSource inherits from it in audio_source.h. Allows audio_processor.cpp to call getSamples without pulling in WLED-coupled audio_source.h and its transitive WLED dependencies (PinManager, i2c_sda, etc.) - Fix FFT.majorPeak() calls to pass pointers (&f, &v) matching kosme/arduinoFFT@2.0.1 API — the refactor had dropped the & vs the original monolithic code (main:777) - Remove custom static constrain() helper that conflicted with Arduino's macro - Update AGENTS.md: use fresh /tmp/WLED clone, drop stale arduinoFFT issue note
Replace all direct PinManager/PinOwner/i2c_sda/i2c_scl references in audio_source.h with a platform-agnostic IPinAllocator interface. WLEDPinAllocator (in audio_reactive.h) is the only concrete implementation and the only place PinManager/PinOwner now appear in the library. - Add IPinAllocator with allocatePin(), deallocatePin(), joinWire() (no-op default) - I2SSource, I2SAdcSource, SPH0654: accept IPinAllocator* in constructor - All five I2C codec subclasses (ES7243, ES8388Source, ES8311Source, WM8978Source, AC101Source): accept sdaPin/sclPin/IPinAllocator* in constructor; initialize() reads _sdaPin/_sclPin instead of i2c_sda/i2c_scl globals - Add _allocatePin()/_deallocatePin() helpers that log-and-skip when no allocator is provided (safe for unit-test / non-WLED builds) - Add fallback DEBUGSR_*/ERRORSR_*/USER_* no-op macro guards for standalone compilation of audio_source.h - Fix two stray DEBUG_PRINTLN -> DEBUGSR_PRINTLN in I2SSource::initialize() - Add WLEDPinAllocator class and m_pinAllocator member to AudioReactive - createAudioSource(): resolve i2c_sda/scl before construction and pass directly to codec constructors along with &m_pinAllocator Build verified: pio run -e esp32dev_oo against wled/WLED main, zero errors.
Collaborator
Author
|
This does now compile, install and at least work in a basic manner, just need to track down why the pins are just shown as "pin" in the settings menu. I have also created a PoC of Node Driver for MoonLight using this at a test of how easily non-WLED projects can use the library MoonModules/MoonLight#178 |
Collaborator
Author
|
In reality we would have a separate library repo entirely that this WLED usermod would use |
…oonLight Introduce audio_source_factory.h with AudioSourceConfig struct, normalizeDmType() helper, and createAudioSource() free function containing the single canonical source-selection switch. AudioReactive::createAudioSource() now resolves I2C pins and PDM auto-promotion locally, then delegates all instantiation to the factory. MoonModulesAudioDriver (D_MoonModulesAudio.h) can do the same, removing its duplicated switch entirely. The factory handles the MoonLight dmType-10 alias for legacy PDM (51) internally, so neither consumer needs to map values before calling.
Switch I2SSource to the new split channel API (i2s_std / i2s_pdm) under IDF >= 5.0.0, keeping the legacy monolithic driver for IDF 4.x behind #else guards. Key changes: - Dual-path includes: driver/i2s_std.h + driver/i2s_pdm.h for IDF 5.x; legacy driver/i2s.h + soc/i2s_reg.h for IDF 4.x. - I2S_SAMPLE_RESOLUTION and I2S_data_size split by IDF version. - I2SSource: _config / _pinConfig replaced by i2s_chan_handle_t + tracked pin members under IDF 5.x; initialize / deinitialize / getSamples all have dual paths. - Channel selection: new _isRightChannel flag used for IDF 5.x slot_mask; all I2C codec subclasses (ES7243, ES8388, ES8311, WM8978, AC101) updated accordingly. - I2SAdcSource excluded from IDF >= 5.x builds: ADC-over-I2S (I2S_MODE_ADC_BUILT_IN / i2s_set_adc_mode) was removed in IDF 5.x. - SPH0654 timing register hack guarded to IDF 4.x + classic ESP32 only. - AGENTS.md: update fork reference to netmindz/WLED-MM AR-Usermod-out-of-tree.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Quick first pass at what an AI can do if we ask to split into an OO library, without much direction
Possibly more talking point than exactly how we would do for real