LCOV - code coverage report
Current view: top level - src/Hardware/LEDs - DotBarDisplayLEDs.hpp (source / functions) Hit Total Coverage
Test: 19d2efc7037c2e176feca44750a12594c76f466f Lines: 7 9 77.8 %
Date: 2019-11-24 14:50:27 Functions: 2 2 100.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.14-5-g4ff2ed6