LCOV - code coverage report
Current view: top level - src/Selectors - IncrementSelector.hpp (source / functions) Hit Total Coverage
Test: b8a30b4b7040ae1abf162fd0a258beaa2de43626 Lines: 19 21 90.5 %
Date: 2024-12-21 21:28:55 Functions: 7 11 63.6 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.15