Control Surface  1.1.1
MIDI Control Surface library for Arduino
Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
ButtonMatrix< nb_rows, nb_cols > Class Template Referenceabstract

A class that reads the states of a button matrix. More...

#include <AH/Hardware/ButtonMatrix.hpp>

Inheritance diagram for ButtonMatrix< nb_rows, nb_cols >:
Collaboration diagram for ButtonMatrix< nb_rows, nb_cols >:

Public Member Functions

 ButtonMatrix (const PinList< nb_rows > &rowPins, const PinList< nb_cols > &colPins)
 Construct a new ButtonMatrix object. More...
 
virtual ~ButtonMatrix ()=default
 Destructor. More...
 
void begin ()
 Initialize (enable internal pull-up resistors on column pins). More...
 
void update ()
 Scan the matrix, read all button states, and call the onButtonChanged callback. More...
 
bool getPrevState (uint8_t col, uint8_t row)
 Get the state of the button in the given column and row. More...
 

Private Member Functions

virtual void onButtonChanged (uint8_t row, uint8_t col, bool state)=0
 The callback function that is called whenever a button changes state. More...
 
void setPrevState (uint8_t col, uint8_t row, bool state)
 

Static Private Member Functions

static uint8_t positionToBits (uint8_t col, uint8_t row)
 
static uint8_t bitsToIndex (uint8_t bits)
 
static uint8_t bitsToBitmask (uint8_t bits)
 

Private Attributes

unsigned long prevRefresh = 0
 
uint8_t prevStates [(nb_cols *nb_rows+7)/8]
 
const PinList< nb_rows > rowPins
 
const PinList< nb_cols > colPins
 

Detailed Description

template<uint8_t nb_rows, uint8_t nb_cols>
class AH::ButtonMatrix< nb_rows, nb_cols >

A class that reads the states of a button matrix.

Template Parameters
nb_rowsThe number of rows in the button matrix.
nb_colsThe number of columns in the button matrix.

Definition at line 23 of file ButtonMatrix.hpp.

Constructor & Destructor Documentation

◆ ButtonMatrix()

ButtonMatrix ( const PinList< nb_rows > &  rowPins,
const PinList< nb_cols > &  colPins 
)

Construct a new ButtonMatrix object.

Parameters
rowPinsA list of pin numbers connected to the rows of the button matrix.
These pins will be driven LOW as outputs (Lo-Z).
colPinsA list of pin numbers connected to the columns of the button matrix.
These pins will be used as inputs (Hi-Z), and the internal pull-up resistor will be enabled.

Definition at line 10 of file ButtonMatrix.ipp.

◆ ~ButtonMatrix()

virtual ~ButtonMatrix ( )
virtualdefault

Destructor.

Member Function Documentation

◆ begin()

void begin ( )

Initialize (enable internal pull-up resistors on column pins).

Definition at line 41 of file ButtonMatrix.ipp.

◆ update()

void update ( )

Scan the matrix, read all button states, and call the onButtonChanged callback.

Definition at line 17 of file ButtonMatrix.ipp.

◆ getPrevState()

bool getPrevState ( uint8_t  col,
uint8_t  row 
)

Get the state of the button in the given column and row.

Note
No bounds checking is performed.

Definition at line 69 of file ButtonMatrix.ipp.

◆ onButtonChanged()

virtual void onButtonChanged ( uint8_t  row,
uint8_t  col,
bool  state 
)
privatepure virtual

◆ positionToBits()

uint8_t positionToBits ( uint8_t  col,
uint8_t  row 
)
inlinestaticprivate

Definition at line 52 of file ButtonMatrix.ipp.

◆ bitsToIndex()

uint8_t bitsToIndex ( uint8_t  bits)
inlinestaticprivate

Definition at line 59 of file ButtonMatrix.ipp.

◆ bitsToBitmask()

uint8_t bitsToBitmask ( uint8_t  bits)
inlinestaticprivate

Definition at line 64 of file ButtonMatrix.ipp.

◆ setPrevState()

void setPrevState ( uint8_t  col,
uint8_t  row,
bool  state 
)
private

Definition at line 75 of file ButtonMatrix.ipp.

Member Data Documentation

◆ prevRefresh

unsigned long prevRefresh = 0
private

Definition at line 82 of file ButtonMatrix.hpp.

◆ prevStates

uint8_t prevStates[(nb_cols *nb_rows+7)/8]
private

Definition at line 83 of file ButtonMatrix.hpp.

◆ rowPins

const PinList<nb_rows> rowPins
private

Definition at line 85 of file ButtonMatrix.hpp.

◆ colPins

const PinList<nb_cols> colPins
private

Definition at line 86 of file ButtonMatrix.hpp.


The documentation for this class was generated from the following files: