Skip to content

Commit

Permalink
Add hysteresis to the button/key press
Browse files Browse the repository at this point in the history
  • Loading branch information
tombresson committed Apr 4, 2017
1 parent ca6a0d0 commit 8a7c39c
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions Handbrake.ino
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@
#define HANDBRAKE_POSITION_MAX 100.0F
#define HANDBRAKE_POSITION_MIN 0.0F

// The hysteresis (in percentage) that in used for the button/key press
#define HANDBRAKE_THRESH_HYSTERESIS 5

// GPIO pin for the mode select button
#define HANDBRAKE_MODE_SELECT_BUTTON 12

Expand Down Expand Up @@ -324,10 +327,16 @@ void loop(void) {
{
Joystick.button(HANDBRAKE_JOY_BUTTON, true);
}
else
// Release the button if below the threshold with the hysteresis or if
// position happens to become 0
else if((position < (g_button_thresh - HANDBRAKE_THRESH_HYSTERESIS)) || (position == 0.0f))
{
Joystick.button(HANDBRAKE_JOY_BUTTON, false);
}
else
{
// Do nothing
}
Joystick.send_now();
}
else if (g_saved_data.mode == HANDBRAKE_KEYBOARD_MODE)
Expand All @@ -337,10 +346,16 @@ void loop(void) {
{
Keyboard.set_key1(g_bound_key);
}
else
// Release the button if below the threshold with the hysteresis or if
// position happens to become 0
else if((position < (g_button_thresh - HANDBRAKE_THRESH_HYSTERESIS)) || (position == 0.0f))
{
Keyboard.set_key1(0);
}
else
{
// Do nothing
}
}
}
else if(g_saved_data.mode == HANDBRAKE_CONFIG_MODE)
Expand Down

0 comments on commit 8a7c39c

Please sign in to comment.