Control Surface  1.1.1
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 
15 enum class DotBarMode : bool {
16  Bar = false,
17  Dot = true,
18 };
19 
28 template <uint8_t N>
29 class DotBarDisplayLEDs : public LEDs<N> {
30  public:
32  DotBarDisplayLEDs(const PinList<N> &ledPins) : LEDs<N>{ledPins} {}
33 
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 
55  void display(float value) const { display(uint8_t(value * (N + 1))); }
56 
58  DotBarMode getMode() const { return mode; }
59 
66  void setMode(DotBarMode mode) { this->mode = mode; }
67 
69  void dotMode() { setMode(DotBarMode::Dot); }
70 
72  void barMode() { setMode(DotBarMode::Bar); }
73 
75  void toggleMode() { getMode() == DotBarMode::Bar ? dotMode() : barMode(); }
76 
77  private:
78  DotBarMode mode = DotBarMode::Bar;
79 };
80 
82 
AH::DotBarDisplayLEDs::display
void display(uint8_t value) const
Display the given number of LEDs on the LED bar.
Definition: DotBarDisplayLEDs.hpp:40
Warnings.hpp
AH::DotBarMode::Dot
Turn on only the active LED.
AH::DotBarDisplayLEDs::barMode
void barMode()
Set the mode to bar mode.
Definition: DotBarDisplayLEDs.hpp:72
AH_DIAGNOSTIC_POP
#define AH_DIAGNOSTIC_POP()
Definition: Warnings.hpp:17
AH::DotBarDisplayLEDs::setMode
void setMode(DotBarMode mode)
Set the mode to either dot or bar mode.
Definition: DotBarDisplayLEDs.hpp:66
AH::DotBarDisplayLEDs::display
void display(float value) const
Display the given fraction of the LED bar.
Definition: DotBarDisplayLEDs.hpp:55
AH::DotBarMode
DotBarMode
An enumeration type to set an LED display to either bar or dot mode.
Definition: DotBarDisplayLEDs.hpp:15
AH::DotBarDisplayLEDs::DotBarDisplayLEDs
DotBarDisplayLEDs(const PinList< N > &ledPins)
Constructor from list of pins.
Definition: DotBarDisplayLEDs.hpp:32
AH::Array< pin_t, N >
AH::DotBarMode::Bar
Turn on a range of LEDs up to the active LED.
AH::DotBarDisplayLEDs::toggleMode
void toggleMode()
Toggle the dot/bar mode.
Definition: DotBarDisplayLEDs.hpp:75
AH::DotBarDisplayLEDs::getMode
DotBarMode getMode() const
Get the dot/bar mode.
Definition: DotBarDisplayLEDs.hpp:58
AH::DotBarDisplayLEDs::dotMode
void dotMode()
Set the mode to dot mode.
Definition: DotBarDisplayLEDs.hpp:69
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::DotBarDisplayLEDs
A class for LED bars.
Definition: DotBarDisplayLEDs.hpp:29