Line data Source code
1 : #pragma once 2 : 3 : #include <Def/Def.hpp> 4 : #include <Hardware/ButtonMatrix.hpp> 5 : #include <MIDI_Outputs/Abstract/MIDIOutputElement.hpp> 6 : 7 : BEGIN_CS_NAMESPACE 8 : 9 : /** 10 : * @brief MIDIButtonMatrix 11 : * @todo Documentation. 12 : * @see ButtonMatrix 13 : */ 14 : template <class Sender, uint8_t nb_rows, uint8_t nb_cols> 15 3 : class MIDIButtonMatrix : public MIDIOutputElement, 16 : public ButtonMatrix<nb_rows, nb_cols> { 17 : 18 : protected: 19 : /** 20 : * @brief 21 : * @todo Documentation 22 : */ 23 3 : MIDIButtonMatrix(const PinList<nb_rows> &rowPins, 24 : const PinList<nb_cols> &colPins, 25 : const AddressMatrix<nb_rows, nb_cols> &addresses, 26 : MIDICNChannel channelCN, const Sender &sender) 27 3 : : ButtonMatrix<nb_rows, nb_cols>(rowPins, colPins), 28 6 : addresses(addresses), baseChannelCN(channelCN), sender{sender} {} 29 : 30 : public: 31 1 : void begin() final override { ButtonMatrix<nb_rows, nb_cols>::begin(); } 32 : 33 2 : void update() final override { ButtonMatrix<nb_rows, nb_cols>::refresh(); } 34 : 35 : private: 36 2 : void onButtonChanged(uint8_t row, uint8_t col, bool state) final override { 37 2 : int8_t address = addresses[row][col]; 38 2 : if (state == LOW) 39 1 : sender.sendOn({address, baseChannelCN}); 40 : else 41 1 : sender.sendOff({address, baseChannelCN}); 42 2 : } 43 : 44 : AddressMatrix<nb_rows, nb_cols> addresses; 45 : const MIDICNChannel baseChannelCN; 46 : 47 : public: 48 : Sender sender; 49 : }; 50 : 51 : END_CS_NAMESPACE