Skip to content

Commit

Permalink
Merge pull request #20 from mahboud/new-standby-methods
Browse files Browse the repository at this point in the history
Add gyro, accelerometer, and temperature enable/disable.
  • Loading branch information
ladyada authored Mar 13, 2022
2 parents 0f482b0 + daf6d4e commit dd977d8
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
71 changes: 71 additions & 0 deletions Adafruit_MPU6050.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,77 @@ void Adafruit_MPU6050::setCycleRate(mpu6050_cycle_rate_t rate) {
cycle_rate.write(rate);
}

/**************************************************************************/
/*!
* @brief Sets standbye mode for each of the gyroscope axes.
* @param xAxisStandby
* If `true` the gyroscope stops sensing in the X-axis.
* Setting `false` resumes X-axis sensing.
* @param yAxisStandby
* If `true` the gyroscope stops sensing in the Y-axis.
* Setting `false` resumes Y-axis sensing.
* @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 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(xAxisStandby << 2 | yAxisStandby << 1 | zAxisStandby);
}

/**************************************************************************/
/*!
* @brief Sets standbye mode for each of the accelerometer axes.
* @param xAxisStandby
* If `true` the accelerometer stops sensing in the X-axis.
* Setting `false` resumes X-axis sensing.
* @param yAxisStandby
* If `true` the accelerometer stops sensing in the Y-axis.
* Setting `false` resumes Y-axis sensing.
* @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 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(xAxisStandby << 2 | yAxisStandby << 1 |
zAxisStandby);
}

/**************************************************************************/
/*!
* @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::setTemperatureStandby(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
Expand Down
6 changes: 6 additions & 0 deletions Adafruit_MPU6050.h
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,12 @@ class Adafruit_MPU6050 {

void setCycleRate(mpu6050_cycle_rate_t rate);
mpu6050_cycle_rate_t getCycleRate(void);

bool setGyroStandby(bool xAxisStandby, bool yAxisStandby, bool zAxisStandby);
bool setAccelerometerStandby(bool xAxisStandby, bool yAxisStandby,
bool zAxisStandby);
bool setTemperatureStandby(bool enable);

void reset(void);

Adafruit_Sensor *getTemperatureSensor(void);
Expand Down

0 comments on commit dd977d8

Please sign in to comment.