Add rotary encoder support, simplify AddMuxButton interface.
This commit is contained in:
parent
564f4b2b57
commit
09043919de
5 changed files with 106 additions and 15 deletions
19
Joystick.h
19
Joystick.h
|
@ -1,9 +1,10 @@
|
|||
#ifndef _JOYSTICK_H_
|
||||
#define _JOYSTICK_H_
|
||||
|
||||
#include <Mux.h>
|
||||
#include <Arduino.h>
|
||||
#include <Bounce2.h>
|
||||
#include <Encoder.h>
|
||||
#include <Mux.h>
|
||||
|
||||
using namespace admux;
|
||||
|
||||
|
@ -27,7 +28,8 @@ enum ButtonType {
|
|||
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
|
||||
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
|
||||
};
|
||||
|
||||
struct JoyReport {
|
||||
|
@ -43,10 +45,16 @@ struct Button {
|
|||
bool pressed = false; // only used by BUTTON_LATCHED_MOMENTARY
|
||||
bool inverted = false; // if true, send button press on release and vice versa.
|
||||
|
||||
// multiplexer button settings
|
||||
// todo: this should probably be abstracted out from this struct...
|
||||
bool mux;
|
||||
uint8_t mux_id;
|
||||
uint8_t mux_channel;
|
||||
|
||||
// encoder button settings
|
||||
bool encoder_button;
|
||||
Encoder* encoder;
|
||||
long last_enc;
|
||||
};
|
||||
|
||||
bool operator ==(JoyReport a, JoyReport b);
|
||||
|
@ -64,7 +72,9 @@ class Joystick {
|
|||
// If `pullup` is false, your button should connect the pin to VCC.
|
||||
// Mux parameters are ignored unless `mux` is true.
|
||||
void AddButton(uint8_t pin, ButtonType type, bool pullup=true);
|
||||
void AddMuxButton(uint8_t pin, uint8_t mux_id, uint8_t mux_channel, ButtonType type, bool pullup=true);
|
||||
// Add a rotary encoder. ENCODER button types allow you to treat an encoder as a momentary button or an axis (TODO)
|
||||
void AddEncoder(uint8_t pin0, uint8_t pin1, ButtonType type, bool pullup=true);
|
||||
void AddMuxButton(uint8_t mux_id, uint8_t mux_channel, ButtonType type, bool pullup=true);
|
||||
|
||||
// Add an analog axis to the joystick. THIS METHOD IS NOT CURRENTLY TESTED OR SUPPORTED. It might work, but probably not.
|
||||
void AddAxis(uint8_t pin);
|
||||
|
@ -83,6 +93,7 @@ class Joystick {
|
|||
|
||||
void _ReleasePulsedButtons();
|
||||
void _UpdateButton(uint8_t index);
|
||||
void _UpdateEncoder(uint8_t index);
|
||||
void _UpdateAxis(uint8_t index);
|
||||
|
||||
Button* _BuildButton(uint8_t pin, ButtonType type, bool pullup);
|
||||
|
@ -103,6 +114,6 @@ class Joystick {
|
|||
};
|
||||
|
||||
// Internal use only.
|
||||
#define _BUTTON_PULSED_TYPES (BUTTON_PULSED | BUTTON_PULSED_DOUBLE_ACTION | BUTTON_PULSED_DOUBLE_ACTION_SPLIT)
|
||||
#define _BUTTON_PULSED_TYPES (BUTTON_PULSED | BUTTON_PULSED_DOUBLE_ACTION | BUTTON_PULSED_DOUBLE_ACTION_SPLIT | ENCODER_PULSED_SPLIT)
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue