3131
3232#pragma once
3333
34+ #include " ledstripeffect.h"
35+
3436class MeteorChannel
3537{
3638 std::vector<float > hue;
@@ -98,19 +100,19 @@ class MeteorChannel
98100 bLeft[iMeteor] = !bLeft[iMeteor];
99101 }
100102
101- virtual void Draw (std::shared_ptr<GFXBase> pGFX )
103+ virtual void Draw (LEDStripEffect* owner )
102104 {
105+ auto pGFX = owner->g (0 );
103106 static CHSV hsv;
104107 hsv.val = 255 ;
105108 hsv.sat = 255 ;
106109
107- for (int j = 0 ; j<pGFX->GetLEDCount (); j++) // fade brightness all LEDs one step
110+ // Fade brightness on all channels
111+ for (int j = 0 ; j < pGFX->GetLEDCount (); j++)
108112 {
109- if ((!meteorRandomDecay) || (random_range (0 , 10 )> 2 )) // BUGBUG Was 5 for everything before atomlight
113+ if ((!meteorRandomDecay) || (random_range (0 , 10 ) > 2 ))
110114 {
111- CRGB c = pGFX->getPixel (j);
112- c.fadeToBlackBy (meteorTrailDecay);
113- pGFX->setPixel (j, c);
115+ owner->fadePixelToBlackOnAllChannelsBy (j, meteorTrailDecay);
114116 }
115117 }
116118
@@ -123,32 +125,35 @@ class MeteorChannel
123125 spd *= g_Analyzer.VURatio ();
124126 #endif
125127
126- iPos[i] = (bLeft[i]) ? iPos[i]- spd : iPos[i]+ spd;
127- if (iPos[i]< meteorSize)
128+ iPos[i] = (bLeft[i]) ? iPos[i] - spd : iPos[i] + spd;
129+ if (iPos[i] < meteorSize)
128130 {
129131 bLeft[i] = false ;
130132 iPos[i] = meteorSize;
131133 }
132134 if (iPos[i] >= pGFX->GetLEDCount ())
133135 {
134136 bLeft[i] = true ;
135- iPos[i] = pGFX->GetLEDCount ()- 1 ;
137+ iPos[i] = pGFX->GetLEDCount () - 1 ;
136138 }
137139
138- for (int j = 0 ; j < meteorSize; j++) // Draw the meteor head
140+ // Draw the meteor head across all channels
141+ for (int j = 0 ; j < meteorSize; j++)
139142 {
140- int x = iPos[i] - j;
141- if ((x <= pGFX->GetLEDCount ()) && (x >= 1 ))
143+ int x = static_cast < int >( iPos[i]) - j;
144+ if ((x <= static_cast < int >( pGFX->GetLEDCount () )) && (x >= 1 ))
142145 {
143146 CRGB rgb;
144147 hue[i] = hue[i] + 0 .025f ;
145148 if (hue[i] > 255 .0f )
146149 hue[i] -= 255 .0f ;
147- hsv.hue = hue[i];
150+ hsv.hue = static_cast < uint8_t >( hue[i]) ;
148151 hsv2rgb_rainbow (hsv, rgb);
152+
153+ // Blend with current pixel from primary device, then set on all channels
149154 CRGB c = pGFX->getPixel (x);
150- nblend (c, rgb , 75 );
151- pGFX-> setPixel (x, c);
155+ nblend (c, rgb, 75 );
156+ owner-> setPixelOnAllChannels (x, c);
152157 }
153158 }
154159 }
@@ -223,7 +228,8 @@ class MeteorEffect : public LEDStripEffect
223228
224229 void Draw () override
225230 {
226- for (int i = 0 ; i < _Meteors.size (); i++)
227- _Meteors[i].Draw (_GFX[i]);
231+ // Draw once using channel 0 state while writing to all channels
232+ if (!_Meteors.empty ())
233+ _Meteors[0 ].Draw (this );
228234 }
229235};
0 commit comments