Control Surface  1.1.0
MIDI Control Surface library for Arduino
DotBarDisplayLEDs.hpp
Go to the documentation of this file.
1 /* ✔ */
2 
3 #pragma once
4 
6 AH_DIAGNOSTIC_WERROR() // Enable errors on warnings
7 
8 #include <AH/Hardware/LEDs/LEDs.hpp>
9 
11 
12 /**
13  * @brief An enumeration type to set an LED display to either bar or dot mode.
14  */
15 enum class DotBarMode : bool {
16  Bar = false, ///< Turn on a range of LEDs up to the active LED.
17  Dot = true, ///< Turn on only the active LED
18 };
19 
20 /**
21  * @brief A class for LED bars.
22  *
23  * @tparam N
24  * The number of LEDs in the bar.
25  *
26  * @ingroup AH_HardwareUtils
27  */
28 template <uint8_t N>
29 class DotBarDisplayLEDs : public LEDs<N> {
30  public:
31  /// Constructor from list of pins.
32  DotBarDisplayLEDs(const PinList<N> &ledPins) : LEDs<N>{ledPins} {}
33 
34  /**
35  * @brief Display the given number of LEDs on the LED bar.
36  *
37  * @param value
38  * The number of the LED to activate.
39  */
40  void display(uint8_t value) const {
41  if (value == 0)
42  this->clear();
43  else if (mode == DotBarMode::Bar)
44  this->displayRange(0, value);
45  else
46  this->displayDot(value - 1);
47  }
48 
49  /**
50  * @brief Display the given fraction of the LED bar.
51  *
52  * @param value
53  * The fraction of the LED bar to display.
54  */
55  void display(float value) const { display(uint8_t(value * (N + 1))); }
56 
57  /**
58  * @brief Set the mode to either dot or bar mode.
59  *
60  * @param mode
61  * The mode.
62  */
63  void setMode(DotBarMode mode) { this->mode = mode; }
64 
65  /// Set the mode to dot mode.
66  void dotMode() { setMode(DotBarMode::Dot); }
67 
68  /// Set the mode to bar mode.
69  void barMode() { setMode(DotBarMode::Bar); }
70 
71  private:
72  DotBarMode mode = DotBarMode::Bar;
73 };
74 
76 
Warnings.hpp
AH::DotBarDisplayLEDs::setMode
void setMode(DotBarMode mode)
Set the mode to either dot or bar mode.
Definition: DotBarDisplayLEDs.hpp:63
AH::DotBarDisplayLEDs::barMode
void barMode()
Set the mode to bar mode.
Definition: DotBarDisplayLEDs.hpp:69
AH_DIAGNOSTIC_POP
#define AH_DIAGNOSTIC_POP()
Definition: Warnings.hpp:17
AH::DotBarDisplayLEDs::display
void display(float value) const
Display the given fraction of the LED bar.
Definition: DotBarDisplayLEDs.hpp:55
AH::DotBarDisplayLEDs::DotBarDisplayLEDs
DotBarDisplayLEDs(const PinList< N > &ledPins)
Constructor from list of pins.
Definition: DotBarDisplayLEDs.hpp:32
AH::Array< pin_t, N >
AH::DotBarDisplayLEDs::dotMode
void dotMode()
Set the mode to dot mode.
Definition: DotBarDisplayLEDs.hpp:66
AH::LEDs
A class for collections of LEDs that can display ranges.
Definition: LEDs.hpp:21
AH_DIAGNOSTIC_WERROR
#define AH_DIAGNOSTIC_WERROR()
Definition: Warnings.hpp:16
BEGIN_AH_NAMESPACE
#define BEGIN_AH_NAMESPACE
Definition: AH/Settings/NamespaceSettings.hpp:9
END_AH_NAMESPACE
#define END_AH_NAMESPACE
Definition: AH/Settings/NamespaceSettings.hpp:10
AH::DotBarMode::Dot
Turn on only the active LED.
AH::DotBarDisplayLEDs::display
void display(uint8_t value) const
Display the given number of LEDs on the LED bar.
Definition: DotBarDisplayLEDs.hpp:40
AH::DotBarMode::Bar
Turn on a range of LEDs up to the active LED.
AH::DotBarMode
DotBarMode
An enumeration type to set an LED display to either bar or dot mode.
Definition: DotBarDisplayLEDs.hpp:15
AH::DotBarDisplayLEDs
A class for LED bars.
Definition: DotBarDisplayLEDs.hpp:29