LCOV - code coverage report
Current view: top level - src/MIDI_Outputs/Bankable/Abstract - MIDIButtonLatching.hpp (source / functions) Hit Total Coverage
Test: 90a1b9beff85a60dc6ebcea034a947a845e56960 Lines: 12 12 100.0 %
Date: 2019-11-30 15:53:32 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 <Banks/BankableMIDIOutput.hpp>
       5             : #include <Def/Def.hpp>
       6             : #include <MIDI_Outputs/Abstract/MIDIOutputElement.hpp>
       7             : 
       8             : BEGIN_CS_NAMESPACE
       9             : 
      10             : namespace Bankable {
      11             : 
      12             : /**
      13             :  * @brief   A class for latching buttons and switches that send MIDI events.
      14             :  *
      15             :  * The button is debounced.
      16             :  *
      17             :  * @see     AH::Button
      18             :  */
      19             : template <class BankAddress, class Sender>
      20           5 : class MIDIButtonLatching : public MIDIOutputElement {
      21             :   protected:
      22             :     /**
      23             :      * @brief   Construct a new MIDIButtonLatching.
      24             :      *
      25             :      * @param   bankAddress
      26             :      *          The bankable MIDI address to send to.
      27             :      * @param   pin
      28             :      *          The digital input pin with the button connected.
      29             :      *          The internal pull-up resistor will be enabled.
      30             :      * @param   sender
      31             :      *          The MIDI sender to use.
      32             :      */
      33           5 :     MIDIButtonLatching(const BankAddress &bankAddress, pin_t pin,
      34             :                        const Sender &sender)
      35          10 :         : address{bankAddress}, button{pin}, sender{sender} {}
      36             : 
      37             :   public:
      38           3 :     void begin() override { button.begin(); }
      39          12 :     void update() override {
      40          12 :         AH::Button::State state = button.update();
      41          12 :         if (state == AH::Button::Falling || state == AH::Button::Rising) {
      42           6 :             MIDICNChannelAddress sendAddress = address.getActiveAddress();
      43           6 :             sender.sendOn(sendAddress);
      44           6 :             sender.sendOff(sendAddress);
      45           6 :         }
      46          12 :     }
      47             : 
      48             :     AH::Button::State getButtonState() const { return button.getState(); }
      49             : 
      50             :   private:
      51             :     BankAddress address;
      52             :     AH::Button button;
      53             : 
      54             :   public:
      55             :     Sender sender;
      56             : };
      57             : 
      58             : } // namespace Bankable
      59             : 
      60             : END_CS_NAMESPACE

Generated by: LCOV version 1.14-5-g4ff2ed6