Control Surface
main
MIDI Control Surface library for Arduino
Toggle main menu visibility
Loading...
Searching...
No Matches
src
AH
Hardware
ButtonMatrix.hpp
Go to the documentation of this file.
1
/* ✔ */
2
3
#pragma once
4
5
#include <
AH/Hardware/Hardware-Types.hpp
>
6
7
BEGIN_AH_NAMESPACE
8
19
template
<
class
Derived, u
int
8_t NumRows, u
int
8_t NumCols>
20
class
ButtonMatrix
{
21
public
:
35
ButtonMatrix
(
const
PinList<NumRows>
&
rowPins
,
36
const
PinList<NumCols>
&
colPins
);
37
41
void
begin
();
42
47
void
update
();
48
54
bool
getPrevState
(uint8_t col, uint8_t row);
55
58
void
setDebounceTime
(
unsigned
long
debounceTime
) {
59
this->debounceTime =
debounceTime
;
60
}
61
62
unsigned
long
getDebounceTime
()
const
{
return
debounceTime
; }
63
64
protected
:
76
void
onButtonChanged
(uint8_t row, uint8_t col,
bool
state) =
delete
;
77
78
private
:
79
static
inline
uint8_t
positionToBits
(uint8_t col, uint8_t row);
80
static
inline
uint8_t
bitsToIndex
(uint8_t bits);
81
static
inline
uint8_t
bitsToBitmask
(uint8_t bits);
82
void
setPrevState
(uint8_t col, uint8_t row,
bool
state);
83
84
unsigned
long
debounceTime
=
BUTTON_DEBOUNCE_TIME
;
85
unsigned
long
prevRefresh
= 0;
86
uint8_t
prevStates
[(NumCols * NumRows + 7) / 8];
87
88
const
PinList<NumRows>
rowPins
;
89
const
PinList<NumCols>
colPins
;
90
};
91
92
END_AH_NAMESPACE
93
94
#include "ButtonMatrix.ipp"
// Template implementations
END_AH_NAMESPACE
#define END_AH_NAMESPACE
Definition
AH/Settings/NamespaceSettings.hpp:14
BEGIN_AH_NAMESPACE
#define BEGIN_AH_NAMESPACE
Definition
AH/Settings/NamespaceSettings.hpp:11
Hardware-Types.hpp
::ButtonMatrix
A class that reads the states of a button matrix.
Definition
ButtonMatrix.hpp:20
AH::ButtonMatrix::ButtonMatrix
ButtonMatrix(const PinList< NumRows > &rowPins, const PinList< NumCols > &colPins)
Construct a new ButtonMatrix object.
AH::ButtonMatrix::setPrevState
void setPrevState(uint8_t col, uint8_t row, bool state)
AH::ButtonMatrix::setDebounceTime
void setDebounceTime(unsigned long debounceTime)
Configure the debounce time interval.
Definition
ButtonMatrix.hpp:58
AH::ButtonMatrix< MIDIButtonMatrix, NumRows, NumCols >::prevRefresh
unsigned long prevRefresh
Definition
ButtonMatrix.hpp:85
AH::ButtonMatrix::getPrevState
bool getPrevState(uint8_t col, uint8_t row)
Get the state of the button in the given column and row.
AH::ButtonMatrix< MIDIButtonMatrix, NumRows, NumCols >::prevStates
uint8_t prevStates[(NumCols *NumRows+7)/8]
Definition
ButtonMatrix.hpp:86
AH::ButtonMatrix::bitsToIndex
static uint8_t bitsToIndex(uint8_t bits)
AH::ButtonMatrix::getDebounceTime
unsigned long getDebounceTime() const
Get the debounce time.
Definition
ButtonMatrix.hpp:62
AH::ButtonMatrix::bitsToBitmask
static uint8_t bitsToBitmask(uint8_t bits)
AH::ButtonMatrix::onButtonChanged
void onButtonChanged(uint8_t row, uint8_t col, bool state)=delete
The callback function that is called whenever a button changes state.
AH::ButtonMatrix::begin
void begin()
Initialize (enable internal pull-up resistors on column pins).
AH::ButtonMatrix::positionToBits
static uint8_t positionToBits(uint8_t col, uint8_t row)
AH::ButtonMatrix::update
void update()
Scan the matrix, read all button states, and call the onButtonChanged callback.
AH::ButtonMatrix< MIDIButtonMatrix, NumRows, NumCols >::rowPins
const PinList< NumRows > rowPins
Definition
ButtonMatrix.hpp:88
AH::ButtonMatrix< MIDIButtonMatrix, NumRows, NumCols >::colPins
const PinList< NumCols > colPins
Definition
ButtonMatrix.hpp:89
AH::ButtonMatrix< MIDIButtonMatrix, NumRows, NumCols >::debounceTime
unsigned long debounceTime
Definition
ButtonMatrix.hpp:84
AH::PinList
Array< pin_t, N > PinList
An easy alias for arrays of pins.
Definition
Hardware-Types.hpp:100
AH::BUTTON_DEBOUNCE_TIME
constexpr unsigned long BUTTON_DEBOUNCE_TIME
The debounce time for momentary push buttons in milliseconds.
Definition
AH/Settings/Settings.hpp:76
Generated by
1.17.0