C ++方法定义&变量声明

时间:2016-05-12 15:25:34

标签: c++ arduino header-files

我正试图将我的arduino代码库从单个' ino'中分离出来。通过创建具有.h和amp;的类来提交到正确的c ++程序中。 .cpp文件。我遇到了一些我无法解决的错误。我希望我错过了一些简单的事情。

在Visual Studio中编译运行" Arduino IDE for Visual Studio"插件,我收到以下错误:

  

7:8:错误:'类MPU6050'没有名为' timer

的成员      

30:5:错误:原型为' int MPU6050 :: MPU6050_read(int,uint8_t *,int)'不匹配任何类别' MPU6050

我在这里缺少什么?

.h

#ifndef MPU6050_H
#define MPU6050_H


class MPU6050
{

private:  // Vars
    uint32_t timer;  // Hold the value of the timer used for the complementary filter
    int error;

public:  // Methods
    MPU6050();
    ~MPU6050();

    void read_acc_gyr();
    float const * const getXa();
    float const * const getYa();
    float const * const getXvel();
    float const * const getYvel();
    float const * const getZvel();
    float const * const getZang();
    double const * const getDt();

private:
    void test_gyr_acc();
    void MPU6050_init();
    void printGyroValues();
    void calibrateGyro();
    int MPU6050_write(int start, const uint8_t *pData, int size);
    int MPU6050_read(int start, uint8_t *buffer, int size);
    int MPU6050_write_reg(int reg, uint8_t data);
};

#endif

的.cpp

#include "MPU6050.h"
#include "Arduino.h"
#include "MPU6050Definitions.h"

MPU6050::MPU6050()
{
    timer = 0;  // Always start the timer at 0
    error = 1;

    Serial.println("Testing Gyro");
    test_gyr_acc();
}

MPU6050::~MPU6050()
{

}

int MPU6050::MPU6050_read(int start, uint8_t *buffer, int size)
{
    int i, n, error;

    Wire.beginTransmission(MPU6050_I2C_ADDRESS);
    n = Wire.write(start);
    if (n != 1)
        return (-10);

    n = Wire.endTransmission(false);    // hold the I2C-bus
    if (n != 0)
        return (n);

    // Third parameter is true: relase I2C-bus after data is read.
    Wire.requestFrom(MPU6050_I2C_ADDRESS, size, true);
    i = 0;
    while (Wire.available() && i<size)
    {
        buffer[i++] = Wire.read();
    }
    if (i != size)
        return (-11);

    return (0);  // return : no error
}

void MPU6050::test_gyr_acc()
{
    uint8_t c = 0;

    error = MPU6050_read(MPU6050_WHO_AM_I, &c, 1);
    if (error != 0) {
        while (true) {
            digitalWrite(13, HIGH);
            delay(300);
            digitalWrite(13, LOW);
            delay(300);
        }
    }
}

MPUT6050Definitions.h包含了我的所有常量,如下所示:(更多我认为不相关的#defines包括在内)

#pragma once

//All the values to setup the MPU6050 gyro/accelermeter

#define MPU6050_AUX_VDDIO          0x01   // R/W
#define MPU6050_SMPLRT_DIV         0x19   // R/W
#define MPU6050_CONFIG             0x1A   // R/W
#define MPU6050_GYRO_CONFIG        0x1B   // R/W

1 个答案:

答案 0 :(得分:1)

看起来我犯了一个简单的错误。

列表中的一些错误是unknown declaration of type uint_32,它自身传播导致我之前看到的错误。我包含Arduino.h标头,该标头解决了uint_32问题,导致其余代码按预期编译。

故事的道德是不要试图从上到下修复你的错误。

相关问题