HMC5883L Digital Compass Library
Fork of HMC5883L by
Diff: HMC5883L.h
- Revision:
- 3:f14ad02770e4
- Parent:
- 1:4c295f793d46
diff -r bbc9ad18fd3e -r f14ad02770e4 HMC5883L.h --- a/HMC5883L.h Wed Aug 05 13:16:12 2015 +0000 +++ b/HMC5883L.h Wed May 30 19:14:58 2018 +0000 @@ -28,8 +28,7 @@ #include "mbed.h" #include "math.h" -#include "ledControl.h" - +#define M_PI 3.14159265359 #define PI 3.14159265359 #define GAUSS_TO_MICROTESLA 100 #define HMC5883L_ADDRESS 0x3C @@ -48,8 +47,37 @@ #define ID_A 0x0A #define ID_B 0x0B #define ID_C 0x0C +#define COMPASS_SCALE_088 0x00 << 2 +#define COMPASS_SCALE_130 0x01 << 2 +#define COMPASS_SCALE_190 0x02 << 2 +#define COMPASS_SCALE_250 0x03 << 2 +#define COMPASS_SCALE_400 0x04 << 2 +#define COMPASS_SCALE_470 0x05 << 2 +#define COMPASS_SCALE_560 0x06 << 2 +#define COMPASS_SCALE_810 0x07 << 2 +// xxXXXYYYZZZxxxxx +// ORIENTATION: +#define COMPASS_NORTH 0x00 +#define COMPASS_SOUTH 0x01 +#define COMPASS_WEST 0x02 +#define COMPASS_EAST 0x03 +#define COMPASS_UP 0x04 +#define COMPASS_DOWN 0x05 +#define COMPASS_CONTINUOUS 0x00 +#define COMPASS_SINGLE 0x01 +#define COMPASS_IDLE 0x02 + + +// When "pointing" north, define the direction of each of the silkscreen'd arrows +// (imagine the Z arrow points out of the top of the device) only N/S/E/W are allowed +#define COMPASS_HORIZONTAL_X_NORTH ( (COMPASS_NORTH << 6) | (COMPASS_WEST << 3) | COMPASS_UP ) << 5 +#define COMPASS_HORIZONTAL_Y_NORTH ( (COMPASS_EAST << 6) | (COMPASS_NORTH << 3) | COMPASS_UP ) << 5 +#define COMPASS_VERTICAL_X_EAST ( (COMPASS_EAST << 6) | (COMPASS_UP << 3) | COMPASS_SOUTH ) << 5 +#define COMPASS_VERTICAL_Y_WEST ( (COMPASS_UP << 6) | (COMPASS_WEST << 3) | COMPASS_SOUTH ) << 5 /* Magnetometer Gain Settings */ + + enum MagGain { MagGain_088 = 0x00, // +/- 0.88 Ga @@ -68,8 +96,10 @@ void init(); double getHeading(); void readMagData(float* dest); + void setScale(uint16_t sampling_mode ); + void setOrientation(uint16_t sampling_mode ); private: - void setMagGain(MagGain gain); + void writeByte(uint8_t address, uint8_t regAddress, uint8_t data); char readByte(uint8_t address, uint8_t regAddress); void readBytes(uint8_t address, uint8_t regAddress, uint8_t byteNum, uint8_t* dest);