Skip to content

Commit

Permalink
apple: acceleration should include gravity (#17467)
Browse files Browse the repository at this point in the history
  • Loading branch information
warmenhoven authored Jan 24, 2025
1 parent 81e443c commit 04cdf0a
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions input/drivers/cocoa_input.m
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,6 @@ static int16_t cocoa_input_state(

static void cocoa_input_free(void *data)
{
unsigned i;
cocoa_input_data_t *apple = (cocoa_input_data_t*)data;

if (!apple || !data)
Expand Down Expand Up @@ -782,6 +781,10 @@ static bool cocoa_input_set_sensor_state(void *data, unsigned port,
continue;
if (!controller.motion)
break;
if (action == RETRO_SENSOR_ACCELEROMETER_ENABLE && !controller.motion.hasGravityAndUserAcceleration)
break;
if (action == RETRO_SENSOR_GYROSCOPE_ENABLE && !controller.motion.hasAttitudeAndRotationRate)
break;
if (controller.motion.sensorsRequireManualActivation)
{
/* This is a bug, we assume if you turn on/off either
Expand Down Expand Up @@ -827,7 +830,7 @@ static bool cocoa_input_set_sensor_state(void *data, unsigned port,
static float cocoa_input_get_sensor_input(void *data, unsigned port, unsigned id)
{
#ifdef HAVE_MFI
if (@available(iOS 14.0, *))
if (@available(iOS 14.0, macOS 11.0, tvOS 14.0, *))
{
for (GCController *controller in [GCController controllers])
{
Expand All @@ -838,11 +841,11 @@ static float cocoa_input_get_sensor_input(void *data, unsigned port, unsigned id
switch (id)
{
case RETRO_SENSOR_ACCELEROMETER_X:
return controller.motion.userAcceleration.x;
return controller.motion.acceleration.x;
case RETRO_SENSOR_ACCELEROMETER_Y:
return controller.motion.userAcceleration.y;
return controller.motion.acceleration.y;
case RETRO_SENSOR_ACCELEROMETER_Z:
return controller.motion.userAcceleration.z;
return controller.motion.acceleration.z;
case RETRO_SENSOR_GYROSCOPE_X:
return controller.motion.rotationRate.x;
case RETRO_SENSOR_GYROSCOPE_Y:
Expand All @@ -860,11 +863,11 @@ static float cocoa_input_get_sensor_input(void *data, unsigned port, unsigned id
switch (id)
{
case RETRO_SENSOR_ACCELEROMETER_X:
return motionManager.deviceMotion.userAcceleration.x;
return motionManager.deviceMotion.gravity.x + motionManager.deviceMotion.userAcceleration.x;
case RETRO_SENSOR_ACCELEROMETER_Y:
return motionManager.deviceMotion.userAcceleration.y;
return motionManager.deviceMotion.gravity.y + motionManager.deviceMotion.userAcceleration.y;
case RETRO_SENSOR_ACCELEROMETER_Z:
return motionManager.deviceMotion.userAcceleration.z;
return motionManager.deviceMotion.gravity.z + motionManager.deviceMotion.userAcceleration.z;
case RETRO_SENSOR_GYROSCOPE_X:
return motionManager.deviceMotion.rotationRate.x;
case RETRO_SENSOR_GYROSCOPE_Y:
Expand Down

0 comments on commit 04cdf0a

Please sign in to comment.