From 8751e55213d55a41222e236b24013000bed74dfe Mon Sep 17 00:00:00 2001 From: Flyinghead Date: Thu, 28 Mar 2019 18:28:29 +0100 Subject: [PATCH] input: wait for 200ms before detecting button/axis input when remapping --- core/input/gamepad_device.cpp | 22 ++++++++++++++++++++-- core/input/gamepad_device.h | 13 +++---------- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/core/input/gamepad_device.cpp b/core/input/gamepad_device.cpp index 29cb1436a..f8bee9bb7 100644 --- a/core/input/gamepad_device.cpp +++ b/core/input/gamepad_device.cpp @@ -20,6 +20,7 @@ #include #include "gamepad_device.h" #include "rend/gui.h" +#include "oslib/oslib.h" extern void dc_exit(); @@ -32,7 +33,8 @@ std::mutex GamepadDevice::_gamepads_mutex; bool GamepadDevice::gamepad_btn_input(u32 code, bool pressed) { - if (_input_detected != NULL && _detecting_button && pressed) + if (_input_detected != NULL && _detecting_button + && os_GetSeconds() >= _detection_start_time && pressed) { _input_detected(code); _input_detected = NULL; @@ -84,7 +86,8 @@ bool GamepadDevice::gamepad_axis_input(u32 code, int value) v = (get_axis_min_value(code) + get_axis_range(code) - value) * 255 / get_axis_range(code) - 128; else v = (value - get_axis_min_value(code)) * 255 / get_axis_range(code) - 128; //-128 ... + 127 range - if (_input_detected != NULL && !_detecting_button && (v >= 64 || v <= -64)) + if (_input_detected != NULL && !_detecting_button + && os_GetSeconds() >= _detection_start_time && (v >= 64 || v <= -64)) { _input_detected(code); _input_detected = NULL; @@ -235,3 +238,18 @@ void UpdateVibration(u32 port, float power, float inclination, u32 duration_ms) gamepad->rumble(power, inclination, duration_ms); } } + +void GamepadDevice::detect_btn_input(input_detected_cb button_pressed) +{ + _input_detected = button_pressed; + _detecting_button = true; + _detection_start_time = os_GetSeconds() + 0.2; +} + +void GamepadDevice::detect_axis_input(input_detected_cb axis_moved) +{ + _input_detected = axis_moved; + _detecting_button = false; + _detection_start_time = os_GetSeconds() + 0.2; +} + diff --git a/core/input/gamepad_device.h b/core/input/gamepad_device.h index e11c5e90d..d7cb5d4a5 100644 --- a/core/input/gamepad_device.h +++ b/core/input/gamepad_device.h @@ -35,16 +35,8 @@ public: bool gamepad_axis_input(u32 code, int value); virtual ~GamepadDevice() {} - void detect_btn_input(input_detected_cb button_pressed) - { - _input_detected = button_pressed; - _detecting_button = true; - } - void detect_axis_input(input_detected_cb axis_moved) - { - _input_detected = axis_moved; - _detecting_button = false; - } + void detect_btn_input(input_detected_cb button_pressed); + void detect_axis_input(input_detected_cb axis_moved); void cancel_detect_input() { _input_detected = NULL; @@ -104,6 +96,7 @@ private: std::string _api_name; int _maple_port; bool _detecting_button = false; + double _detection_start_time; input_detected_cb _input_detected; bool _remappable; float _dead_zone = 0.1f;