mirror of
https://github.com/libretro/RetroArch
synced 2025-02-28 03:39:59 +00:00
Move sensor value reading to retro_sensor_interface
This commit is contained in:
parent
b480009604
commit
460670f074
@ -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",
|
||||
};
|
||||
|
@ -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,
|
||||
|
@ -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",
|
||||
};
|
||||
|
8
driver.c
8
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)
|
||||
{
|
||||
|
2
driver.h
2
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
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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",
|
||||
|
||||
|
@ -556,6 +556,7 @@ const input_driver_t input_dinput = {
|
||||
dinput_free,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
dinput_get_capabilities,
|
||||
"dinput",
|
||||
|
||||
|
@ -241,6 +241,7 @@ const input_driver_t input_linuxraw = {
|
||||
linuxraw_input_free,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
linuxraw_get_capabilities,
|
||||
"linuxraw",
|
||||
NULL,
|
||||
|
@ -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",
|
||||
};
|
||||
|
@ -155,6 +155,7 @@ const input_driver_t input_rwebinput = {
|
||||
rwebinput_input_free,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
rwebinput_get_capabilities,
|
||||
"rwebinput",
|
||||
rwebinput_grab_mouse,
|
||||
|
@ -281,6 +281,7 @@ const input_driver_t input_sdl = {
|
||||
sdl_input_free,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
sdl_get_capabilities,
|
||||
"sdl",
|
||||
NULL,
|
||||
|
@ -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,
|
||||
|
@ -318,6 +318,7 @@ const input_driver_t input_x = {
|
||||
x_input_free,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
x_input_get_capabilities,
|
||||
"x",
|
||||
x_grab_mouse,
|
||||
|
@ -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;
|
||||
};
|
||||
////
|
||||
|
||||
|
@ -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",
|
||||
|
||||
|
@ -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",
|
||||
};
|
||||
|
@ -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",
|
||||
|
||||
|
@ -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",
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user