Anderson Cunha / sgam_mdw_NUCLEOF429ZI_impl

Dependencies:   MPU6050 Grove_temperature

Dependents:   sgam_mdw_test

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Gyroscope.cpp Source File

Gyroscope.cpp

00001 #include "sgam_mdw.h"
00002 #include "mbed.h"
00003 
00004 #include "MPU6050.h"
00005 #include "Gyroscope.h"
00006 
00007 Gyroscope::Gyroscope(I2C &i2c): mpu(i2c, MPU6050_ADDRESS_AD0_LOW) { 
00008     mpu.initialize();
00009 
00010     if( mpu.testConnection() ) {
00011         D_LOG("Giroscope Initialized !!\r\n");
00012     } else {
00013         D_LOG("There's an error trying initialize the Gyroscope !!\r\n");
00014     }
00015 
00016     value = new GyroscopeData();
00017 }
00018 
00019 Gyroscope::~Gyroscope() {
00020     value->~GyroscopeData();
00021 }
00022 
00023 int Gyroscope::initialize() { D_LOG("INITIALIZE %s! \r\n", this->getName() ); return 1; }
00024 int Gyroscope::finalize() { D_LOG("FINALIZE %s! \r\n", this->getName() ); return 1; }
00025 
00026 void Gyroscope::getMotion(GyroscopeData* data) {
00027     mpu.getMotion6(
00028         &data->ax, &data->ay, &data->az,
00029         &data->gx, &data->gy, &data->gz
00030     );
00031 }
00032 
00033 GyroscopeData* Gyroscope::getValue() {
00034     getMotion(value);
00035     return value;
00036 }
00037 
00038 const char* Gyroscope::getName() { 
00039     return "Gyroscope"; 
00040 }