Line data Source code
1 : #pragma once 2 : 3 : #include <AH/Hardware/ButtonMatrix.hpp> 4 : #include <Def/Def.hpp> 5 : #include <MIDI_Outputs/Abstract/MIDIOutputElement.hpp> 6 : 7 : BEGIN_CS_NAMESPACE 8 : 9 : /** 10 : * @brief MIDIButtonMatrix 11 : * @todo Documentation. 12 : * @see AH::ButtonMatrix 13 : */ 14 : template <class Sender, uint8_t nb_rows, uint8_t nb_cols> 15 3 : class MIDIButtonMatrix : public MIDIOutputElement, 16 : public AH::ButtonMatrix<nb_rows, nb_cols> { 17 : 18 : protected: 19 : /** 20 : * @brief Construct a new MIDIButtonMatrix. 21 : * 22 : * @param rowPins 23 : * A list of pin numbers connected to the rows of the button 24 : * matrix. 25 : * **⚠** These pins will be driven LOW as outputs (Lo-Z). 26 : * @param colPins 27 : * A list of pin numbers connected to the columns of the button 28 : * matrix. 29 : * These pins will be used as inputs (Hi-Z), and the internal 30 : * pull-up resistor will be enabled. 31 : * @param addresses 32 : * A matrix containing the address corresponding to each button. 33 : * @param channelCN 34 : * The MIDI channel and optional cable number for all buttons. 35 : * @param sender 36 : * The MIDI sender to use. 37 : */ 38 3 : MIDIButtonMatrix(const PinList<nb_rows> &rowPins, 39 : const PinList<nb_cols> &colPins, 40 : const AddressMatrix<nb_rows, nb_cols> &addresses, 41 : MIDIChannelCN channelCN, const Sender &sender) 42 3 : : AH::ButtonMatrix<nb_rows, nb_cols>(rowPins, colPins), 43 6 : addresses(addresses), baseChannelCN(channelCN), sender{sender} {} 44 : 45 : public: 46 1 : void begin() final override { AH::ButtonMatrix<nb_rows, nb_cols>::begin(); } 47 : 48 2 : void update() final override { 49 2 : AH::ButtonMatrix<nb_rows, nb_cols>::update(); 50 2 : } 51 : 52 : private: 53 2 : void onButtonChanged(uint8_t row, uint8_t col, bool state) final override { 54 2 : int8_t address = addresses[row][col]; 55 2 : if (state == LOW) 56 1 : sender.sendOn({address, baseChannelCN}); 57 : else 58 1 : sender.sendOff({address, baseChannelCN}); 59 2 : } 60 : 61 : AddressMatrix<nb_rows, nb_cols> addresses; 62 : MIDIChannelCN baseChannelCN; 63 : 64 : public: 65 : Sender sender; 66 : }; 67 : 68 : END_CS_NAMESPACE