From 8a7c39c123c490207ee61f4d6b4d3532486c8778 Mon Sep 17 00:00:00 2001 From: turfyman Date: Mon, 3 Apr 2017 23:54:45 -0400 Subject: [PATCH] Add hysteresis to the button/key press --- Handbrake.ino | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/Handbrake.ino b/Handbrake.ino index 13b2f45..14fb108 100644 --- a/Handbrake.ino +++ b/Handbrake.ino @@ -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 @@ -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) @@ -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)