try to fix: built-in gyro doesn't work on iOS12 & iOS13

This commit is contained in:
TrueZhuanjia committed 2025-09-28 10:59:01 +08:00
1 parent b4493707ca
commit f60433ff3f
1 file changed
+29 -3
+29 -3
View File
@@ -101,15 +101,20 @@ static const double MOUSE_SPEED_DIVISOR = 1.25;
[controller.rightTriggerMotor setMotorAmplitude:rightTrigger]; [controller.rightTriggerMotor setMotorAmplitude:rightTrigger];
} }
- (bool)isLandscapeNow {
return CGRectGetWidth([[UIScreen mainScreen]bounds]) > CGRectGetHeight([[UIScreen mainScreen]bounds]);
}
-(void)updateTimerStateForController:(VoidController* )voidController{ -(void)updateTimerStateForController:(VoidController* )voidController{
if (@available(iOS 14.0, tvOS 14.0, *)) { // if (@available(iOS 14.0, tvOS 14.0, *)) {
if (true) {
if(_gyroMode == GyroModeOff){ if(_gyroMode == GyroModeOff){
[self stopTimerForController:voidController]; [self stopTimerForController:voidController];
return; return;
} }
if(voidController.gamepad.motion.hasAttitudeAndRotationRate) [voidController.motionTypes addObject:@(LI_MOTION_TYPE_ACCEL)]; if(voidController.gamepad.motion.hasAttitudeAndRotationRate) [voidController.motionTypes addObject:@(LI_MOTION_TYPE_ACCEL)];
if(voidController.gamepad.motion.hasRotationRate) [voidController.motionTypes addObject:@(LI_MOTION_TYPE_GYRO)]; if (@available(iOS 14.0, *)) if(voidController.gamepad.motion.hasRotationRate) [voidController.motionTypes addObject:@(LI_MOTION_TYPE_GYRO)];
for(NSNumber* motionTypeObj in voidController.motionTypes){ for(NSNumber* motionTypeObj in voidController.motionTypes){
uint8_t motionType = motionTypeObj.intValue; uint8_t motionType = motionTypeObj.intValue;
@@ -147,6 +152,7 @@ static const double MOUSE_SPEED_DIVISOR = 1.25;
voidController.lastDeviceAccelSample = deviceAccelSample; voidController.lastDeviceAccelSample = deviceAccelSample;
// Convert g to m/s^2 // Convert g to m/s^2
if (@available(iOS 13.0, *)) {
if(UIApplication.sharedApplication.windows.firstObject.windowScene.interfaceOrientation == 4){ //check for landscape left or landscape right if(UIApplication.sharedApplication.windows.firstObject.windowScene.interfaceOrientation == 4){ //check for landscape left or landscape right
LiSendControllerMotionEvent((uint8_t)voidController.controllerNumber, LiSendControllerMotionEvent((uint8_t)voidController.controllerNumber,
LI_MOTION_TYPE_ACCEL, LI_MOTION_TYPE_ACCEL,
@@ -161,6 +167,14 @@ static const double MOUSE_SPEED_DIVISOR = 1.25;
deviceAccelSample.z * -9.80665f * self->_gyroSensitivity, deviceAccelSample.z * -9.80665f * self->_gyroSensitivity,
deviceAccelSample.x * +9.80665f * self->_gyroSensitivity); deviceAccelSample.x * +9.80665f * self->_gyroSensitivity);
} }
}
else{
LiSendControllerMotionEvent((uint8_t)voidController.controllerNumber,
LI_MOTION_TYPE_ACCEL,
deviceAccelSample.y * -9.80665f * self->_gyroSensitivity,
deviceAccelSample.z * -9.80665f * self->_gyroSensitivity,
deviceAccelSample.x * -9.80665f * self->_gyroSensitivity);
}
}]; }];
});} });}
break; break;
@@ -187,6 +201,7 @@ static const double MOUSE_SPEED_DIVISOR = 1.25;
// Convert rad/s to deg/s // Convert rad/s to deg/s
//NSLog(@"sending built-in gyro data, accelSample data 00: %f, playerIndex: %d",deviceGyroSample.x, voidController.playerIndex); //NSLog(@"sending built-in gyro data, accelSample data 00: %f, playerIndex: %d",deviceGyroSample.x, voidController.playerIndex);
if (@available(iOS 13.0, *)) {
if(UIApplication.sharedApplication.windows.firstObject.windowScene.interfaceOrientation == 4){//check for landscape left or landscape right if(UIApplication.sharedApplication.windows.firstObject.windowScene.interfaceOrientation == 4){//check for landscape left or landscape right
LiSendControllerMotionEvent((uint8_t)voidController.controllerNumber, LiSendControllerMotionEvent((uint8_t)voidController.controllerNumber,
LI_MOTION_TYPE_GYRO, LI_MOTION_TYPE_GYRO,
@@ -201,6 +216,14 @@ static const double MOUSE_SPEED_DIVISOR = 1.25;
deviceGyroSample.z * 57.2957795f * self->_gyroSensitivity, deviceGyroSample.z * 57.2957795f * self->_gyroSensitivity,
deviceGyroSample.x * -57.2957795f * self->_gyroSensitivity); deviceGyroSample.x * -57.2957795f * self->_gyroSensitivity);
} }
}
else{
LiSendControllerMotionEvent((uint8_t)voidController.controllerNumber,
LI_MOTION_TYPE_GYRO,
deviceGyroSample.y * 57.2957795f * self->_gyroSensitivity,
deviceGyroSample.z * 57.2957795f * self->_gyroSensitivity,
deviceGyroSample.x * 57.2957795f * self->_gyroSensitivity);
}
}]; }];
break; break;
} }
@@ -209,6 +232,8 @@ static const double MOUSE_SPEED_DIVISOR = 1.25;
#endif #endif
else{ else{
NSLog(@"controller obj timer update: controller timer "); NSLog(@"controller obj timer update: controller timer ");
if (@available(iOS 14.0, *)) {
switch (motionType) { switch (motionType) {
case LI_MOTION_TYPE_ACCEL: case LI_MOTION_TYPE_ACCEL:
[voidController.accelTimer invalidate]; [voidController.accelTimer invalidate];
@@ -278,12 +303,13 @@ static const double MOUSE_SPEED_DIVISOR = 1.25;
} }
} }
} }
}
NSLog(@"controller obj timer, motionTypes: %lu", (unsigned long)voidController.motionTypes.count); NSLog(@"controller obj timer, motionTypes: %lu", (unsigned long)voidController.motionTypes.count);
// Set the motion sensor state if they require manual activation // Set the motion sensor state if they require manual activation
[self updateSensorSateForController:voidController]; [self updateSensorSateForController:voidController];
NSLog(@"sensor active: %d", voidController.gamepad.motion.sensorsActive); // NSLog(@"sensor active: %d", voidController.gamepad.motion.sensorsActive);
} }
} }