roverSTM  UM2 2013
Projet M1 Navarro Benjamin
 All Classes Files Functions Groups Pages
HMC5883L.h
1 /*
2  * HMC5883L.h
3  *
4  * Created on: 9 fŽvr. 2013
5  * Author: Benjamin Navarro
6  */
7 
8 #ifndef HMC5883L_H_
9 #define HMC5883L_H_
10 
11 #include <stm32f4xx.h>
12 #include <math.h>
13 #include <string>
14 #include <iostream>
15 
16 #include "MyLib.h"
17 #include "I2CDevice.h"
18 
19 
20 using namespace std ;
21 
22 typedef enum {
23  Continous = 0,
24  SingleShot = 1,
25  Idle = 3
26 } CompasMesMode;
27 
28 typedef enum {
29  GAUSS_088 = 0,
30  GAUSS_130 = 1,
31  GAUSS_190 = 2,
32  GAUSS_250 = 3,
33  GAUSS_400 = 4,
34  GAUSS_470 = 5,
35  GAUSS_560 = 6,
36  GAUSS_810 = 7
37 } CompasScale;
38 
39 typedef enum {
40  AvgSamples_1 = 0,
41  AvgSamples_2 = 32,
42  AvgSamples_4 = 64,
43  AvgSamples_8 = 96
44 } CompasAverageSamples;
45 
46 typedef enum {
47  DataRate_0_75 = 0,
48  DataRate_1_5 = 4,
49  DataRate_3 = 8,
50  DataRate_7_5 = 12,
51  DataRate_15 = 16,
52  DataRate_30 = 20,
53  DataRate_75 = 24
54 } CompasDataRate;
55 
56 class HMC5883L : public I2CDevice {
57 public:
58 
59  HMC5883L(I2C_TypeDef* I2C_Port, uint8_t address = 0x3C, uint32_t speed = 100000);
60 
61  int16x3 getRawData();
62  floatx3 getScaledValues();
63  float getHeading();
64  float getTiltCompensatedHeading(rollpitch angles);
65  string getID();
66 
67  void setScale(CompasScale s);
68  void setMode(CompasMesMode m, CompasAverageSamples avg = AvgSamples_1, CompasDataRate rate = DataRate_15);
69 
70 private:
71  enum registers {
72  Config_A = 0x00,
73  Config_B = 0x01,
74  Mode = 0x02,
75  Data_XH = 0x03,
76  Data_XL = 0x04,
77  Data_ZH = 0x05,
78  Data_ZL = 0x06,
79  Data_YH = 0x07,
80  Data_YL = 0x08,
81  Satus = 0x09,
82  Ident_A = 0x0A,
83  Ident_B = 0x0B,
84  Ident_C = 0x0C
85  };
86 
87  float scale;
88 
89 };
90 
91 
92 #endif /* HMC5883L_H_ */