LCOV - code coverage report
Current view: top level - src/MIDI_Outputs/Bankable/Abstract - MIDIButton.hpp (source / functions) Coverage Total Hit
Test: 73449d9b107c772cf65493691543348214e5d5eb Lines: 100.0 % 12 12
Test Date: 2026-06-06 17:44:35 Functions: 55.6 % 18 10
Legend: Lines:     hit not hit

            Line data    Source code
       1              : #pragma once
       2              : 
       3              : #include <AH/Hardware/Button.hpp>
       4              : #include <Banks/BankableAddresses.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              : 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(BankAddress bankAddress, pin_t pin, const Sender &sender)
      34           12 :         : 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           19 :         } else if (state == AH::Button::Rising) {
      43            7 :             sender.sendOff(address.getActiveAddress());
      44            7 :             address.unlock();
      45              :         }
      46           26 :     }
      47              : 
      48              :     /// @see @ref AH::Button::invert()
      49              :     void invert() { button.invert(); }
      50              : 
      51              :     AH::Button::State getButtonState() const { return button.getState(); }
      52              : 
      53              :   protected:
      54              :     BankAddress address;
      55              :     AH::Button button;
      56              : 
      57              :   public:
      58              :     Sender sender;
      59              : };
      60              : 
      61              : } // namespace Bankable
      62              : 
      63              : END_CS_NAMESPACE
        

Generated by: LCOV version 2.4-beta