Add Imu Magnetometer and persistent memory setting so oxs_configurator
[openXsensor.git] / openXsensor / oXs_ms5611.h
blob368708eb86b5e4f54f509c66c010aad4ef987ef8
1 #ifndef OXS_MS5611_h
2 #define OXS_MS5611_h
5 #include "Arduino.h"
6 #include "oXs_config_basic.h"
7 #include "oXs_config_advanced.h"
8 #include "oXs_config_macros.h"
9 #include "I2C.h"
11 struct VARIODATA {
12 int32_t temperature; // in 1/100 Celsius
13 int64_t rawPressure ; // in 1/10000 mBar so = Pa * 10000
14 byte SensorState ;
15 int32_t rawAltitude ; // in cm * 100
16 struct ONE_MEASUREMENT absoluteAlt ; // value in cm
17 struct ONE_MEASUREMENT relativeAlt ; // value in cm
18 int32_t altOffset ; // in cm
19 int32_t relativeAltMax ; // in cm
20 bool relativeAltMaxAvailable ;
21 float delaySmooth ; // smoothed delay between 2 altitude calculations
22 int32_t prevAlt[20] ; // table contains the 20 latest altitude
23 byte idxPrevAlt ; // index of last entry in table
24 int32_t vSpeed10Sec; // Altitude gain/loose between 10 sec (is calculated and send every 500 msec)
25 bool vSpeed10SecAvailable ;
26 float climbRateFloat ; // in cm/sec but as float
27 struct ONE_MEASUREMENT climbRate ; // value in cm /sec = vertical speed
28 struct ONE_MEASUREMENT sensitivity ;
29 int sensitivityPpm ; // sensivity to apply when PPM is used. Value has to be divided by 1000 in order to calculate the smoothing parameter
30 unsigned long lastCommandMicros ; // used to avoid some task (reading voltage sensor, currentsensor, ..) when barometric data should be soon available for reading
34 class OXS_MS5611 {
35 public:
36 #ifdef DEBUG
37 OXS_MS5611(uint8_t addr, HardwareSerial &print);
38 #else
39 OXS_MS5611(uint8_t addr) ;
40 #endif
41 VARIODATA varioData ;
42 //int64_t rawPressure; // in 1/10000 mBar
43 void setup();
44 bool readSensor();
46 void resetValues();
48 private:
49 uint8_t _addr;
50 unsigned int _calibrationData[7]; // The factory calibration data of the ms5611
51 uint8_t errorI2C ; //error code returned by I2C::Write and I2C::Read; 0 = no error
52 bool errorCalibration ; // (true = error)
53 void SendCommand(byte command);
54 long getData(byte command, byte del);
55 void calculateVario() ;
56 unsigned int low, high;
57 int32_t D1 ;
58 int32_t D2 ;
59 int32_t D2Prev ;
60 int32_t D2Apply ;
61 int64_t dT ;
62 int32_t TEMP ;
63 int64_t OFF, SENS;
64 int16_t alt_temp_compensation ;
66 int32_t altitude ; // in cm * 100
67 int32_t altitudeLowPass ;
68 int32_t altitudeHighPass ;
69 int sensitivityMin ;
71 unsigned long extended2Micros ; // used to temporarilly save micros() >> 1
72 unsigned long pressureMicros ; // save time when program send command asking the MS5611 to get the pressure
73 unsigned long pressureMicrosPrev1 ; // save the previous pressureMicros
74 unsigned long pressureMicrosPrev2 ; // save the previous of the previous pressureMicros
75 unsigned long altMillis ;
76 unsigned long nextAltMillis ; // save when Altitude has to be calculated; altitude is available only after 3200 in order to get a stable value (less temperature drift)
77 // unsigned long nextAverageAltMillis ; // save when AverageAltitude has to be calculated
79 float climbRate2AltFloat ;
81 float abs_deltaClimbRate ;
83 #ifdef DEBUG
84 HardwareSerial* printer;
85 #endif
86 }; // end class OXS_MS5611
89 #endif // OXS_MS5611