LCOV - code coverage report
Current view: top level - src/AH/Hardware/LEDs - DotBarDisplayLEDs.hpp (source / functions) Hit Total Coverage
Test: 90a1b9beff85a60dc6ebcea034a947a845e56960 Lines: 9 10 90.0 %
Date: 2019-11-30 15:53:32 Functions: 5 5 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* ✔ */
       2             : 
       3             : #pragma once
       4             : 
       5             : #include <AH/Settings/Warnings.hpp>
       6             : AH_DIAGNOSTIC_WERROR() // Enable errors on warnings
       7             : 
       8             : #include <AH/Hardware/LEDs/LEDs.hpp>
       9             : 
      10             : BEGIN_AH_NAMESPACE
      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           2 :     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           7 :     void display(uint8_t value) const {
      41           7 :         if (value == 0)
      42           1 :             this->clear();
      43           6 :         else if (mode == DotBarMode::Bar)
      44           6 :             this->displayRange(0, value);
      45             :         else
      46           0 :             this->displayDot(value - 1);
      47           7 :     }
      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           3 :     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           2 :     DotBarMode mode = DotBarMode::Bar;
      73             : };
      74             : 
      75             : END_AH_NAMESPACE
      76             : 
      77             : AH_DIAGNOSTIC_POP()

Generated by: LCOV version 1.14-5-g4ff2ed6