LCOV - code coverage report
Current view: top level - src/MIDI_Outputs/Abstract - MIDIButtonLatching.hpp (source / functions) Hit Total Coverage
Test: 19d2efc7037c2e176feca44750a12594c76f466f Lines: 11 11 100.0 %
Date: 2019-11-24 14:50:27 Functions: 6 10 60.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : #pragma once
       2             : 
       3             : #include <Def/Def.hpp>
       4             : #include <Hardware/Button.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 MIDICNChannelAddress &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 :         Button::State state = button.update();
      38           4 :         if (state == Button::Falling || state == Button::Rising) {
      39           2 :             sender.sendOn(address);
      40           2 :             sender.sendOff(address);
      41           2 :         }
      42           4 :     }
      43             : 
      44             :     Button::State getButtonState() const { return button.getState(); }
      45             : 
      46             :   private:
      47             :     Button button;
      48             :     const MIDICNChannelAddress address;
      49             : 
      50             :   public:
      51             :     Sender sender;
      52             : };
      53             : 
      54             : END_CS_NAMESPACE

Generated by: LCOV version 1.14-5-g4ff2ed6