2021-11-08 01:37:30 +00:00
|
|
|
#ifndef _BUTTON_H_
|
|
|
|
#define _BUTTON_H_
|
|
|
|
|
|
|
|
#include <Encoder.h>
|
2021-11-22 19:12:44 +00:00
|
|
|
#include "Reader.h"
|
2021-11-08 01:37:30 +00:00
|
|
|
|
|
|
|
using namespace admux;
|
|
|
|
|
|
|
|
class Joystick; // forward declaration
|
|
|
|
|
|
|
|
enum ButtonType {
|
|
|
|
BUTTON_PASSTHRU = 0x1, // always use the (debounced) absolute state of the input
|
|
|
|
BUTTON_PULSED = 0x2, // on button press, send an on signal followed immediately by an off signal.
|
|
|
|
BUTTON_PULSED_DOUBLE_ACTION = 0x4, // Send a button press twice - once for press and once for release.
|
|
|
|
BUTTON_PULSED_DOUBLE_ACTION_SPLIT = 0x8, // Send two separate button presses - one button on press, another on release.
|
|
|
|
BUTTON_LATCHED_MOMENTARY = 0x10,
|
|
|
|
ENCODER_PULSED_SPLIT = 0x20 // A rotary encoder that should be treated as two different pulsed/momentary buttons, one for each direction
|
|
|
|
};
|
|
|
|
|
|
|
|
// The abstract button base class. A button must have, at a minimum:
|
|
|
|
// * a button *type* (typically automatically assigned by the constructor)
|
|
|
|
// * at least one "virtual button" - that is, a Joystick input that it controls
|
|
|
|
// * an update method.
|
|
|
|
class Button {
|
|
|
|
public:
|
2021-11-22 19:12:44 +00:00
|
|
|
Button(uint8_t vbutton, Reader* reader);
|
2021-11-09 06:11:36 +00:00
|
|
|
virtual bool Update(Joystick* js) = 0;
|
2021-11-08 01:37:30 +00:00
|
|
|
virtual void ReleaseButtons(Joystick* js);
|
|
|
|
ButtonType type;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
uint8_t vbutton;
|
2021-11-22 19:12:44 +00:00
|
|
|
Reader *reader;
|
2021-11-08 01:37:30 +00:00
|
|
|
};
|
|
|
|
|
2021-11-22 19:12:44 +00:00
|
|
|
class PassthruButton : public Button {
|
2021-11-08 01:37:30 +00:00
|
|
|
public:
|
2021-11-22 19:12:44 +00:00
|
|
|
PassthruButton(uint8_t vbutton, Reader* reader);
|
2021-11-09 06:11:36 +00:00
|
|
|
bool Update(Joystick* js);
|
2021-11-08 01:37:30 +00:00
|
|
|
};
|
|
|
|
|
2021-11-22 19:12:44 +00:00
|
|
|
class LatchedButton : public Button {
|
2021-11-08 01:37:30 +00:00
|
|
|
public:
|
2021-11-22 19:12:44 +00:00
|
|
|
LatchedButton(uint8_t vbutton, Reader* reader);
|
2021-11-09 06:11:36 +00:00
|
|
|
bool Update(Joystick* js);
|
2021-11-08 01:37:30 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
bool pressed;
|
|
|
|
};
|
|
|
|
|
2021-11-22 19:12:44 +00:00
|
|
|
class PulsedButton : public Button {
|
2021-11-08 01:37:30 +00:00
|
|
|
public:
|
2021-11-22 19:12:44 +00:00
|
|
|
PulsedButton(uint8_t vbutton, Reader* reader, bool double_action = false, bool split = false);
|
2021-11-09 06:11:36 +00:00
|
|
|
bool Update(Joystick* js);
|
2021-11-08 01:37:30 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
bool double_action;
|
|
|
|
bool split;
|
2021-11-13 22:48:12 +00:00
|
|
|
unsigned long release_time1;
|
|
|
|
unsigned long release_time2;
|
2021-11-08 01:37:30 +00:00
|
|
|
uint8_t vbutton2;
|
|
|
|
};
|
|
|
|
|
|
|
|
class EncoderButton : public Button {
|
|
|
|
public:
|
2021-12-21 04:16:07 +00:00
|
|
|
EncoderButton(uint8_t pin1, uint8_t pin2, uint8_t vbutton, int8_t tick_threshold);
|
2021-11-09 06:11:36 +00:00
|
|
|
bool Update(Joystick* js);
|
2021-11-08 01:37:30 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
Encoder* encoder;
|
|
|
|
long last_value;
|
|
|
|
uint8_t vbutton2;
|
2021-11-13 22:48:12 +00:00
|
|
|
unsigned long release_time1;
|
|
|
|
unsigned long release_time2;
|
2021-12-21 04:16:07 +00:00
|
|
|
int8_t ticks;
|
|
|
|
int8_t tick_threshold;
|
2021-11-08 01:37:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|