LCOV - code coverage report
Current view: top level - src/MIDI_Outputs/Abstract - MIDIButton.hpp (source / functions) Hit Total Coverage
Test: e224b347cd670555e44f06608ac41bd1ace9d9d8 Lines: 12 12 100.0 %
Date: 2020-09-08 17:44:46 Functions: 10 15 66.7 %
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   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 MIDIAddress &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 :         AH::Button::State state = button.update();
      37           8 :         if (state == AH::Button::Falling) {
      38           2 :             sender.sendOn(address);
      39           8 :         } else if (state == AH::Button::Rising) {
      40           2 :             sender.sendOff(address);
      41           2 :         }
      42           8 :     }
      43             : 
      44             : #ifdef AH_INDIVIDUAL_BUTTON_INVERT
      45             :     void invert() { button.invert(); }
      46             : #endif
      47             : 
      48             :     AH::Button::State getButtonState() const { return button.getState(); }
      49             : 
      50             :   private:
      51             :     AH::Button button;
      52             :     const MIDIAddress address;
      53             : 
      54             :   public:
      55             :     Sender sender;
      56             : };
      57             : 
      58             : END_CS_NAMESPACE

Generated by: LCOV version 1.14-6-g40580cd