arduino-joystick/Reader.h

66 lines
1.3 KiB
C
Raw Normal View History

// "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_
#include "Matrix.h"
#include <Arduino.h>
#include <Bounce2.h>
#include <Mux.h>
using namespace admux;
// 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
class DirectReader : public Reader {
public:
DirectReader(uint8_t pin, bool inverted = true);
bool Update();
bool On();
};
// The button is connected to a Multiplexer channel
class MuxReader : public Reader {
public:
MuxReader(uint8_t channel, Mux* mux, bool inverted = true);
bool Update();
bool On();
protected:
uint8_t channel;
Mux * mux;
};
// The button is connected via a scan matrix
// "row" should always be the input, with "col" the selecter.
class MatrixReader : public Reader {
public:
MatrixReader(uint8_t row, uint8_t col, Matrix* matrix, bool inverted = true);
bool Update();
bool On();
protected:
uint8_t col;
Matrix* matrix;
};
#endif