LCOV - code coverage report
Current view: top level - src/MIDI_Outputs/Bankable/Abstract - MIDIButton.hpp (source / functions) Hit Total Coverage
Test: 90a1b9beff85a60dc6ebcea034a947a845e56960 Lines: 14 14 100.0 %
Date: 2019-11-30 15:53:32 Functions: 16 30 53.3 %
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   An abstract class for momentary push buttons that send MIDI events.
      14             :  *
      15             :  * The button is debounced.
      16             :  *
      17             :  * @see     Button
      18             :  */
      19             : template <class BankAddress, class Sender>
      20          12 : class MIDIButton : public MIDIOutputElement {
      21             :   public:
      22             :     /**
      23             :      * @brief   Construct a new bankable MIDIButton.
      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          12 :     MIDIButton(const BankAddress &bankAddress, pin_t pin, const Sender &sender)
      34          24 :         : address{bankAddress}, button{pin}, sender(sender) {}
      35             : 
      36           6 :     void begin() override { button.begin(); }
      37          26 :     void update() override {
      38          26 :         AH::Button::State state = button.update();
      39          26 :         if (state == AH::Button::Falling) {
      40           7 :             address.lock();
      41           7 :             sender.sendOn(address.getActiveAddress());
      42          26 :         } else if (state == AH::Button::Rising) {
      43           7 :             sender.sendOff(address.getActiveAddress());
      44           7 :             address.unlock();
      45           7 :         }
      46          26 :     }
      47             : 
      48             : #ifdef INDIVIDUAL_BUTTON_INVERT
      49             :     void invert() { button.invert(); }
      50             : #endif
      51             : 
      52             :     AH::Button::State getButtonState() const { return button.getState(); }
      53             : 
      54             :   private:
      55             :     BankAddress address;
      56             :     AH::Button button;
      57             : 
      58             :   public:
      59             :     Sender sender;
      60             : };
      61             : 
      62             : } // namespace Bankable
      63             : 
      64             : END_CS_NAMESPACE

Generated by: LCOV version 1.14-5-g4ff2ed6