LCOV - code coverage report
Current view: top level - src/MIDI_Outputs/Bankable/Abstract - MIDIButtonLatching.hpp (source / functions) Hit Total Coverage
Test: 19d2efc7037c2e176feca44750a12594c76f466f Lines: 12 12 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 <Banks/BankableMIDIOutput.hpp>
       4             : #include <Def/Def.hpp>
       5             : #include <Hardware/Button.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     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 :         Button::State state = button.update();
      41          12 :         if (state == Button::Falling || state == Button::Rising) {
      42           6 :             MIDICNChannelAddress sendAddress = address.getActiveAddress();
      43           6 :             sender.sendOn(sendAddress);
      44           6 :             sender.sendOff(sendAddress);
      45           6 :         }
      46          12 :     }
      47             : 
      48             :     Button::State getButtonState() const { return button.getState(); }
      49             : 
      50             :   private:
      51             :     BankAddress address;
      52             :     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