I'm working on an Arduino project and I need to use HMC5883L sensor's libraries. The problem is that the libraries are kind old and my compiler is complaining about the 'return' from a function:
/home/leandro/arduino-1.6.1/libraries/HMC5883L/HMC5883L.cpp: In member function 'uint8_t* HMC5883L::Read(int, int)':
/home/leandro/arduino-1.6.1/libraries/HMC5883L/HMC5883L.cpp:124:11: warning: address of local variable 'buffer' returned [-Wreturn-local-addr]
uint8_t buffer[length];
The part of the code is:
HMC5883L.cpp
uint8_t* HMC5883L::Read(int address, int length)
{
Wire.beginTransmission(HMC5883L_Address);
Wire.write(address);
Wire.endTransmission();
Wire.beginTransmission(HMC5883L_Address);
Wire.requestFrom(HMC5883L_Address, length);
uint8_t buffer[length]; // Here is line 124
if(Wire.available() == length)
{
for(uint8_t i = 0; i < length; i++)
{
buffer[i] = Wire.read();
}
}
Wire.endTransmission();
return buffer;
}
HMC5883L.h:
#ifndef HMC5883L_h
#define HMC5883L_h
#include <Arduino.h>
#include <Wire.h>
#define HMC5883L_Address 0x1E
#define ConfigurationRegisterA 0x00
#define ConfigurationRegisterB 0x01
#define ModeRegister 0x02
#define DataRegisterBegin 0x03
#define Measurement_Continuous 0x00
#define Measurement_SingleShot 0x01
#define Measurement_Idle 0x03
#define ErrorCode_1 "Entered scale was not valid, valid gauss values are: 0.88, 1.3, 1.9, 2.5, 4.0, 4.7, 5.6, 8.1"
#define ErrorCode_1_Num 1
struct MagnetometerScaled
{
float XAxis;
float YAxis;
float ZAxis;
};
struct MagnetometerRaw
{
int XAxis;
int YAxis;
int ZAxis;
};
class HMC5883L
{
public:
HMC5883L();
MagnetometerRaw ReadRawAxis();
MagnetometerScaled ReadScaledAxis();
int SetMeasurementMode(uint8_t mode);
int SetScale(float gauss);
const char* GetErrorText(int errorCode);
protected:
void Write(int address, int byte);
uint8_t* Read(int address, int length);
private:
float m_Scale;
};
#endif
I tried few suggestions from here, here and here without success. Maybe I just couldn't figure out on how to solve this issue using those suggestion.
EDIT: There was an typo on my code, just changed it.