2021-11-22 19:12:44 +00:00
|
|
|
// "Readers" represent different methods for reading the state of a pin.
|
|
|
|
// They also include debouncing logic using the Bounce2 library, when appropriate.
|
|
|
|
|
|
|
|
#ifndef _READER_H_
|
|
|
|
#define _READER_H_
|
|
|
|
|
2021-11-22 20:10:08 +00:00
|
|
|
#include "Matrix.h"
|
|
|
|
#include <Arduino.h>
|
2021-11-22 19:12:44 +00:00
|
|
|
#include <Bounce2.h>
|
|
|
|
#include <Mux.h>
|
|
|
|
|
2021-11-22 20:10:08 +00:00
|
|
|
using namespace admux;
|
|
|
|
|
2021-11-22 19:12:44 +00:00
|
|
|
// The abstract base class - a very simple interface
|
|
|
|
class Reader {
|
|
|
|
public:
|
|
|
|
Reader(bool inverted);
|
|
|
|
|
|
|
|
virtual bool Update() = 0; // should return true if the state of the pin has changed
|
|
|
|
bool On();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
uint8_t getMode(bool pullup);
|
|
|
|
|
|
|
|
Bounce bouncer;
|
|
|
|
bool inverted;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// A standard reader; the button is connected directly to a switch
|
2021-11-22 20:10:08 +00:00
|
|
|
class DirectReader : public Reader {
|
2021-11-22 19:12:44 +00:00
|
|
|
public:
|
|
|
|
DirectReader(uint8_t pin, bool inverted = true);
|
|
|
|
bool Update();
|
|
|
|
bool On();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// The button is connected to a Multiplexer channel
|
2021-11-22 20:10:08 +00:00
|
|
|
class MuxReader : public Reader {
|
2021-11-22 19:12:44 +00:00
|
|
|
public:
|
|
|
|
MuxReader(uint8_t channel, Mux* mux, bool inverted = true);
|
|
|
|
bool Update();
|
|
|
|
bool On();
|
|
|
|
|
|
|
|
protected:
|
2021-11-22 20:10:08 +00:00
|
|
|
uint8_t channel;
|
2021-11-22 19:12:44 +00:00
|
|
|
Mux * mux;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// The button is connected via a scan matrix
|
|
|
|
// "row" should always be the input, with "col" the selecter.
|
2021-11-22 20:10:08 +00:00
|
|
|
class MatrixReader : public Reader {
|
2021-11-22 19:12:44 +00:00
|
|
|
public:
|
2021-11-22 20:10:08 +00:00
|
|
|
MatrixReader(uint8_t row, uint8_t col, Matrix* matrix, bool inverted = true);
|
2021-11-22 19:12:44 +00:00
|
|
|
bool Update();
|
|
|
|
bool On();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
uint8_t col;
|
2021-11-22 20:10:08 +00:00
|
|
|
Matrix* matrix;
|
2021-11-22 19:12:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|