Skip to content

Templates#747

Merged
davepl merged 11 commits into
ttgofrom
templates
Aug 21, 2025
Merged

Templates#747
davepl merged 11 commits into
ttgofrom
templates

Conversation

@davepl

@davepl davepl commented Aug 17, 2025

Copy link
Copy Markdown
Contributor

Replace macro stucture with typed templates

  • I read the contribution guidelines in CONTRIBUTING.md.
  • I understand the BlinkenPerBit metric, and maximized it in this PR.
  • I selected main as the target branch.
  • All code herein is subjected to the license terms in COPYING.txt.

@rbergen

rbergen commented Aug 19, 2025

Copy link
Copy Markdown
Collaborator

I noticed this PR (#747) is the same as PR #748, except this one aims to merge the templates branch into ttgo, and the other into main. I will focus my review on #748 and leave this PR alone.

@robertlipe

robertlipe commented Aug 19, 2025 via email

Copy link
Copy Markdown
Collaborator

@davepl

davepl commented Aug 19, 2025

Copy link
Copy Markdown
Contributor Author

It was a lot of work to write, too :-)

I'd say one approach would be to review the deltas as I submitted them - first the audio, then the templates, etc. Each is relative to the one before it was I careful NOT to make it just one big combined PR (or that was my intent).

Honestly, for soundanalyzer and effects.cpp I'd review the final file, not the diff.

@davepl
davepl requested review from Copilot and rbergen August 19, 2025 19:50

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR converts the LED effects system from a macro-based structure to a type-safe template system, improving code maintainability and type safety. The changes remove preprocessor macros in favor of C++ templates and enum-based effect identifiers, while providing backward compatibility through transitional constructors.

Key changes:

  • Replaces macro-based effect definitions with template-based registration system
  • Converts effect IDs from preprocessor defines to strongly-typed enums
  • Updates memory allocation utilities to use proper template overloading

Reviewed Changes

Copilot reviewed 70 out of 71 changed files in this pull request and generated 12 comments.

