Control Surface  1.1.1
MIDI Control Surface library for Arduino
ButtonMatrix.hpp
Go to the documentation of this file.
1 /* ✔ */
2 
3 #pragma once
4 
6 AH_DIAGNOSTIC_WERROR() // Enable errors on warnings
7 
8 #include <AH/Hardware/Hardware-Types.hpp>
9 
11 
22 template <uint8_t nb_rows, uint8_t nb_cols>
23 class ButtonMatrix {
24  public:
38  ButtonMatrix(const PinList<nb_rows> &rowPins,
39  const PinList<nb_cols> &colPins);
43  virtual ~ButtonMatrix() = default;
44 
48  void begin();
49 
54  void update();
55 
61  bool getPrevState(uint8_t col, uint8_t row);
62 
63  private:
75  virtual void onButtonChanged(uint8_t row, uint8_t col, bool state) = 0;
76 
77  static inline uint8_t positionToBits(uint8_t col, uint8_t row);
78  static inline uint8_t bitsToIndex(uint8_t bits);
79  static inline uint8_t bitsToBitmask(uint8_t bits);
80  void setPrevState(uint8_t col, uint8_t row, bool state);
81 
82  unsigned long prevRefresh = 0;
83  uint8_t prevStates[(nb_cols * nb_rows + 7) / 8];
84 
87 };
88 
90 
91 #include "ButtonMatrix.ipp" // Template implementations
92 
Warnings.hpp
AH_DIAGNOSTIC_POP
#define AH_DIAGNOSTIC_POP()
Definition: Warnings.hpp:17
AH::ButtonMatrix::colPins
const PinList< nb_cols > colPins
Definition: ButtonMatrix.hpp:86
AH::Array< pin_t, N >
AH_DIAGNOSTIC_WERROR
#define AH_DIAGNOSTIC_WERROR()
Definition: Warnings.hpp:16
ButtonMatrix.ipp
BEGIN_AH_NAMESPACE
#define BEGIN_AH_NAMESPACE
Definition: AH/Settings/NamespaceSettings.hpp:9
END_AH_NAMESPACE
#define END_AH_NAMESPACE
Definition: AH/Settings/NamespaceSettings.hpp:10
AH::ButtonMatrix::rowPins
const PinList< nb_rows > rowPins
Definition: ButtonMatrix.hpp:85
AH::ButtonMatrix
A class that reads the states of a button matrix.
Definition: ButtonMatrix.hpp:23