input: wait for 200ms before detecting button/axis input when remapping

This commit is contained in:
Flyinghead 2019-03-28 18:28:29 +01:00
parent 47201b9e48
commit 8751e55213
2 changed files with 23 additions and 12 deletions

View File

@ -20,6 +20,7 @@
#include <limits.h>
#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;
}

View File

@ -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;