Compare commits
2 Commits
70d7bdd3b2
...
23e491b424
Author | SHA1 | Date | |
---|---|---|---|
23e491b424 | |||
aef35f96a0 |
18
Button.cpp
18
Button.cpp
|
@ -48,7 +48,8 @@ bool LatchedButton::Update(Joystick* js) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PulsedButton::PulsedButton(uint8_t vbutton, Reader* reader, bool double_action, bool split) : Button(vbutton, reader) {
|
PulsedButton::PulsedButton(uint8_t vbutton, Reader* reader, uint8_t release_delay, bool double_action, bool split) : Button(vbutton, reader) {
|
||||||
|
this->release_delay = release_delay;
|
||||||
this->release_time1 = 0;
|
this->release_time1 = 0;
|
||||||
this->release_time2 = 0;
|
this->release_time2 = 0;
|
||||||
if (double_action) {
|
if (double_action) {
|
||||||
|
@ -80,21 +81,21 @@ bool PulsedButton::Update(Joystick* js) {
|
||||||
case BUTTON_PULSED:
|
case BUTTON_PULSED:
|
||||||
if (reader->On()) {
|
if (reader->On()) {
|
||||||
js->PressButton(vbutton);
|
js->PressButton(vbutton);
|
||||||
release_time1 = millis() + 250;
|
release_time1 = millis() + release_delay;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case BUTTON_PULSED_DOUBLE_ACTION:
|
case BUTTON_PULSED_DOUBLE_ACTION:
|
||||||
js->PressButton(vbutton);
|
js->PressButton(vbutton);
|
||||||
release_time1 = millis() + 250;
|
release_time1 = millis() + release_delay;
|
||||||
break;
|
break;
|
||||||
case BUTTON_PULSED_DOUBLE_ACTION_SPLIT:
|
case BUTTON_PULSED_DOUBLE_ACTION_SPLIT:
|
||||||
if (reader->On()) {
|
if (reader->On()) {
|
||||||
js->PressButton(vbutton);
|
js->PressButton(vbutton);
|
||||||
release_time1 = millis() + 250;
|
release_time1 = millis() + release_delay;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
js->PressButton(vbutton2);
|
js->PressButton(vbutton2);
|
||||||
release_time2 = millis() + 250;
|
release_time2 = millis() + release_delay;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -103,11 +104,12 @@ bool PulsedButton::Update(Joystick* js) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
EncoderButton::EncoderButton(uint8_t pin1, uint8_t pin2, uint8_t vbutton, int8_t tick_threshold) : Button(vbutton, NULL) {
|
EncoderButton::EncoderButton(uint8_t pin1, uint8_t pin2, uint8_t vbutton, int8_t tick_threshold, uint8_t release_delay) : Button(vbutton, NULL) {
|
||||||
this->type = ENCODER_PULSED_SPLIT;
|
this->type = ENCODER_PULSED_SPLIT;
|
||||||
this->vbutton2 = vbutton + 1;
|
this->vbutton2 = vbutton + 1;
|
||||||
this->encoder = new Encoder(pin1, pin2);
|
this->encoder = new Encoder(pin1, pin2);
|
||||||
this->last_value = encoder->read();
|
this->last_value = encoder->read();
|
||||||
|
this->release_delay = release_delay;
|
||||||
this->release_time1 = 0;
|
this->release_time1 = 0;
|
||||||
this->release_time2 = 0;
|
this->release_time2 = 0;
|
||||||
this->ticks = 0;
|
this->ticks = 0;
|
||||||
|
@ -135,13 +137,13 @@ bool EncoderButton::Update(Joystick* js) {
|
||||||
if (ticks >= tick_threshold) {
|
if (ticks >= tick_threshold) {
|
||||||
js->PressButton(vbutton);
|
js->PressButton(vbutton);
|
||||||
changed = true;
|
changed = true;
|
||||||
release_time1 = millis() + 250;
|
release_time1 = millis() + release_delay;
|
||||||
ticks = 0;
|
ticks = 0;
|
||||||
}
|
}
|
||||||
else if (ticks <= tick_threshold * -1) {
|
else if (ticks <= tick_threshold * -1) {
|
||||||
js->PressButton(vbutton2);
|
js->PressButton(vbutton2);
|
||||||
changed = true;
|
changed = true;
|
||||||
release_time2 = millis() + 250;
|
release_time2 = millis() + release_delay;
|
||||||
ticks = 0;
|
ticks = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
6
Button.h
6
Button.h
|
@ -50,12 +50,13 @@ class LatchedButton : public Button {
|
||||||
|
|
||||||
class PulsedButton : public Button {
|
class PulsedButton : public Button {
|
||||||
public:
|
public:
|
||||||
PulsedButton(uint8_t vbutton, Reader* reader, bool double_action = false, bool split = false);
|
PulsedButton(uint8_t vbutton, Reader* reader, uint8_t release_delay, bool double_action = false, bool split = false);
|
||||||
bool Update(Joystick* js);
|
bool Update(Joystick* js);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool double_action;
|
bool double_action;
|
||||||
bool split;
|
bool split;
|
||||||
|
uint8_t release_delay;
|
||||||
unsigned long release_time1;
|
unsigned long release_time1;
|
||||||
unsigned long release_time2;
|
unsigned long release_time2;
|
||||||
uint8_t vbutton2;
|
uint8_t vbutton2;
|
||||||
|
@ -63,13 +64,14 @@ class PulsedButton : public Button {
|
||||||
|
|
||||||
class EncoderButton : public Button {
|
class EncoderButton : public Button {
|
||||||
public:
|
public:
|
||||||
EncoderButton(uint8_t pin1, uint8_t pin2, uint8_t vbutton, int8_t tick_threshold);
|
EncoderButton(uint8_t pin1, uint8_t pin2, uint8_t vbutton, int8_t tick_threshold, uint8_t release_delay);
|
||||||
bool Update(Joystick* js);
|
bool Update(Joystick* js);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Encoder* encoder;
|
Encoder* encoder;
|
||||||
long last_value;
|
long last_value;
|
||||||
uint8_t vbutton2;
|
uint8_t vbutton2;
|
||||||
|
uint8_t release_delay;
|
||||||
unsigned long release_time1;
|
unsigned long release_time1;
|
||||||
unsigned long release_time2;
|
unsigned long release_time2;
|
||||||
int8_t ticks;
|
int8_t ticks;
|
||||||
|
|
11
Joystick.cpp
11
Joystick.cpp
|
@ -21,11 +21,12 @@ bool operator !=(JoyReport a, JoyReport b){
|
||||||
return !(a == b);
|
return !(a == b);
|
||||||
}
|
}
|
||||||
|
|
||||||
Joystick::Joystick(bool debug) {
|
Joystick::Joystick(uint8_t release_delay, bool debug) {
|
||||||
_debug = debug;
|
_debug = debug;
|
||||||
_virtual_buttons = 0;
|
_virtual_buttons = 0;
|
||||||
_num_axes = 0;
|
_num_axes = 0;
|
||||||
_num_buttons = 0;
|
_num_buttons = 0;
|
||||||
|
this->release_delay = release_delay;
|
||||||
|
|
||||||
for (uint8_t i=0; i < JOYSTICK_NUM_AXES; i++) {
|
for (uint8_t i=0; i < JOYSTICK_NUM_AXES; i++) {
|
||||||
_joyReport.axis[i] = 0;
|
_joyReport.axis[i] = 0;
|
||||||
|
@ -58,7 +59,7 @@ void Joystick::AddEncoder(uint8_t pin1, uint8_t pin2, int8_t tick_threshold, But
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case ENCODER_PULSED_SPLIT:
|
case ENCODER_PULSED_SPLIT:
|
||||||
// add an encoder button. _BuildButton() doesn't do everything we need, however...
|
// add an encoder button. _BuildButton() doesn't do everything we need, however...
|
||||||
button = new EncoderButton(pin1, pin2, _virtual_buttons, tick_threshold);
|
button = new EncoderButton(pin1, pin2, _virtual_buttons, tick_threshold, release_delay);
|
||||||
_buttons[_num_buttons] = button;
|
_buttons[_num_buttons] = button;
|
||||||
_num_buttons++;
|
_num_buttons++;
|
||||||
_virtual_buttons += 2;
|
_virtual_buttons += 2;
|
||||||
|
@ -157,15 +158,15 @@ void Joystick::_addButton(ButtonType type, Reader* reader) {
|
||||||
_virtual_buttons++;
|
_virtual_buttons++;
|
||||||
break;
|
break;
|
||||||
case BUTTON_PULSED:
|
case BUTTON_PULSED:
|
||||||
button = new PulsedButton(_virtual_buttons, reader, false, false);
|
button = new PulsedButton(_virtual_buttons, reader, release_delay, false, false);
|
||||||
_virtual_buttons++;
|
_virtual_buttons++;
|
||||||
break;
|
break;
|
||||||
case BUTTON_PULSED_DOUBLE_ACTION:
|
case BUTTON_PULSED_DOUBLE_ACTION:
|
||||||
button = new PulsedButton(_virtual_buttons, reader, true, false);
|
button = new PulsedButton(_virtual_buttons, reader, release_delay, true, false);
|
||||||
_virtual_buttons++;
|
_virtual_buttons++;
|
||||||
break;
|
break;
|
||||||
case BUTTON_PULSED_DOUBLE_ACTION_SPLIT:
|
case BUTTON_PULSED_DOUBLE_ACTION_SPLIT:
|
||||||
button = new PulsedButton(_virtual_buttons, reader, true, true);
|
button = new PulsedButton(_virtual_buttons, reader, release_delay, true, true);
|
||||||
_virtual_buttons += 2;
|
_virtual_buttons += 2;
|
||||||
break;
|
break;
|
||||||
case BUTTON_LATCHED_MOMENTARY:
|
case BUTTON_LATCHED_MOMENTARY:
|
||||||
|
|
|
@ -29,7 +29,7 @@ bool operator !=(JoyReport a, JoyReport b);
|
||||||
|
|
||||||
class Joystick {
|
class Joystick {
|
||||||
public:
|
public:
|
||||||
Joystick(bool debug=false);
|
Joystick(uint8_t release_delay = 50, bool debug = false);
|
||||||
void Init();
|
void Init();
|
||||||
void Update();
|
void Update();
|
||||||
|
|
||||||
|
@ -78,6 +78,7 @@ class Joystick {
|
||||||
JoyReport _joyReport;
|
JoyReport _joyReport;
|
||||||
|
|
||||||
bool _debug;
|
bool _debug;
|
||||||
|
uint8_t release_delay;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -42,7 +42,7 @@ using namespace admux;
|
||||||
|
|
||||||
|
|
||||||
bool debug = true;
|
bool debug = true;
|
||||||
Joystick js(debug);
|
Joystick js(250, debug);
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
js.Init();
|
js.Init();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user