Show a summary per file
File Description
src/gfxbase.cpp Updates make_unique_psram_array calls and removes blank lines
src/effects.cpp Major refactoring from macro-based to template-based effect registration
src/effectmanager.cpp Updates to use new enum-based effect IDs
src/deviceconfig.cpp Updates memory allocation function call
platformio.ini Build configuration updates and removed obsolete environment
include/types.h Template overload improvements for PSRAM allocation
include/soundanalyzer.h Conditional compilation and namespace fixes
include/ledstripeffect.h Effect ID system overhaul and macro replacement
include/globals.h Namespace cleanup for accumulate function
include/effectsupport.h Template-based effect registration helpers
include/effects/strip/*.h Effect ID updates across all strip effects
include/effects/matrix/*.h Effect ID updates across all matrix effects
include/effects.h Conversion from preprocessor defines to enums
include/effectfactories.h Factory function type updates for template compatibility

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread src/effects.cpp
#include "effects/strip/meteoreffect.h" // meteor blend effect
#include "effects/strip/stareffect.h" // star effects
#include "effects/strip/bouncingballeffect.h" // bouncing ball effectsenable+
#include "effects/strip/bouncingballeffect.h" // bouncing ball effects

Copilot AI Aug 19, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct the typo in the comment. Change 'effectsenable+' to 'effects'.

Copilot uses AI. Check for mistakes.
public:

ColorBeatWithFlash(const String & strName) : BeatEffectBase(), ParticleSystem<RingParticle>(), LEDStripEffect(EFFECT_STRIP_COLOR_BEAT_WITH_FLASH, strName)
ColorBeatWithFlash(const String & strName) : BeatEffectBase(), ParticleSystem<RingParticle>(), LEDStripEffect(idStripColorBeatWithFlash, strName)

Copilot AI Aug 19, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing static constexpr EffectId kId and effectId() override in ColorBeatWithFlash class. This is inconsistent with the pattern used in other effect classes throughout the codebase.

Copilot uses AI. Check for mistakes.

ColorBeatOverRed(const String & strName)
: LEDStripEffect(EFFECT_STRIP_COLOR_BEAT_OVER_RED, strName),
: LEDStripEffect(idStripColorBeatOverRed, strName),

Copilot AI Aug 19, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing static constexpr EffectId kId and effectId() override in ColorBeatOverRed class. This is inconsistent with the pattern used in other effect classes throughout the codebase.

Copilot uses AI. Check for mistakes.

MoltenGlassOnVioletBkgnd(const String & strName, const CRGBPalette16 & Palette)
: LEDStripEffect(EFFECT_STRIP_MOLTEN_GLASS_ON_VIOLET_BKGND, strName),
: LEDStripEffect(idStripMoltenGlassOnVioletBkgnd, strName),

Copilot AI Aug 19, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing static constexpr EffectId kId and effectId() override in MoltenGlassOnVioletBkgnd class. This is inconsistent with the pattern used in other effect classes throughout the codebase.

Copilot uses AI. Check for mistakes.

NewMoltenGlassOnVioletBkgnd(const String & strName, const CRGBPalette16 & Palette)
: LEDStripEffect(EFFECT_STRIP_NEW_MOLTEN_GLASS_ON_VIOLET_BKGND, strName),
: LEDStripEffect(idStripNewMoltenGlassOnVioletBkgnd, strName),

Copilot AI Aug 19, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing static constexpr EffectId kId and effectId() override in NewMoltenGlassOnVioletBkgnd class. This is inconsistent with the pattern used in other effect classes throughout the codebase.

Copilot uses AI. Check for mistakes.
FanBeatEffect(const String & strName) : LEDStripEffect(idStripFanBeat, strName)
{
}

Copilot AI Aug 19, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are two consecutive 'public:' access specifiers. Remove the duplicate on line 385.

Copilot uses AI. Check for mistakes.
public:

PatternQR() : LEDStripEffect(EFFECT_MATRIX_QR, "QR")
PatternQR() : LEDStripEffect(idMatrixQR, "QR")

Copilot AI Aug 19, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing static constexpr EffectId kId and effectId() override in PatternQR class. This is inconsistent with the pattern used in other effect classes throughout the codebase.

Copilot uses AI. Check for mistakes.
public:

PatternPulse() : LEDStripEffect(EFFECT_MATRIX_PULSE, "Pulse")
PatternPulse() : LEDStripEffect(idMatrixPulse, "Pulse")

Copilot AI Aug 19, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing static constexpr EffectId kId and effectId() override in PatternPulse class. This is inconsistent with the pattern used in other effect classes throughout the codebase.

Copilot uses AI. Check for mistakes.
PatternSpiro() : LEDStripEffect(EFFECT_MATRIX_SPIRO, "Spiro")
PatternSpiro() : LEDStripEffect(idMatrixSpiro, "Spiro")
{
}

Copilot AI Aug 19, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing static constexpr EffectId kId and effectId() override in PatternSpiro class. This is inconsistent with the pattern used in other effect classes throughout the codebase.

Copilot uses AI. Check for mistakes.
PatternRainbowFlag() : LEDStripEffect(EFFECT_MATRIX_RAINBOW_FLAG, "RainbowFlag")
PatternRainbowFlag() : LEDStripEffect(idMatrixRainbowFlag, "RainbowFlag")
{
}

Copilot AI Aug 19, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing static constexpr EffectId kId and effectId() override in PatternRainbowFlag class. This is inconsistent with the pattern used in other effect classes throughout the codebase.

Copilot uses AI. Check for mistakes.
@rbergen

rbergen commented Aug 19, 2025

Copy link
Copy Markdown
Collaborator

It was a lot of work to write, too :-)

Trust me, you're talking about PR #746. :)

I think we should move towards merging that first, and then focus on #748.

This PR (#747) is really irrelevant if we follow that approach; #748 will merge the changes since #746 straight into main.

@davepl
davepl merged commit b4120b8 into ttgo Aug 21, 2025
141 checks passed
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

Successfully merging this pull request may close these issues.

4 participants