Fixed crash bug in gyro.cpp

This commit is contained in:
Magnus Persson 2022-01-13 09:08:53 +01:00
parent adc21b5527
commit 5b6ce7d672
2 changed files with 3 additions and 3 deletions

View File

@ -25,6 +25,7 @@ SOFTWARE.
#include <helper.hpp> #include <helper.hpp>
GyroSensor myGyro; GyroSensor myGyro;
MPU6050 accelgyro;
#define GYRO_USE_INTERRUPT // Use interrupt to detect when new sample is ready #define GYRO_USE_INTERRUPT // Use interrupt to detect when new sample is ready
#define SENSOR_MOVING_THREASHOLD 500 #define SENSOR_MOVING_THREASHOLD 500
@ -45,8 +46,7 @@ bool GyroSensor::setup() {
Wire.begin(D3, D4); Wire.begin(D3, D4);
Wire.setClock(400000); // 400kHz I2C clock. Comment this line if having Wire.setClock(400000); // 400kHz I2C clock. Comment this line if having
// compilation difficulties // compilation difficulties
accelgyro.initialize();
if (!accelgyro.testConnection()) { if (!accelgyro.testConnection()) {
Log.error(F("GYRO: Failed to connect to MPU6050 (gyro)." CR)); Log.error(F("GYRO: Failed to connect to MPU6050 (gyro)." CR));
sensorConnected = false; sensorConnected = false;
@ -54,6 +54,7 @@ bool GyroSensor::setup() {
#if !defined(GYRO_DISABLE_LOGGING) #if !defined(GYRO_DISABLE_LOGGING)
Log.notice(F("GYRO: Connected to MPU6050 (gyro)." CR)); Log.notice(F("GYRO: Connected to MPU6050 (gyro)." CR));
#endif #endif
accelgyro.initialize();
sensorConnected = true; sensorConnected = true;
// Configure the sensor // Configure the sensor

View File

@ -50,7 +50,6 @@ struct RawGyroDataL { // Used for average multiple readings
class GyroSensor { class GyroSensor {
private: private:
MPU6050 accelgyro;
bool sensorConnected = false; bool sensorConnected = false;
bool validValue = false; bool validValue = false;
float angle = 0; float angle = 0;