diff --git a/android/native/jni/input_android.c b/android/native/jni/input_android.c index a7ddcf906c..edddf4949c 100644 --- a/android/native/jni/input_android.c +++ b/android/native/jni/input_android.c @@ -1983,26 +1983,9 @@ static int16_t android_input_state(void *data, const struct retro_keybind **bind default: return 0; } - case RETRO_DEVICE_SENSOR_ACCELEROMETER: - switch (id) - { - // FIXME: These are float values. - // If they have a fixed range, e.g. (-1, 1), they can - // be converted to fixed point easily. If they have unbound range, this should be - // queried from a function in retro_sensor_interface. - case RETRO_DEVICE_ID_SENSOR_ACCELEROMETER_X: - return android->accelerometer_state.x; - case RETRO_DEVICE_ID_SENSOR_ACCELEROMETER_Y: - return android->accelerometer_state.y; - case RETRO_DEVICE_ID_SENSOR_ACCELEROMETER_Z: - return android->accelerometer_state.z; - default: - return 0; - } - break; - default: - return 0; } + + return 0; } static bool android_input_key_pressed(void *data, int key) @@ -2079,10 +2062,27 @@ static bool android_input_set_sensor_state(void *data, unsigned port, enum retro android_app->sensor_state_mask &= ~(1ULL << RETRO_SENSOR_ACCELEROMETER_ENABLE); android_app->sensor_state_mask |= (1ULL << RETRO_SENSOR_ACCELEROMETER_DISABLE); return true; - - default: - return false; } + + return false; +} + +static float android_input_get_sensor_input(void *data, unsigned port, enum retro_sensor_action action) +{ + android_input_t *android = (android_input_t*)data; + struct android_app *android_app = (struct android_app*)g_android; + + switch (action) + { + case RETRO_DEVICE_ID_SENSOR_ACCELEROMETER_X: + return android->accelerometer_state.x; + case RETRO_DEVICE_ID_SENSOR_ACCELEROMETER_Y: + return android->accelerometer_state.y; + case RETRO_DEVICE_ID_SENSOR_ACCELEROMETER_Z: + return android->accelerometer_state.z; + } + + return 0; } const input_driver_t input_android = { @@ -2093,6 +2093,7 @@ const input_driver_t input_android = { android_input_free_input, android_input_set_keybinds, android_input_set_sensor_state, + android_input_get_sensor_input, android_input_get_capabilities, "android_input", }; diff --git a/apple/common/apple_input.c b/apple/common/apple_input.c index 43f0a0e784..480b3e7ffc 100644 --- a/apple/common/apple_input.c +++ b/apple/common/apple_input.c @@ -445,6 +445,7 @@ const input_driver_t input_apple = { apple_input_free_input, apple_input_set_keybinds, NULL, + NULL, apple_input_get_capabilities, "apple_input", NULL, diff --git a/blackberry-qnx/qnx_input.c b/blackberry-qnx/qnx_input.c index abe0232d3b..4963d3fd92 100644 --- a/blackberry-qnx/qnx_input.c +++ b/blackberry-qnx/qnx_input.c @@ -862,6 +862,7 @@ const input_driver_t input_qnx = { qnx_input_free_input, qnx_input_set_keybinds, NULL, + NULL, qnx_input_get_capabilities, "qnx_input", }; diff --git a/driver.c b/driver.c index 6453b3185a..72dbc45e89 100644 --- a/driver.c +++ b/driver.c @@ -601,6 +601,14 @@ bool driver_set_sensor_state(unsigned port, enum retro_sensor_action action, uns return false; } +float driver_sensor_get_input(unsigned port, enum retro_sensor_action action) +{ + if (driver.input && driver.input_data && driver.input->get_sensor_input) + return driver.input->get_sensor_input(driver.input_data, port, action); + else + return 0.0f; +} + #ifdef HAVE_CAMERA bool driver_camera_start(void) { diff --git a/driver.h b/driver.h index df6c69cd93..cb6d42af62 100644 --- a/driver.h +++ b/driver.h @@ -354,6 +354,7 @@ typedef struct input_driver void (*free)(void *data); void (*set_keybinds)(void *data, unsigned device, unsigned port, unsigned id, unsigned keybind_action); bool (*set_sensor_state)(void *data, unsigned port, enum retro_sensor_action action, unsigned rate); + float (*get_sensor_input)(void *data, unsigned port, enum retro_sensor_action action); uint64_t (*get_capabilities)(void *data); const char *ident; @@ -613,6 +614,7 @@ retro_proc_address_t driver_get_proc_address(const char *sym); bool driver_set_rumble_state(unsigned port, enum retro_rumble_effect effect, uint16_t strength); // Used by RETRO_ENVIRONMENT_GET_SENSOR_INTERFACE bool driver_set_sensor_state(unsigned port, enum retro_sensor_action action, unsigned rate); +float driver_sensor_get_input(unsigned port, enum retro_sensor_action action); // Used by RETRO_ENVIRONMENT_GET_CAMERA_INTERFACE #ifdef HAVE_CAMERA diff --git a/dynamic.c b/dynamic.c index de969d3400..3d19d67f38 100644 --- a/dynamic.c +++ b/dynamic.c @@ -827,6 +827,7 @@ bool rarch_environment_cb(unsigned cmd, void *data) RARCH_LOG("Environ GET_SENSOR_INTERFACE.\n"); struct retro_sensor_interface *iface = (struct retro_sensor_interface*)data; iface->set_sensor_state = driver_set_sensor_state; + iface->get_sensor_input = driver_sensor_get_input; break; } diff --git a/gx/gx_input.c b/gx/gx_input.c index cb2cd3ac27..2a3ad83f91 100644 --- a/gx/gx_input.c +++ b/gx/gx_input.c @@ -763,6 +763,7 @@ const input_driver_t input_gx = { gx_input_free_input, gx_input_set_keybinds, NULL, + NULL, gx_input_get_capabilities, "gx", diff --git a/input/dinput.c b/input/dinput.c index be10d7dded..170b6aa5f6 100644 --- a/input/dinput.c +++ b/input/dinput.c @@ -556,6 +556,7 @@ const input_driver_t input_dinput = { dinput_free, NULL, NULL, + NULL, dinput_get_capabilities, "dinput", diff --git a/input/linuxraw_input.c b/input/linuxraw_input.c index eef15e32ac..03eca75376 100644 --- a/input/linuxraw_input.c +++ b/input/linuxraw_input.c @@ -241,6 +241,7 @@ const input_driver_t input_linuxraw = { linuxraw_input_free, NULL, NULL, + NULL, linuxraw_get_capabilities, "linuxraw", NULL, diff --git a/input/null.c b/input/null.c index 5957b955ab..e219de21c9 100644 --- a/input/null.c +++ b/input/null.c @@ -83,6 +83,7 @@ const input_driver_t input_null = { nullinput_input_free_input, nullinput_set_keybinds, nullinput_set_sensor_state, + NULL, nullinput_get_capabilities, "null", }; diff --git a/input/rwebinput_input.c b/input/rwebinput_input.c index 2c3224f2ff..13e8e15319 100644 --- a/input/rwebinput_input.c +++ b/input/rwebinput_input.c @@ -155,6 +155,7 @@ const input_driver_t input_rwebinput = { rwebinput_input_free, NULL, NULL, + NULL, rwebinput_get_capabilities, "rwebinput", rwebinput_grab_mouse, diff --git a/input/sdl_input.c b/input/sdl_input.c index 4df9f6c60e..2fd68bcaa7 100644 --- a/input/sdl_input.c +++ b/input/sdl_input.c @@ -281,6 +281,7 @@ const input_driver_t input_sdl = { sdl_input_free, NULL, NULL, + NULL, sdl_get_capabilities, "sdl", NULL, diff --git a/input/udev_input.c b/input/udev_input.c index d2d3979ed1..ecf34c491b 100644 --- a/input/udev_input.c +++ b/input/udev_input.c @@ -818,6 +818,7 @@ const input_driver_t input_udev = { udev_input_free, NULL, NULL, + NULL, udev_input_get_capabilities, "udev", udev_input_grab_mouse, diff --git a/input/x11_input.c b/input/x11_input.c index c630211be0..d8dab4cbc5 100644 --- a/input/x11_input.c +++ b/input/x11_input.c @@ -318,6 +318,7 @@ const input_driver_t input_x = { x_input_free, NULL, NULL, + NULL, x_input_get_capabilities, "x", x_grab_mouse, diff --git a/libretro.h b/libretro.h index c15c3f9b0d..e1e952dc09 100755 --- a/libretro.h +++ b/libretro.h @@ -700,9 +700,11 @@ enum retro_sensor_action }; typedef bool (*retro_set_sensor_state_t)(unsigned port, enum retro_sensor_action action, unsigned rate); +typedef float (*retro_sensor_get_input_t)(unsigned port, enum retro_sensor_action action); struct retro_sensor_interface { retro_set_sensor_state_t set_sensor_state; + retro_sensor_get_input_t get_sensor_input; }; //// diff --git a/ps3/ps3_input.c b/ps3/ps3_input.c index e22a587f7a..22abadd411 100644 --- a/ps3/ps3_input.c +++ b/ps3/ps3_input.c @@ -513,6 +513,7 @@ const input_driver_t input_ps3 = { ps3_input_free_input, ps3_input_set_keybinds, ps3_input_set_sensor_state, + NULL, ps3_input_get_capabilities, "ps3", diff --git a/psp/psp_input.c b/psp/psp_input.c index 4a758eccfe..b355075621 100644 --- a/psp/psp_input.c +++ b/psp/psp_input.c @@ -194,6 +194,7 @@ const input_driver_t input_psp = { psp_input_free_input, psp_input_set_keybinds, NULL, + NULL, psp_input_get_capabilities, "psp", }; diff --git a/xdk/xdk_xinput_input.c b/xdk/xdk_xinput_input.c index 33a6b110f3..ef4c34141f 100644 --- a/xdk/xdk_xinput_input.c +++ b/xdk/xdk_xinput_input.c @@ -443,6 +443,7 @@ const input_driver_t input_xinput = xdk_input_free_input, xdk_input_set_keybinds, NULL, + NULL, xdk_input_get_capabilities, "xinput", diff --git a/xenon/xenon360_input.c b/xenon/xenon360_input.c index e6e74652eb..c9b854dd4f 100644 --- a/xenon/xenon360_input.c +++ b/xenon/xenon360_input.c @@ -126,6 +126,7 @@ const input_driver_t input_xenon360 = { xenon360_input_free_input, xenon360_input_set_keybinds, NULL, + NULL, xenon360_input_get_capabilities, "xenon360", };