Add new behavior for a button that sends separate keypresses on press and release. This required a refactor of the button abstraction as well.
This commit is contained in:
parent
9234060532
commit
c37e4a6789
3 changed files with 49 additions and 26 deletions
23
Joystick.h
23
Joystick.h
|
@ -3,6 +3,9 @@
|
|||
|
||||
#include <Arduino.h>
|
||||
#include <Bounce2.h>
|
||||
#include <list>
|
||||
|
||||
using std::list;
|
||||
|
||||
// If you're using the arduino-big-joystick firmware, these numbers can't be
|
||||
// changed. If you're writing your own Report Descriptor, tune these to match by
|
||||
|
@ -16,9 +19,10 @@
|
|||
#define JOYSTICK_NUM_BYTES (JOYSTICK_NUM_BUTTONS+7)/8
|
||||
|
||||
enum ButtonType {
|
||||
BUTTON_LATCHED = 0x1,
|
||||
BUTTON_PULSED = 0x2,
|
||||
BUTTON_PULSED_DOUBLE_ACTION = 0x4
|
||||
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.
|
||||
};
|
||||
|
||||
struct JoyReport {
|
||||
|
@ -29,6 +33,9 @@ struct JoyReport {
|
|||
struct Button {
|
||||
ButtonType type;
|
||||
Bounce bouncer;
|
||||
uint8_t index0;
|
||||
uint8_t index1;
|
||||
bool inverted = false; // if true, send button press on release and vice versa.
|
||||
};
|
||||
|
||||
bool operator ==(JoyReport a, JoyReport b);
|
||||
|
@ -40,10 +47,10 @@ class Joystick {
|
|||
void Init();
|
||||
void Update();
|
||||
|
||||
void AddButton(uint8_t pin, ButtonType type, bool pullup=false);
|
||||
void AddButton(uint8_t pin, ButtonType type, bool pullup=true);
|
||||
void AddAxis(uint8_t pin); // Axes don't actually work yet!
|
||||
|
||||
// These functions are deprecated and may become private in a future
|
||||
// Public access to these functions is deprecated and they may become private in a future
|
||||
// version. Prefer the above API instead.
|
||||
void SetAxis(uint8_t axis, int16_t value);
|
||||
void PressButton(uint8_t button);
|
||||
|
@ -56,8 +63,8 @@ class Joystick {
|
|||
void _UpdateButton(uint8_t index);
|
||||
void _UpdateAxis(uint8_t index);
|
||||
|
||||
Button _buttons[JOYSTICK_NUM_BUTTONS];
|
||||
uint8_t _num_buttons;
|
||||
list<Button> _buttons;
|
||||
uint8_t _last_button_index;
|
||||
bool _have_pulsed_button;
|
||||
|
||||
uint8_t _axes[JOYSTICK_NUM_AXES];
|
||||
|
@ -68,6 +75,6 @@ class Joystick {
|
|||
};
|
||||
|
||||
// Internal use only.
|
||||
#define _BUTTON_PULSED_TYPES (BUTTON_PULSED | BUTTON_PULSED_DOUBLE_ACTION)
|
||||
#define _BUTTON_PULSED_TYPES (BUTTON_PULSED | BUTTON_PULSED_DOUBLE_ACTION | BUTTON_PULSED_DOUBLE_ACTION_SPLIT)
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue