@@ -226,17 +226,49 @@ class StatefulLED {
226
226
};
227
227
228
228
229
+ // All Binky LEDs respond to global modes (like rainbow)
230
+ // The local states must be defined as member variables, and a chooseNextLocalState function
231
+ // chooses which state to point to when it is time to find the next one. This ensures
232
+ // we only need to handle global behaviors here.
233
+ class BinkyLED : public StatefulLED {
234
+ public:
235
+ SolidColorTimedState m_stOn;
236
+ SolidColorState m_stOff;
237
+ PartyMode m_partymode;
238
+ RainbowState m_stRainbow;
239
+ unsigned long m_canFlashMs;
240
+
241
+ BinkyLED (struct CRGB * leds, int numLEDs, int index) :
242
+ StatefulLED (leds, numLEDs, index),
243
+ m_stOn (COLOR_WHITE, FLASH_DURATION_MS / 10 ),
244
+ m_stOff (COLOR_BLACK),
245
+ m_partymode (PartyMode::Values::rainbow);
246
+ m_stRainbow (numLEDs, index),
247
+ m_canFlashMs (0 )
248
+ {}
249
+
250
+ // the master signal for rainbow mode overrides all others
251
+ virtual LEDState* chooseNextState (unsigned long const &millis, const SlaveState &slave) {
252
+ if (slave.getMasterSignal (MasterSignal::Values::scrollRainbowEffects)) {
253
+ return &m_stRainbow;
254
+ } else {
255
+ return chooseNextLocalState (millis, slave);
256
+ }
257
+ }
258
+
259
+ // what state to pick next
260
+ virtual LEDState* chooseNextLocalState (unsigned long const &millis, const SlaveState &slave) = 0;
261
+ };
262
+
229
263
// A simple LED switches between a solid color mode (on/off) and a rainbow mode
230
264
// the on/off criteria cna be overridden
231
- class SimpleLED : public StatefulLED {
265
+ class SimpleLED : public BinkyLED {
232
266
public:
233
- RainbowState m_stRainbow;
234
267
SolidColorState m_stOff;
235
268
SolidColorState m_stOn;
236
269
237
270
SimpleLED (struct CRGB * leds, int numLEDs, int index, const struct CHSV &color) :
238
- StatefulLED (leds, numLEDs, index),
239
- m_stRainbow (numLEDs, index),
271
+ BinkyLED (leds, numLEDs, index),
240
272
m_stOff (COLOR_BLACK),
241
273
m_stOn (color)
242
274
{}
@@ -246,12 +278,8 @@ class SimpleLED : public StatefulLED {
246
278
{}
247
279
248
280
// the master signal for rainbow mode overrides all others
249
- virtual LEDState* chooseNextState (unsigned long const &millis, const SlaveState &slave) {
250
- if (slave.getMasterSignal (MasterSignal::Values::scrollRainbowEffects)) {
251
- return &m_stRainbow;
252
- } else {
253
- return isOn (millis, slave) ? &m_stOn : &m_stOff;
254
- }
281
+ virtual LEDState* chooseNextLocalState (unsigned long const &millis, const SlaveState &slave) {
282
+ return isOn (millis, slave) ? &m_stOn : &m_stOff;
255
283
}
256
284
257
285
// by default, always on
@@ -321,7 +349,7 @@ class RearFoggerLED : public SimpleLED {
321
349
322
350
323
351
// This class defines a blinking LED that can blink 2 different colors
324
- class MultiBlinkingLED : public StatefulLED {
352
+ class MultiBlinkingLED : public BinkyLED {
325
353
public:
326
354
SolidColorState m_stSolid;
327
355
FlashLoudState m_stFlashRedLoud;
@@ -333,7 +361,7 @@ class MultiBlinkingLED : public StatefulLED {
333
361
// the solid state can be interrupted at any time
334
362
335
363
MultiBlinkingLED (struct CRGB * leds, int numLEDs, int index) :
336
- StatefulLED (leds, numLEDs, index),
364
+ BinkyLED (leds, numLEDs, index),
337
365
m_stSolid (COLOR_WHITE),
338
366
m_stFlashRedLoud (COLOR_RED),
339
367
m_stFlashRedQuiet (m_stSolid),
@@ -358,10 +386,8 @@ class MultiBlinkingLED : public StatefulLED {
358
386
virtual bool isCritical (const SlaveState &slave) const = 0;
359
387
360
388
// what state to pick next
361
- virtual LEDState* chooseNextState (unsigned long const &millis, const SlaveState &slave) {
362
- if (slave.getMasterSignal (MasterSignal::Values::scrollRainbowEffects)) {
363
- return &m_stRainbow;
364
- } else if (isCritical (slave)) {
389
+ virtual LEDState* chooseNextLocalState (unsigned long const &millis, const SlaveState &slave) {
390
+ if (isCritical (slave)) {
365
391
seedFlashTiming (millis);
366
392
// loud states must transition to quiet to complete the blink. all others go loud immediately
367
393
return (inState (m_stFlashRedLoud) || inState (m_stFlashAmberLoud)) ? (LEDState*)&m_stFlashRedQuiet : (LEDState*)&m_stFlashRedLoud;
0 commit comments