LCOV - code coverage report
Current view: top level - src/MIDI_Outputs/Abstract - MIDIButtonLatching.hpp (source / functions) Hit Total Coverage
Test: e224b347cd670555e44f06608ac41bd1ace9d9d8 Lines: 11 11 100.0 %
Date: 2020-09-08 17:44:46 Functions: 6 10 60.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : #pragma once
       2             : 
       3             : #include <AH/Hardware/Button.hpp>
       4             : #include <Def/Def.hpp>
       5             : #include <MIDI_Outputs/Abstract/MIDIOutputElement.hpp>
       6             : 
       7             : BEGIN_CS_NAMESPACE
       8             : 
       9             : /**
      10             :  * @brief   A class for latching buttons and switches that send MIDI events.
      11             :  *
      12             :  * The button is debounced.
      13             :  *
      14             :  * @see     Button
      15             :  */
      16             : template <class Sender>
      17           3 : class MIDIButtonLatching : public MIDIOutputElement {
      18             :   protected:
      19             :     /**
      20             :      * @brief   Construct a new MIDIButtonLatching.
      21             :      *
      22             :      * @param   pin
      23             :      *          The digital input pin with the button connected.
      24             :      *          The internal pull-up resistor will be enabled.
      25             :      * @param   address
      26             :      *          The MIDI address to send to.
      27             :      * @param   sender
      28             :      *          The MIDI sender to use.
      29             :      */
      30           3 :     MIDIButtonLatching(pin_t pin, const MIDIAddress &address,
      31             :                        const Sender &sender)
      32           6 :         : button{pin}, address(address), sender{sender} {}
      33             : 
      34             :   public:
      35           1 :     void begin() override { button.begin(); }
      36           4 :     void update() override {
      37           4 :         AH::Button::State state = button.update();
      38           4 :         if (state == AH::Button::Falling || state == AH::Button::Rising) {
      39           2 :             sender.sendOn(address);
      40           2 :             sender.sendOff(address);
      41           2 :         }
      42           4 :     }
      43             : 
      44             :     AH::Button::State getButtonState() const { return button.getState(); }
      45             : 
      46             :   private:
      47             :     AH::Button button;
      48             :     const MIDIAddress address;
      49             : 
      50             :   public:
      51             :     Sender sender;
      52             : };
      53             : 
      54             : END_CS_NAMESPACE

Generated by: LCOV version 1.14-6-g40580cd