LCOV - code coverage report
Current view: top level - src/Selectors - IncrementDecrementSelector.hpp (source / functions) Hit Total Coverage
Test: 169c36a3797bc662d84b5726f34a3f37d3c58247 Lines: 19 20 95.0 %
Date: 2024-11-09 15:32:27 Functions: 11 15 73.3 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : #pragma once
       2             : 
       3             : #include "Selector.hpp"
       4             : #include <AH/Hardware/IncrementDecrementButtons.hpp>
       5             : 
       6             : BEGIN_CS_NAMESPACE
       7             : 
       8             : template <setting_t N, class Callback = EmptySelectorCallback>
       9             : class GenericIncrementDecrementSelector : public GenericSelector<N, Callback> {
      10             :     using Parent = GenericSelector<N, Callback>;
      11             : 
      12             :   public:
      13           7 :     GenericIncrementDecrementSelector(
      14             :         Selectable<N> &selectable, const Callback &callback,
      15             :         const AH::IncrementDecrementButtons &buttons, Wrap wrap = Wrap::Wrap)
      16           7 :         : GenericSelector<N, Callback> {selectable, callback}, buttons(buttons),
      17          14 :           wrap(wrap) {}
      18             : 
      19           5 :     void begin() override {
      20           5 :         Parent::begin();
      21           5 :         buttons.begin();
      22           5 :     }
      23             : 
      24          19 :     void update() override {
      25          19 :         Parent::update();
      26             :         using IncrDecrButtons = AH::IncrementDecrementButtons;
      27          19 :         switch (buttons.update()) {
      28           8 :             case IncrDecrButtons::Nothing: break;
      29           5 :             case IncrDecrButtons::IncrementShort: // fallthrough
      30             :             case IncrDecrButtons::IncrementLong:  // fallthrough
      31           5 :             case IncrDecrButtons::IncrementHold: this->increment(wrap); break;
      32           5 :             case IncrDecrButtons::DecrementShort: // fallthrough
      33             :             case IncrDecrButtons::DecrementLong:  // fallthrough
      34           5 :             case IncrDecrButtons::DecrementHold: this->decrement(wrap); break;
      35           1 :             case IncrDecrButtons::Reset: this->reset(); break;
      36           0 :             default: break;
      37             :         }
      38          19 :     }
      39             : 
      40             :     /// @see @ref AH::Button::invert()
      41             :     void invert() { buttons.invert(); }
      42             : 
      43             :     AH::IncrementDecrementButtons::State getButtonsState() const {
      44             :         return buttons.getState();
      45             :     }
      46             : 
      47             :   private:
      48             :     AH::IncrementDecrementButtons buttons;
      49             :     Wrap wrap;
      50             : };
      51             : 
      52             : // -------------------------------------------------------------------------- //
      53             : 
      54             : /**
      55             :  * @brief   Selector with two buttons (one to increment, one to decrement).
      56             :  * 
      57             :  * Pressing two buttons simultaneously resets to the default setting.
      58             :  * 
      59             :  * @htmlonly 
      60             :  * <object type="image/svg+xml" data="../../selector-increment-decrement-LED.svg"></object>
      61             :  * @endhtmlonly
      62             :  * 
      63             :  * @ingroup Selectors 
      64             :  * 
      65             :  * @tparam  N 
      66             :  *          The number of settings.
      67             :  */
      68             : template <setting_t N>
      69             : class IncrementDecrementSelector : public GenericIncrementDecrementSelector<N> {
      70             :   public:
      71           6 :     IncrementDecrementSelector(Selectable<N> &selectable,
      72             :                                const AH::IncrementDecrementButtons &buttons,
      73             :                                Wrap wrap = Wrap::Wrap)
      74             :         : GenericIncrementDecrementSelector<N> {
      75             :               selectable,
      76             :               {},
      77             :               buttons,
      78             :               wrap,
      79           6 :           } {}
      80             : };
      81             : 
      82             : END_CS_NAMESPACE

Generated by: LCOV version 1.15