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

          Line data    Source code
       1             : /* ✔ */
       2             : 
       3             : #pragma once
       4             : 
       5             : #include "Button.hpp"
       6             : 
       7             : BEGIN_CS_NAMESPACE
       8             : 
       9             : /**
      10             :  * @brief   A class for buttons that increment some counter or setting.
      11             :  * 
      12             :  * It behaves the same way as a computer keyboard: when you press the button, 
      13             :  * it increments the counter once. If you keep on pressing it for longer than
      14             :  * a certain threshold, it keeps on incrementing at a faster rate, until you
      15             :  * release it.
      16             :  * 
      17             :  * @ingroup HardwareUtils
      18             :  */
      19             : class IncrementButton {
      20             :   public:
      21             :     /** 
      22             :      * @brief   Create a IncrementButton.
      23             :      * 
      24             :      * @param   button
      25             :      *          The button to read from.  
      26             :      *          The button is copied.
      27             :      */
      28           4 :     IncrementButton(const Button &button) : button(button) {}
      29             : 
      30             :     /// @see     Button::begin
      31           2 :     void begin() { button.begin(); }
      32             : 
      33             :     /**
      34             :      * @brief   An enumeration of the different actions to be performed by the
      35             :      *          counter.
      36             :      * @todo    Add states for initial press.
      37             :      */
      38             :     enum State {
      39             :         Nothing = 0, ///< The counter must not be incremented.
      40             :         Increment,   ///< The counter must be incremented.
      41             :     };
      42             : 
      43             :     /**
      44             :      * @brief   Update and return the state of the increment button.
      45             :      */
      46          12 :     State update() { return state = updateImplementation(); }
      47             : 
      48             :     /**
      49             :      * @brief   Return the state of the increment button without updating it.
      50             :      * 
      51             :      * Returns the same value as the last @ref update call.
      52             :      */
      53             :     State getState() const { return state; }
      54             : 
      55             : #ifdef INDIVIDUAL_BUTTON_INVERT
      56             :     /// @see    Button::invert
      57             :     void invert() { button.invert(); }
      58             : #endif
      59             : 
      60             :   protected:
      61             :     State updateImplementation();
      62             : 
      63             :   private:
      64             :     Button button;
      65             : 
      66             :     enum {
      67             :         Initial,
      68             :         LongPress,
      69           4 :     } longPressState = Initial;
      70             :     unsigned long longPressRepeat;
      71             : 
      72           4 :     State state = Nothing;
      73             : };
      74             : 
      75             : END_CS_NAMESPACE

Generated by: LCOV version 1.14-5-g4ff2ed6