2023-Robot
Robot code for 2023 FRC season by Argos, FRC team #1756
Loading...
Searching...
No Matches
IndicatorLights.h
Go to the documentation of this file.
1
4
25
26#pragma once
27
28#include "LED.h"
29
30template <size_t N>
32 public:
33 IndicatorLights() = delete;
34 explicit IndicatorLights(LED (&&lights)[N], size_t maxIlluminated = N)
35 : m_lights(lights), m_initialized(false), m_numLEDs(N), m_maxIlluminated(maxIlluminated), m_numIlluminated(0) {}
36
37 void Initialize() {
38 if (!m_initialized) {
39 for (size_t i = 0; i < N; ++i) {
41 }
42 m_initialized = true;
43 }
44 }
45
46 void Update() {
47 if (m_initialized) {
48 for (size_t i = 0; i < N; ++i) {
49 m_lights[i].Update();
50 }
51 }
52 }
53
54 void On(size_t idx) {
55 if (m_initialized && idx < m_numLEDs) {
56 bool activeIllumination = m_lights[idx].GetIlluminated();
57 if (!activeIllumination && m_numIlluminated < m_maxIlluminated) {
59 m_lights[idx].On();
60 }
61 }
62 }
63
64 void Off(size_t idx) {
65 if (m_initialized && idx < m_numLEDs) {
66 bool activeIllumination = m_lights[idx].GetIlluminated();
67 if (activeIllumination) {
69 m_lights[idx].Off();
70 }
71 }
72 }
73
74 void Set(size_t idx, bool val) {
75 if (m_initialized) {
76 if (val) {
77 On(idx);
78 } else {
79 Off(idx);
80 }
81 }
82 }
83
84 LED::LEDPattern GetPattern(size_t idx) const {
86 if (m_initialized && idx < m_numLEDs) {
87 retVal = m_lights[idx].GetPattern();
88 }
89 return retVal;
90 }
91
92 void SetPattern(size_t idx, LED::LEDPattern newPattern) {
93 if (m_initialized && idx < m_numLEDs) {
94 m_lights[idx].SetPattern(newPattern);
95 }
96 }
97
98 size_t GetNumLights() const { return m_numLEDs; }
99
100 bool GetIlluminated(size_t idx) const {
101 bool retVal = false;
102 if (m_initialized && idx < m_numLEDs) {
103 retVal = m_lights[idx].GetIlluminated();
104 }
105 return retVal;
106 }
107
108 private:
111 const size_t m_numLEDs;
112 const size_t m_maxIlluminated;
114};
Manages a single LED.
Definition IndicatorLights.h:31
size_t m_numIlluminated
Definition IndicatorLights.h:113
const size_t m_numLEDs
Definition IndicatorLights.h:111
IndicatorLights(LED(&&lights)[N], size_t maxIlluminated=N)
Definition IndicatorLights.h:34
bool GetIlluminated(size_t idx) const
Definition IndicatorLights.h:100
size_t GetNumLights() const
Definition IndicatorLights.h:98
LED::LEDPattern GetPattern(size_t idx) const
Definition IndicatorLights.h:84
IndicatorLights()=delete
void SetPattern(size_t idx, LED::LEDPattern newPattern)
Definition IndicatorLights.h:92
void On(size_t idx)
Definition IndicatorLights.h:54
LED m_lights[N]
Definition IndicatorLights.h:109
void Initialize()
Definition IndicatorLights.h:37
void Off(size_t idx)
Definition IndicatorLights.h:64
void Update()
Definition IndicatorLights.h:46
bool m_initialized
Definition IndicatorLights.h:110
void Set(size_t idx, bool val)
Definition IndicatorLights.h:74
const size_t m_maxIlluminated
Definition IndicatorLights.h:112
Definition LED.h:42
void Initialize()
Definition LED.cpp:60
void SetPattern(LEDPattern newPattern)
Definition LED.cpp:105
LEDPattern
Definition LED.h:44
void On()
Definition LED.cpp:91
bool GetIlluminated() const
Definition LED.cpp:101
void Off()
Definition LED.cpp:96
void Update()
Definition LED.cpp:74
LEDPattern GetPattern() const
Definition LED.cpp:109