From 907ccfa2200a9d2de09298bc2eea6e75089968a9 Mon Sep 17 00:00:00 2001 From: Mahboud Zabetian Date: Sat, 12 Mar 2022 18:42:48 -0800 Subject: [PATCH 1/6] Add gyro, accelerometer, and temperature enable/disable. --- Adafruit_MPU6050.cpp | 68 ++++++++++++++++++++++++++++++++++++++++++++ Adafruit_MPU6050.h | 9 ++++++ 2 files changed, 77 insertions(+) diff --git a/Adafruit_MPU6050.cpp b/Adafruit_MPU6050.cpp index 13f4b31..0e684d3 100644 --- a/Adafruit_MPU6050.cpp +++ b/Adafruit_MPU6050.cpp @@ -551,6 +551,74 @@ void Adafruit_MPU6050::setCycleRate(mpu6050_cycle_rate_t rate) { cycle_rate.write(rate); } +/**************************************************************************/ +/*! + * @brief Sets standbye mode for each of the gyroscope axes. + * @param xAxisEnable + * If `true` the gyroscope stops sensing in the X-axis. + * Setting `false` resumes X-axis sensing. + * @param yAxisEnable + * If `true` the gyroscope stops sensing in the Y-axis. + * Setting `false` resumes Y-axis sensing. + * @param zAxisEnable + * If `true` the gyroscope stops sensing in the Z-axis. + * Setting `false` resumes Z-axis sensing. + * @return True if setting was successful, otherwise false. + */ +/**************************************************************************/ +bool Adafruit_MPU6050::enableGyroStandby(bool xAxisEnable, bool yAxisEnable, bool zAxisEnable) { + Adafruit_BusIO_Register pwr_mgmt_2 = + Adafruit_BusIO_Register(i2c_dev, MPU6050_PWR_MGMT_2, 1); + + Adafruit_BusIO_RegisterBits gyro_stdby = + Adafruit_BusIO_RegisterBits(&pwr_mgmt_2, 3, 0); + return gyro_stdby.write(xAxisEnable << 2 | yAxisEnable << 1 | zAxisEnable); +} + +/**************************************************************************/ +/*! + * @brief Sets standbye mode for each of the accelerometer axes. + * @param xAxisEnable + * If `true` the accelerometer stops sensing in the X-axis. + * Setting `false` resumes X-axis sensing. + * @param yAxisEnable + * If `true` the accelerometer stops sensing in the Y-axis. + * Setting `false` resumes Y-axis sensing. + * @param zAxisEnable + * If `true` the accelerometer stops sensing in the Z-axis. + * Setting `false` resumes Z-axis sensing. + * @return True if setting was successful, otherwise false. + */ +/**************************************************************************/ +bool Adafruit_MPU6050::enableAccelerometerStandby(bool xAxisEnable, bool yAxisEnable, + bool zAxisEnable) { + Adafruit_BusIO_Register pwr_mgmt_2 = + Adafruit_BusIO_Register(i2c_dev, MPU6050_PWR_MGMT_2, 1); + + Adafruit_BusIO_RegisterBits accel_stdby = + Adafruit_BusIO_RegisterBits(&pwr_mgmt_2, 3, 3); + return accel_stdby.write(xAxisEnable << 2 | yAxisEnable << 1 | zAxisEnable); +} + +/**************************************************************************/ +/*! + * @brief Sets disable mode for thermometer sensor. + * @param enable + * If `true` the temperature sensor will stop taking measurements. + * Setting `false` returns the temperature sensor to the normal + * measurement mode. + * @return True if setting was successful, otherwise false. + */ +/**************************************************************************/ +bool Adafruit_MPU6050::enableTemperatureStandby(bool enable) { + Adafruit_BusIO_Register pwr_mgmt = + Adafruit_BusIO_Register(i2c_dev, MPU6050_PWR_MGMT_1, 1); + + Adafruit_BusIO_RegisterBits temp_stdby = + Adafruit_BusIO_RegisterBits(&pwr_mgmt, 1, 3); + return temp_stdby.write(1); +} + /******************* Adafruit_Sensor functions *****************/ /*! * @brief Updates the measurement data for all sensors simultaneously diff --git a/Adafruit_MPU6050.h b/Adafruit_MPU6050.h index 942e247..4e052fe 100644 --- a/Adafruit_MPU6050.h +++ b/Adafruit_MPU6050.h @@ -250,6 +250,15 @@ class Adafruit_MPU6050 { void setCycleRate(mpu6050_cycle_rate_t rate); mpu6050_cycle_rate_t getCycleRate(void); + + bool enableGyroStandby(bool xAxisEnable, + bool yAxisEnable, + bool zAxisEnable); + bool enableAccelerometerStandby(bool xAxisEnable, + bool yAxisEnable, + bool zAxisEnable); + bool enableTemperatureStandby(bool enable); + void reset(void); Adafruit_Sensor *getTemperatureSensor(void); From 74128a1aedbb9f62d39990e5f71fef44f036387d Mon Sep 17 00:00:00 2001 From: Mahboud Zabetian Date: Sat, 12 Mar 2022 19:20:28 -0800 Subject: [PATCH 2/6] Text formatting. --- Adafruit_MPU6050.cpp | 6 ++++-- Adafruit_MPU6050.h | 7 ++----- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/Adafruit_MPU6050.cpp b/Adafruit_MPU6050.cpp index 0e684d3..e8bdc30 100644 --- a/Adafruit_MPU6050.cpp +++ b/Adafruit_MPU6050.cpp @@ -566,7 +566,8 @@ void Adafruit_MPU6050::setCycleRate(mpu6050_cycle_rate_t rate) { * @return True if setting was successful, otherwise false. */ /**************************************************************************/ -bool Adafruit_MPU6050::enableGyroStandby(bool xAxisEnable, bool yAxisEnable, bool zAxisEnable) { +bool Adafruit_MPU6050::enableGyroStandby(bool xAxisEnable, bool yAxisEnable, + bool zAxisEnable) { Adafruit_BusIO_Register pwr_mgmt_2 = Adafruit_BusIO_Register(i2c_dev, MPU6050_PWR_MGMT_2, 1); @@ -590,7 +591,8 @@ bool Adafruit_MPU6050::enableGyroStandby(bool xAxisEnable, bool yAxisEnable, boo * @return True if setting was successful, otherwise false. */ /**************************************************************************/ -bool Adafruit_MPU6050::enableAccelerometerStandby(bool xAxisEnable, bool yAxisEnable, +bool Adafruit_MPU6050::enableAccelerometerStandby(bool xAxisEnable, + bool yAxisEnable, bool zAxisEnable) { Adafruit_BusIO_Register pwr_mgmt_2 = Adafruit_BusIO_Register(i2c_dev, MPU6050_PWR_MGMT_2, 1); diff --git a/Adafruit_MPU6050.h b/Adafruit_MPU6050.h index 4e052fe..392e0bc 100644 --- a/Adafruit_MPU6050.h +++ b/Adafruit_MPU6050.h @@ -251,11 +251,8 @@ class Adafruit_MPU6050 { void setCycleRate(mpu6050_cycle_rate_t rate); mpu6050_cycle_rate_t getCycleRate(void); - bool enableGyroStandby(bool xAxisEnable, - bool yAxisEnable, - bool zAxisEnable); - bool enableAccelerometerStandby(bool xAxisEnable, - bool yAxisEnable, + bool enableGyroStandby(bool xAxisEnable, bool yAxisEnable, bool zAxisEnable); + bool enableAccelerometerStandby(bool xAxisEnable, bool yAxisEnable, bool zAxisEnable); bool enableTemperatureStandby(bool enable); From 80ff985cc13568b2872877058e0a18aa23e2d602 Mon Sep 17 00:00:00 2001 From: Mahboud Zabetian Date: Sun, 13 Mar 2022 13:01:41 -0700 Subject: [PATCH 3/6] changed method names --- Adafruit_MPU6050.cpp | 12 ++++++------ Adafruit_MPU6050.h | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Adafruit_MPU6050.cpp b/Adafruit_MPU6050.cpp index e8bdc30..d0a308d 100644 --- a/Adafruit_MPU6050.cpp +++ b/Adafruit_MPU6050.cpp @@ -566,8 +566,8 @@ void Adafruit_MPU6050::setCycleRate(mpu6050_cycle_rate_t rate) { * @return True if setting was successful, otherwise false. */ /**************************************************************************/ -bool Adafruit_MPU6050::enableGyroStandby(bool xAxisEnable, bool yAxisEnable, - bool zAxisEnable) { +bool Adafruit_MPU6050::setGyroStandby(bool xAxisEnable, bool yAxisEnable, + bool zAxisEnable) { Adafruit_BusIO_Register pwr_mgmt_2 = Adafruit_BusIO_Register(i2c_dev, MPU6050_PWR_MGMT_2, 1); @@ -591,9 +591,9 @@ bool Adafruit_MPU6050::enableGyroStandby(bool xAxisEnable, bool yAxisEnable, * @return True if setting was successful, otherwise false. */ /**************************************************************************/ -bool Adafruit_MPU6050::enableAccelerometerStandby(bool xAxisEnable, - bool yAxisEnable, - bool zAxisEnable) { +bool Adafruit_MPU6050::setAccelerometerStandby(bool xAxisEnable, + bool yAxisEnable, + bool zAxisEnable) { Adafruit_BusIO_Register pwr_mgmt_2 = Adafruit_BusIO_Register(i2c_dev, MPU6050_PWR_MGMT_2, 1); @@ -612,7 +612,7 @@ bool Adafruit_MPU6050::enableAccelerometerStandby(bool xAxisEnable, * @return True if setting was successful, otherwise false. */ /**************************************************************************/ -bool Adafruit_MPU6050::enableTemperatureStandby(bool enable) { +bool Adafruit_MPU6050::setTemperatureStandby(bool enable) { Adafruit_BusIO_Register pwr_mgmt = Adafruit_BusIO_Register(i2c_dev, MPU6050_PWR_MGMT_1, 1); diff --git a/Adafruit_MPU6050.h b/Adafruit_MPU6050.h index 392e0bc..b24aaf8 100644 --- a/Adafruit_MPU6050.h +++ b/Adafruit_MPU6050.h @@ -251,10 +251,10 @@ class Adafruit_MPU6050 { void setCycleRate(mpu6050_cycle_rate_t rate); mpu6050_cycle_rate_t getCycleRate(void); - bool enableGyroStandby(bool xAxisEnable, bool yAxisEnable, bool zAxisEnable); - bool enableAccelerometerStandby(bool xAxisEnable, bool yAxisEnable, - bool zAxisEnable); - bool enableTemperatureStandby(bool enable); + bool setGyroStandby(bool xAxisEnable, bool yAxisEnable, bool zAxisEnable); + bool setAccelerometerStandby(bool xAxisEnable, bool yAxisEnable, + bool zAxisEnable); + bool setTemperatureStandby(bool enable); void reset(void); From 53930c45d7c884ec5d535ee35a6598bd7cb1cd88 Mon Sep 17 00:00:00 2001 From: Mahboud Zabetian Date: Sun, 13 Mar 2022 14:22:46 -0700 Subject: [PATCH 4/6] changed method arguments --- Adafruit_MPU6050.cpp | 26 +++++++++++++------------- Adafruit_MPU6050.h | 6 +++--- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/Adafruit_MPU6050.cpp b/Adafruit_MPU6050.cpp index d0a308d..ad704eb 100644 --- a/Adafruit_MPU6050.cpp +++ b/Adafruit_MPU6050.cpp @@ -554,52 +554,52 @@ void Adafruit_MPU6050::setCycleRate(mpu6050_cycle_rate_t rate) { /**************************************************************************/ /*! * @brief Sets standbye mode for each of the gyroscope axes. - * @param xAxisEnable + * @param xAxisStandby * If `true` the gyroscope stops sensing in the X-axis. * Setting `false` resumes X-axis sensing. - * @param yAxisEnable + * @param yAxisStandby * If `true` the gyroscope stops sensing in the Y-axis. * Setting `false` resumes Y-axis sensing. - * @param zAxisEnable + * @param zAxisStandby * If `true` the gyroscope stops sensing in the Z-axis. * Setting `false` resumes Z-axis sensing. * @return True if setting was successful, otherwise false. */ /**************************************************************************/ -bool Adafruit_MPU6050::setGyroStandby(bool xAxisEnable, bool yAxisEnable, - bool zAxisEnable) { +bool Adafruit_MPU6050::setGyroStandby(bool xAxisStandby, bool yAxisStandby, + bool zAxisStandby) { Adafruit_BusIO_Register pwr_mgmt_2 = Adafruit_BusIO_Register(i2c_dev, MPU6050_PWR_MGMT_2, 1); Adafruit_BusIO_RegisterBits gyro_stdby = Adafruit_BusIO_RegisterBits(&pwr_mgmt_2, 3, 0); - return gyro_stdby.write(xAxisEnable << 2 | yAxisEnable << 1 | zAxisEnable); + return gyro_stdby.write(xAxisStandby << 2 | yAxisStandby << 1 | zAxisStandby); } /**************************************************************************/ /*! * @brief Sets standbye mode for each of the accelerometer axes. - * @param xAxisEnable + * @param xAxisStandby * If `true` the accelerometer stops sensing in the X-axis. * Setting `false` resumes X-axis sensing. - * @param yAxisEnable + * @param yAxisStandby * If `true` the accelerometer stops sensing in the Y-axis. * Setting `false` resumes Y-axis sensing. - * @param zAxisEnable + * @param zAxisStandby * If `true` the accelerometer stops sensing in the Z-axis. * Setting `false` resumes Z-axis sensing. * @return True if setting was successful, otherwise false. */ /**************************************************************************/ -bool Adafruit_MPU6050::setAccelerometerStandby(bool xAxisEnable, - bool yAxisEnable, - bool zAxisEnable) { +bool Adafruit_MPU6050::setAccelerometerStandby(bool xAxisStandby, + bool yAxisStandby, + bool zAxisStandby) { Adafruit_BusIO_Register pwr_mgmt_2 = Adafruit_BusIO_Register(i2c_dev, MPU6050_PWR_MGMT_2, 1); Adafruit_BusIO_RegisterBits accel_stdby = Adafruit_BusIO_RegisterBits(&pwr_mgmt_2, 3, 3); - return accel_stdby.write(xAxisEnable << 2 | yAxisEnable << 1 | zAxisEnable); + return accel_stdby.write(xAxisStandby << 2 | yAxisStandby << 1 | zAxisStandby); } /**************************************************************************/ diff --git a/Adafruit_MPU6050.h b/Adafruit_MPU6050.h index b24aaf8..1a16a64 100644 --- a/Adafruit_MPU6050.h +++ b/Adafruit_MPU6050.h @@ -251,9 +251,9 @@ class Adafruit_MPU6050 { void setCycleRate(mpu6050_cycle_rate_t rate); mpu6050_cycle_rate_t getCycleRate(void); - bool setGyroStandby(bool xAxisEnable, bool yAxisEnable, bool zAxisEnable); - bool setAccelerometerStandby(bool xAxisEnable, bool yAxisEnable, - bool zAxisEnable); + bool setGyroStandby(bool xAxisStandby, bool yAxisStandby, bool zAxisStandby); + bool setAccelerometerStandby(bool xAxisStandby, bool yAxisStandby, + bool zAxisStandby); bool setTemperatureStandby(bool enable); void reset(void); From b87299a93774cb8fbd379f978ff9161bc21f0b9f Mon Sep 17 00:00:00 2001 From: Mahboud Zabetian Date: Sun, 13 Mar 2022 15:45:05 -0700 Subject: [PATCH 5/6] clang reformatting --- Adafruit_MPU6050.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Adafruit_MPU6050.cpp b/Adafruit_MPU6050.cpp index ad704eb..e79bad0 100644 --- a/Adafruit_MPU6050.cpp +++ b/Adafruit_MPU6050.cpp @@ -573,7 +573,8 @@ bool Adafruit_MPU6050::setGyroStandby(bool xAxisStandby, bool yAxisStandby, Adafruit_BusIO_RegisterBits gyro_stdby = Adafruit_BusIO_RegisterBits(&pwr_mgmt_2, 3, 0); - return gyro_stdby.write(xAxisStandby << 2 | yAxisStandby << 1 | zAxisStandby); + return gyro_stdby.write(xAxisStandby << 2 | yAxisStandby << 1 | + zAxisStandby); } /**************************************************************************/ @@ -599,7 +600,8 @@ bool Adafruit_MPU6050::setAccelerometerStandby(bool xAxisStandby, Adafruit_BusIO_RegisterBits accel_stdby = Adafruit_BusIO_RegisterBits(&pwr_mgmt_2, 3, 3); - return accel_stdby.write(xAxisStandby << 2 | yAxisStandby << 1 | zAxisStandby); + return accel_stdby.write(xAxisStandby << 2 | yAxisStandby << 1 | + zAxisStandby); } /**************************************************************************/ From daf6d4ef77bb318261aa4c2d45af1ea7053e3af6 Mon Sep 17 00:00:00 2001 From: Mahboud Zabetian Date: Sun, 13 Mar 2022 15:56:26 -0700 Subject: [PATCH 6/6] clang reformatting 2 --- Adafruit_MPU6050.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Adafruit_MPU6050.cpp b/Adafruit_MPU6050.cpp index e79bad0..e976071 100644 --- a/Adafruit_MPU6050.cpp +++ b/Adafruit_MPU6050.cpp @@ -573,8 +573,7 @@ bool Adafruit_MPU6050::setGyroStandby(bool xAxisStandby, bool yAxisStandby, Adafruit_BusIO_RegisterBits gyro_stdby = Adafruit_BusIO_RegisterBits(&pwr_mgmt_2, 3, 0); - return gyro_stdby.write(xAxisStandby << 2 | yAxisStandby << 1 | - zAxisStandby); + return gyro_stdby.write(xAxisStandby << 2 | yAxisStandby << 1 | zAxisStandby); } /**************************************************************************/