From c247d358dc6165059eff7fbae07baa676db1c69f Mon Sep 17 00:00:00 2001 From: sfncrp Date: Mon, 7 Oct 2024 17:51:12 +0200 Subject: [PATCH] fixed initialize switch statements --- src/MPU6050.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/MPU6050.cpp b/src/MPU6050.cpp index 957ec2c..c27f7a0 100644 --- a/src/MPU6050.cpp +++ b/src/MPU6050.cpp @@ -93,18 +93,26 @@ void MPU6050_Base::initialize(ACCEL_FS accelRange, GYRO_FS gyroRange) { case ACCEL_FS::A2G: setFullScaleAccelRange(MPU6050_ACCEL_FS_2); accelerationResolution = 2.0 / 16384.0; + break; case ACCEL_FS::A4G: setFullScaleAccelRange(MPU6050_ACCEL_FS_4); accelerationResolution = 4.0 / 16384.0; + break; case ACCEL_FS::A8G: setFullScaleAccelRange(MPU6050_ACCEL_FS_8); accelerationResolution = 8.0 / 16384.0; + break; case ACCEL_FS::A16G: setFullScaleAccelRange(MPU6050_ACCEL_FS_16); accelerationResolution = 16.0 / 16384.0; + break; + default: + Serial.println("Init accelRange not valid, setting maximum accel range"); + setFullScaleAccelRange(MPU6050_ACCEL_FS_16); + accelerationResolution = 16.0 / 16384.0; } switch (gyroRange) @@ -112,18 +120,26 @@ void MPU6050_Base::initialize(ACCEL_FS accelRange, GYRO_FS gyroRange) { case GYRO_FS::G250DPS: setFullScaleGyroRange(MPU6050_GYRO_FS_250); gyroscopeResolution = 250.0 / 16384.0; + break; case GYRO_FS::G500DPS: setFullScaleGyroRange(MPU6050_GYRO_FS_500); gyroscopeResolution = 500.0 / 16384.0; + break; case GYRO_FS::G1000DPS: setFullScaleGyroRange(MPU6050_GYRO_FS_1000); gyroscopeResolution = 1000.0 / 16384.0; + break; case GYRO_FS::G2000DPS: setFullScaleGyroRange(MPU6050_GYRO_FS_2000); gyroscopeResolution = 2000.0 / 16384.0; + break; + default: + Serial.println("Init gyroRange not valid, setting maximum gyro range"); + setFullScaleGyroRange(MPU6050_GYRO_FS_2000); + gyroscopeResolution = 2000.0 / 16384.0; } setSleepEnabled(false); // thanks to Jack Elston for pointing this one out! @@ -3475,4 +3491,4 @@ void MPU6050_Base::PrintActiveOffsets() { Serial.print((float)offsets[3], 5); Serial.print(",\t"); Serial.print((float)offsets[4], 5); Serial.print(",\t"); Serial.print((float)offsets[5], 5); Serial.print("\n\n"); -} \ No newline at end of file +}