From 67bd97b193e240eb7dcf45c982b6cb57e26422e3 Mon Sep 17 00:00:00 2001 From: Dominic Clifton Date: Wed, 17 Apr 2019 15:29:57 +0200 Subject: [PATCH] Really fix gyro detection code code for multi gyro setups. Broken in e44f75b4a7e7554b11d3197650ece64288d837b2. Problem caused by not checking both of the bits after masking. Prior to this commit the code would incorrectly attempt to use GYRO1 when only GYRO2 was detected resulting in a segfault. --- src/main/sensors/gyro.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/sensors/gyro.c b/src/main/sensors/gyro.c index 44b40d1efe..205d97b63a 100644 --- a/src/main/sensors/gyro.c +++ b/src/main/sensors/gyro.c @@ -539,7 +539,7 @@ bool gyroInit(void) } #if defined(USE_MULTI_GYRO) - if ((gyroToUse == GYRO_CONFIG_USE_GYRO_BOTH && !(gyroDetectionFlags & DETECTED_BOTH_GYROS)) + if ((gyroToUse == GYRO_CONFIG_USE_GYRO_BOTH && !((gyroDetectionFlags & DETECTED_BOTH_GYROS) == DETECTED_BOTH_GYROS)) || (gyroToUse == GYRO_CONFIG_USE_GYRO_1 && !(gyroDetectionFlags & DETECTED_GYRO_1)) || (gyroToUse == GYRO_CONFIG_USE_GYRO_2 && !(gyroDetectionFlags & DETECTED_GYRO_2))) { if (gyroDetectionFlags & DETECTED_GYRO_1) { @@ -552,7 +552,7 @@ bool gyroInit(void) } // Only allow using both gyros simultaneously if they are the same hardware type. - if ((gyroDetectionFlags & DETECTED_BOTH_GYROS) && gyroSensor1.gyroDev.gyroHardware == gyroSensor2.gyroDev.gyroHardware) { + if (((gyroDetectionFlags & DETECTED_BOTH_GYROS) == DETECTED_BOTH_GYROS) && gyroSensor1.gyroDev.gyroHardware == gyroSensor2.gyroDev.gyroHardware) { gyroDetectionFlags |= DETECTED_DUAL_GYROS; } else if (gyroToUse == GYRO_CONFIG_USE_GYRO_BOTH) { // If the user selected "BOTH" and they are not the same type, then reset to using only the first gyro.