LCOV - code coverage report
Current view: top level - src/Selectors - SwitchSelector.hpp (source / functions) Hit Total Coverage
Test: 90a1b9beff85a60dc6ebcea034a947a845e56960 Lines: 9 21 42.9 %
Date: 2019-11-30 15:53:32 Functions: 6 13 46.2 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : #pragma once
       2             : 
       3             : #include "Selector.hpp"
       4             : #include <AH/Hardware/Button.hpp>
       5             : 
       6             : BEGIN_CS_NAMESPACE
       7             : 
       8             : template <class Callback = EmptySelectorCallback>
       9           2 : class GenericSwitchSelector : public GenericSelector<2, Callback> {
      10             :     using Parent = GenericSelector<2, Callback>;
      11             : 
      12             :   public:
      13           2 :     GenericSwitchSelector(Selectable<2> &selectable, const Callback &callback,
      14             :                           const AH::Button &button)
      15           2 :         : GenericSelector<2, Callback>{selectable, callback}, button{button} {}
      16             : 
      17           0 :     void begin() override {
      18           0 :         Parent::begin();
      19           0 :         button.begin();
      20           0 :     }
      21             : 
      22           0 :     void update() override {
      23           0 :         Parent::update();
      24           0 :         AH::Button::State state = button.update();
      25           0 :         if (state == AH::Button::Falling)
      26           0 :             this->set(1);
      27           0 :         else if (state == AH::Button::Rising)
      28           0 :             this->set(0);
      29           0 :     }
      30             : 
      31             :     AH::Button::State getButtonState() const { return button.getState(); }
      32             : 
      33             : #ifdef INDIVIDUAL_BUTTON_INVERT
      34             :     void invert() { button.invert(); }
      35             : #endif
      36             : 
      37             :   private:
      38             :     AH::Button button;
      39             : };
      40             : 
      41             : /**
      42             :  * @brief   Selector that selects one of two settings, based on the state of a 
      43             :  *          toggle or momentary switch.
      44             :  * 
      45             :  * @htmlonly 
      46             :  * <object type="image/svg+xml" data="../../selector-one-toggle-switch-LED.svg"></object>
      47             :  * @endhtmlonly
      48             :  * 
      49             :  * @ingroup Selectors
      50             :  */
      51           1 : class SwitchSelector : public GenericSwitchSelector<> {
      52             :   public:
      53           1 :     SwitchSelector(Selectable<2> &selectable, const AH::Button &button)
      54           1 :         : GenericSwitchSelector<>{
      55           1 :               selectable,
      56             :               {},
      57           1 :               button,
      58           2 :           } {}
      59             : };
      60             : 
      61             : END_CS_NAMESPACE

Generated by: LCOV version 1.14-5-g4ff2ed6