LCOV - code coverage report
Current view: top level - src/MIDI_Outputs/Abstract - MIDIButton.hpp (source / functions) Hit Total Coverage
Test: 19d2efc7037c2e176feca44750a12594c76f466f Lines: 12 12 100.0 %
Date: 2019-11-24 14:50:27 Functions: 10 15 66.7 %
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   An abstract class for momentary push buttons that send MIDI events.
      11             :  *
      12             :  * The button is debounced.
      13             :  *
      14             :  * @see     Button
      15             :  */
      16             : template <class Sender>
      17           5 : class MIDIButton : public MIDIOutputElement {
      18             :   public:
      19             :     /**
      20             :      * @brief   Construct a new MIDIButton.
      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           5 :     MIDIButton(pin_t pin, const MIDICNChannelAddress &address,
      31             :                const Sender &sender)
      32          10 :         : button{pin}, address{address}, sender{sender} {}
      33             : 
      34           2 :     void begin() override { button.begin(); }
      35           8 :     void update() override {
      36           8 :         Button::State state = button.update();
      37           8 :         if (state == Button::Falling) {
      38           2 :             sender.sendOn(address);
      39           8 :         } else if (state == Button::Rising) {
      40           2 :             sender.sendOff(address);
      41           2 :         }
      42           8 :     }
      43             : 
      44             : #ifdef INDIVIDUAL_BUTTON_INVERT
      45             :     void invert() { button.invert(); }
      46             : #endif
      47             : 
      48             :     Button::State getButtonState() const { return button.getState(); }
      49             : 
      50             :   private:
      51             :     Button button;
      52             :     const MIDICNChannelAddress address;
      53             : 
      54             :   public:
      55             :     Sender sender;
      56             : };
      57             : 
      58             : END_CS_NAMESPACE

Generated by: LCOV version 1.14-5-g4ff2ed6