LCOV - code coverage report
Current view: top level - src/MIDI_Outputs/Bankable/Abstract - MIDIButtonMatrix.hpp (source / functions) Hit Total Coverage
Test: 19d2efc7037c2e176feca44750a12594c76f466f Lines: 19 19 100.0 %
Date: 2019-11-24 14:50:27 Functions: 18 36 50.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/ButtonMatrix.hpp>
       6             : #include <Helpers/Array.hpp>
       7             : #include <MIDI_Outputs/Abstract/MIDIOutputElement.hpp>
       8             : 
       9             : BEGIN_CS_NAMESPACE
      10             : 
      11             : namespace Bankable {
      12             : 
      13             : /**
      14             :  * @brief   MIDIButtonMatrix
      15             :  * @todo    Documentation
      16             :  * @see     ButtonMatrix
      17             :  * 
      18             :  * @tparam  BankAddress
      19             :  *          The bankable address object containing the addresses of all buttons,
      20             :  *          as well as a reference to the bank this element belongs to.
      21             :  * @tparam  Sender
      22             :  *          The MIDI Sender class.
      23             :  * @tparam  nb_rows 
      24             :  *          The number of rows of the button matrix.
      25             :  * @tparam  nb_cols
      26             :  *          The number of columns of the button matrix.
      27             :  */
      28             : template <class BankAddress, class Sender, uint8_t nb_rows, uint8_t nb_cols>
      29           6 : class MIDIButtonMatrix : public MIDIOutputElement,
      30             :                          public ButtonMatrix<nb_rows, nb_cols> {
      31             : 
      32             :   protected:
      33             :     /**
      34             :      * @brief   Create a new Bankable MIDIButtonMatrix.
      35             :      * 
      36             :      * @param   bankAddress
      37             :      *          The bankable MIDI address to send to.
      38             :      * @param   rowPins
      39             :      *          A list of pin numbers connected to the rows of the button
      40             :      *          matrix.  
      41             :      *          **⚠** These pins will be driven LOW as outputs (Lo-Z).
      42             :      * @param   colPins
      43             :      *          A list of pin numbers connected to the columns of the button
      44             :      *          matrix.  
      45             :      *          These pins will be used as inputs (Hi-Z), and the
      46             :      *          internal pull-up resistor will be enabled.
      47             :      * @param   sender
      48             :      *          The MIDI sender to use.
      49             :      */
      50           6 :     MIDIButtonMatrix(const BankAddress &bankAddress,
      51             :                      const PinList<nb_rows> &rowPins,
      52             :                      const PinList<nb_cols> &colPins, const Sender &sender)
      53           6 :         : ButtonMatrix<nb_rows, nb_cols>(rowPins, colPins),
      54          12 :           address{bankAddress}, sender{sender} {}
      55             : 
      56             :   public:
      57           2 :     void begin() override { ButtonMatrix<nb_rows, nb_cols>::begin(); }
      58             : 
      59           8 :     void update() override { ButtonMatrix<nb_rows, nb_cols>::refresh(); }
      60             : 
      61             :   private:
      62           8 :     void onButtonChanged(uint8_t row, uint8_t col, bool state) final override {
      63           8 :         if (state == LOW) {
      64           4 :             if (!activeButtons)
      65           4 :                 address.lock(); // Don't allow changing of the bank setting
      66           4 :             activeButtons++;
      67           4 :             sender.sendOn(address.getActiveAddress(row, col));
      68           4 :         } else {
      69           4 :             sender.sendOff(address.getActiveAddress(row, col));
      70           4 :             activeButtons--;
      71           4 :             if (!activeButtons)
      72           4 :                 address.unlock();
      73             :         }
      74           8 :     }
      75             : 
      76             :     BankAddress address;
      77           6 :     uint16_t activeButtons = 0;
      78             : 
      79             :   public:
      80             :     Sender sender;
      81             : };
      82             : 
      83             : } // namespace Bankable
      84             : 
      85             : END_CS_NAMESPACE

Generated by: LCOV version 1.14-5-g4ff2ed6