Dependencies:   MPU6050 Grove_temperature

Dependents:   sgam_mdw_test

sensor/gyroscope/Gyroscope.cpp

Committer:
AndersonIctus
Date:
2019-06-22
Revision:
5:fa36c3288be8
Parent:
3:f67352c85fd7
Child:
6:806043bf1a2c

File content as of revision 5:fa36c3288be8:

#include "sgam_mdw.h"
#include "mbed.h"

#include "MPU6050.h"
#include "Gyroscope.h"

Gyroscope::Gyroscope(I2C &i2c): mpu(i2c, MPU6050_ADDRESS_AD0_LOW) { 
    mpu.initialize();

    if( mpu.testConnection() ) {
        LOG("Giroscope Initialized !!\r\n");
    } else {
        LOG("There's an error trying initialize the Gyroscope !!\r\n");
    }

    value = new GyroscopeData();
}

Gyroscope::~Gyroscope() {
    value->~GyroscopeData();
}

int Gyroscope::initialize() { return 1; }
int Gyroscope::finalize() { return 1; }

void Gyroscope::getMotion(GyroscopeData* data) {
    mpu.getMotion6(
        &data->ax, &data->ay, &data->az,
        &data->gx, &data->gy, &data->gz
    );
}

GyroscopeData* Gyroscope::getValue() {
    getMotion(value);
    return value;
}

const char* Gyroscope::getName() { 
    return "Gyroscope"; 
}