Skip to content

Commit 04cdf0a

Browse files
authored
apple: acceleration should include gravity (libretro#17467)
1 parent 81e443c commit 04cdf0a

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

input/drivers/cocoa_input.m

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,6 @@ static int16_t cocoa_input_state(
742742

743743
static void cocoa_input_free(void *data)
744744
{
745-
unsigned i;
746745
cocoa_input_data_t *apple = (cocoa_input_data_t*)data;
747746

748747
if (!apple || !data)
@@ -782,6 +781,10 @@ static bool cocoa_input_set_sensor_state(void *data, unsigned port,
782781
continue;
783782
if (!controller.motion)
784783
break;
784+
if (action == RETRO_SENSOR_ACCELEROMETER_ENABLE && !controller.motion.hasGravityAndUserAcceleration)
785+
break;
786+
if (action == RETRO_SENSOR_GYROSCOPE_ENABLE && !controller.motion.hasAttitudeAndRotationRate)
787+
break;
785788
if (controller.motion.sensorsRequireManualActivation)
786789
{
787790
/* This is a bug, we assume if you turn on/off either
@@ -827,7 +830,7 @@ static bool cocoa_input_set_sensor_state(void *data, unsigned port,
827830
static float cocoa_input_get_sensor_input(void *data, unsigned port, unsigned id)
828831
{
829832
#ifdef HAVE_MFI
830-
if (@available(iOS 14.0, *))
833+
if (@available(iOS 14.0, macOS 11.0, tvOS 14.0, *))
831834
{
832835
for (GCController *controller in [GCController controllers])
833836
{
@@ -838,11 +841,11 @@ static float cocoa_input_get_sensor_input(void *data, unsigned port, unsigned id
838841
switch (id)
839842
{
840843
case RETRO_SENSOR_ACCELEROMETER_X:
841-
return controller.motion.userAcceleration.x;
844+
return controller.motion.acceleration.x;
842845
case RETRO_SENSOR_ACCELEROMETER_Y:
843-
return controller.motion.userAcceleration.y;
846+
return controller.motion.acceleration.y;
844847
case RETRO_SENSOR_ACCELEROMETER_Z:
845-
return controller.motion.userAcceleration.z;
848+
return controller.motion.acceleration.z;
846849
case RETRO_SENSOR_GYROSCOPE_X:
847850
return controller.motion.rotationRate.x;
848851
case RETRO_SENSOR_GYROSCOPE_Y:
@@ -860,11 +863,11 @@ static float cocoa_input_get_sensor_input(void *data, unsigned port, unsigned id
860863
switch (id)
861864
{
862865
case RETRO_SENSOR_ACCELEROMETER_X:
863-
return motionManager.deviceMotion.userAcceleration.x;
866+
return motionManager.deviceMotion.gravity.x + motionManager.deviceMotion.userAcceleration.x;
864867
case RETRO_SENSOR_ACCELEROMETER_Y:
865-
return motionManager.deviceMotion.userAcceleration.y;
868+
return motionManager.deviceMotion.gravity.y + motionManager.deviceMotion.userAcceleration.y;
866869
case RETRO_SENSOR_ACCELEROMETER_Z:
867-
return motionManager.deviceMotion.userAcceleration.z;
870+
return motionManager.deviceMotion.gravity.z + motionManager.deviceMotion.userAcceleration.z;
868871
case RETRO_SENSOR_GYROSCOPE_X:
869872
return motionManager.deviceMotion.rotationRate.x;
870873
case RETRO_SENSOR_GYROSCOPE_Y:

0 commit comments

Comments
 (0)