lib para o framework sgam

Dependencies:   MPU6050 Grove_temperature

Dependents:   example_smart-grid

peripheral/impl/Gyroscope.cpp

Committer:
AndersonIctus
Date:
2019-06-03
Revision:
4:f21aab30658a
Parent:
3:f998244e9f80
Child:
5:caecc2426bbb

File content as of revision 4:f21aab30658a:

#include "mbed.h"
#include "MPU6050.h"

#include "Gyroscope.h"

#define LOG(args...)   // printf(args)     

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

    if(mpu.testConnection()) {
        LOG("MPU6050 test passed !!\r\n");
    } else {
        LOG("MPU6050 test failed !!\r\n");
    }
}

Gyroscope::~Gyroscope() {
    // mpu.
}

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

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

void Gyroscope::setCallbackReadOcurred( void* (*callback)(GyroscopeData* value) ) {
    Gyroscope::callback = callback;
}

void Gyroscope::run(float timeout) {
    // TODO: every timeout, calls acceptData !!
}

void Gyroscope::acceptDataEvent(GyroscopeData* data) {
    if(Gyroscope::callback != NULL)
        Gyroscope::callback(data);
}