RSeries astromech firmware
SingleStatusLED.h
Go to the documentation of this file.
1 #ifndef SingleStatusLED_h
2 #define SingleStatusLED_h
3 
4 #include "ReelTwo.h"
5 #include "dome/LogicEngine.h"
6 
21 template <uint8_t DATA_PIN>
23 {
24 public:
26  {
27  }
28 
29  SingleStatusLED(const uint8_t (*colors)[4][3], unsigned numModes = 1) :
30  fNumModes(numModes),
31  fColors(colors)
32  {
33  setDelay(1000);
34  }
35 
36  virtual void setup() override
37  {
38  fStatus.init();
39  pickColor();
40  #if USE_LEDLIB == 1
41  fStatus.show();
42  #else
43  FastLED.show();
44  #endif
45  }
46 
47  virtual void animate() override
48  {
49  uint32_t timeNow = millis();
51  {
52  fPrevFlipFlopMillis = timeNow;
53  fStatusColor++;
54  if (fStatusColor == 4) fStatusColor = 0;
55  pickColor();
56  #if USE_LEDLIB == 1
57  fStatus.show();
58  #else
59  FastLED.show();
60  #endif
61  }
62  }
63 
64  void setMode(unsigned mode)
65  {
66  if (mode < fNumModes)
67  {
68  if (fMode != mode)
69  {
70  fMode = mode;
72  fStatusColor = 0;
73  }
74  animate();
75  }
76  }
77 
78  void setDelay(uint32_t delay)
79  {
80  fStatusFlipFlopTime = delay;
81  }
82 
83 protected:
84  FastLEDPCB<WS2812B, DATA_PIN> fStatus;
85  byte fStatusColor = 0; //status LED will cycle between 4 colors depending on what mode we're in
86  byte fPrevStatusColor = 0;
87  unsigned fMode = 0;
88  unsigned fNumModes = 4;
89  const uint8_t (*fColors)[4][3] = nullptr;
90  uint32_t fPrevFlipFlopMillis = 0;
91  uint32_t fStatusFlipFlopTime = 1000;
92 
93  void pickColor()
94  {
95  if (fColors == nullptr)
96  {
97  static constexpr uint8_t kStatusColors[5][4][3] = {
98  { { 10, 0, 0} , { 0, 0, 10} , { 10, 0, 0} , { 0, 0, 10} } , // red,blue,red,blue
99  { { 25, 25, 25} , { 16, 16, 16} , { 10, 10, 10} , { 10, 2, 2} } , // brightness
100  { { 2, 0, 0} , { 2, 2, 0} , { 0, 2, 0} , { 0, 0, 2} } , // hue (red , yel, green, blue)
101  { { 2, 0, 2} , { 2, 0, 1} , { 2, 0, 0} , { 2, 0, 1} } , // fade (purple, blue)
102  { { 0, 2, 0} , { 0, 2, 0} , { 0, 2, 0} , { 0, 2, 0} } // pause (all green)
103  };
104  fStatus.fLED[0].setRGB(
105  kStatusColors[fMode][fStatusColor][0],
106  kStatusColors[fMode][fStatusColor][1],
107  kStatusColors[fMode][fStatusColor][2]);
108  }
109  else
110  {
111  fStatus.fLED[0].setRGB(
114  fColors[fMode][fStatusColor][2]);
115  }
116  }
117 };
118 
119 #endif
ReelTwo.h
AnimatedEvent
Base class for all animated devices. AnimatedEvent::animate() is called for each device once through ...
Definition: AnimatedEvent.h:18
SingleStatusLED::animate
virtual void animate() override
Subclasses must implement this function to run through a single frame of animation/activity.
Definition: SingleStatusLED.h:47
SingleStatusLED::fPrevStatusColor
byte fPrevStatusColor
Definition: SingleStatusLED.h:86
SetupEvent
Base class for all devices that require setup that cannot happen in the constructor....
Definition: SetupEvent.h:15
SingleStatusLED::fMode
unsigned fMode
Definition: SingleStatusLED.h:87
SingleStatusLED::fStatus
FastLEDPCB< WS2812B, DATA_PIN > fStatus
Definition: SingleStatusLED.h:84
SingleStatusLED::SingleStatusLED
SingleStatusLED(const uint8_t(*colors)[4][3], unsigned numModes=1)
Definition: SingleStatusLED.h:29
SingleStatusLED::setup
virtual void setup() override
Subclasses must implement this function to perform any necessary setup that cannot happen in the cons...
Definition: SingleStatusLED.h:36
SingleStatusLED
LED status indicator.
Definition: SingleStatusLED.h:22
SingleStatusLED::fColors
const uint8_t(* fColors)[4][3]
Definition: SingleStatusLED.h:89
SingleStatusLED::setDelay
void setDelay(uint32_t delay)
Definition: SingleStatusLED.h:78
SingleStatusLED::fStatusFlipFlopTime
uint32_t fStatusFlipFlopTime
Definition: SingleStatusLED.h:91
SingleStatusLED::fNumModes
unsigned fNumModes
Definition: SingleStatusLED.h:88
SingleStatusLED::setMode
void setMode(unsigned mode)
Definition: SingleStatusLED.h:64
SingleStatusLED::fPrevFlipFlopMillis
uint32_t fPrevFlipFlopMillis
Definition: SingleStatusLED.h:90
LogicEngine.h
SingleStatusLED::fStatusColor
byte fStatusColor
Definition: SingleStatusLED.h:85
SingleStatusLED::pickColor
void pickColor()
Definition: SingleStatusLED.h:93
SingleStatusLED::SingleStatusLED
SingleStatusLED()
Definition: SingleStatusLED.h:25