Code: Select all
In file included from magsensor.ino:34:
C:\Program Files (x86)\Arduino\libraries\Adafruit_HMC5883_Unified/Adafruit_HMC5883_U.h:93: error: expected class-name before '{' token
C:\Program Files (x86)\Arduino\libraries\Adafruit_HMC5883_Unified/Adafruit_HMC5883_U.h:99: error: 'sensors_event_t' has not been declared
C:\Program Files (x86)\Arduino\libraries\Adafruit_HMC5883_Unified/Adafruit_HMC5883_U.h:100: error: 'sensor_t' has not been declared
magsensor.ino: In function 'void displaySensorDetails()':
magsensor:41: error: 'sensor_t' was not declared in this scope
magsensor:41: error: expected `;' before 'sensor'
magsensor:42: error: 'sensor' was not declared in this scope
magsensor.ino: In function 'void loop()':
magsensor:75: error: 'sensors_event_t' was not declared in this scope
magsensor:75: error: expected `;' before 'event'
magsensor:76: error: 'event' was not declared in this scope
Code: Select all
/***************************************************************************
This is a library for the HMC5883 magnentometer/compass
Designed specifically to work with the Adafruit HMC5883 Breakout
http://www.adafruit.com/products/1746
These displays use I2C to communicate, 2 pins are required to interface.
Adafruit invests time and resources providing this open source code,
please support Adafruit andopen-source hardware by purchasing products
from Adafruit!
Written by Kevin Townsend for Adafruit Industries.
BSD license, all text above must be included in any redistribution
***************************************************************************/
#ifndef __HMC5883_H__
#define __HMC5883_H__
#if (ARDUINO >= 100)
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
#include <Adafruit_Sensor.h>
#include <Wire.h>
/*=========================================================================
I2C ADDRESS/BITS
-----------------------------------------------------------------------*/
#define HMC5883_ADDRESS_MAG (0x3C >> 1) // 0011110x
/*=========================================================================*/
/*=========================================================================
REGISTERS
-----------------------------------------------------------------------*/
typedef enum
{
HMC5883_REGISTER_MAG_CRA_REG_M = 0x00,
HMC5883_REGISTER_MAG_CRB_REG_M = 0x01,
HMC5883_REGISTER_MAG_MR_REG_M = 0x02,
HMC5883_REGISTER_MAG_OUT_X_H_M = 0x03,
HMC5883_REGISTER_MAG_OUT_X_L_M = 0x04,
HMC5883_REGISTER_MAG_OUT_Z_H_M = 0x05,
HMC5883_REGISTER_MAG_OUT_Z_L_M = 0x06,
HMC5883_REGISTER_MAG_OUT_Y_H_M = 0x07,
HMC5883_REGISTER_MAG_OUT_Y_L_M = 0x08,
HMC5883_REGISTER_MAG_SR_REG_Mg = 0x09,
HMC5883_REGISTER_MAG_IRA_REG_M = 0x0A,
HMC5883_REGISTER_MAG_IRB_REG_M = 0x0B,
HMC5883_REGISTER_MAG_IRC_REG_M = 0x0C,
HMC5883_REGISTER_MAG_TEMP_OUT_H_M = 0x31,
HMC5883_REGISTER_MAG_TEMP_OUT_L_M = 0x32
} hmc5883MagRegisters_t;
/*=========================================================================*/
/*=========================================================================
MAGNETOMETER GAIN SETTINGS
-----------------------------------------------------------------------*/
typedef enum
{
HMC5883_MAGGAIN_1_3 = 0x20, // +/- 1.3
HMC5883_MAGGAIN_1_9 = 0x40, // +/- 1.9
HMC5883_MAGGAIN_2_5 = 0x60, // +/- 2.5
HMC5883_MAGGAIN_4_0 = 0x80, // +/- 4.0
HMC5883_MAGGAIN_4_7 = 0xA0, // +/- 4.7
HMC5883_MAGGAIN_5_6 = 0xC0, // +/- 5.6
HMC5883_MAGGAIN_8_1 = 0xE0 // +/- 8.1
} hmc5883MagGain;
/*=========================================================================*/
/*=========================================================================
INTERNAL MAGNETOMETER DATA TYPE
-----------------------------------------------------------------------*/
typedef struct hmc5883MagData_s
{
float x;
float y;
float z;
float orientation;
} hmc5883MagData;
/*=========================================================================*/
/*=========================================================================
CHIP ID
-----------------------------------------------------------------------*/
#define HMC5883_ID (0b11010100)
/*=========================================================================*/
/* Unified sensor driver for the magnetometer */
class Adafruit_HMC5883_Unified : public Adafruit_Sensor
{
public:
Adafruit_HMC5883_Unified(int32_t sensorID = -1);
bool begin(void);
void setMagGain(hmc5883MagGain gain);
void getEvent(sensors_event_t*);
void getSensor(sensor_t*);
private:
hmc5883MagGain _magGain;
hmc5883MagData _magData; // Last read magnetometer data will be available here
int32_t _sensorID;
void write8(byte address, byte reg, byte value);
byte read8(byte address, byte reg);
void read(void);
};
#endif