Merge pull request #73 from romoloman/master
[openXsensor.git] / openXsensor / oXs_4525.h
blobe792beaa4c25fa89061c13479bf04822aa2a895b
1 #ifndef OXS_4525_h
2 #define OXS_4525_h
4 #include <Arduino.h>
5 #include "oXs_config_basic.h"
6 #include "oXs_config_advanced.h"
7 #include "oXs_config_macros.h"
8 #include "I2C.h"
10 //#define CALCULATEINTEGER
12 struct AIRSPEEDDATA {
13 // float smoothDifPressureAdc ; // in steps ADC
14 float temperature4525; // in Celsius , used when compensation is calculated
15 // float rawAirSpeed ; // cm/sec
16 struct ONE_MEASUREMENT airSpeed ; // in km/h (no decimal)
17 // int32_t compensation ; // in km/h (no decimal)
18 // bool compensationAvailable ;
19 bool airspeedReset ;
20 float smoothAirSpeed ; //cm/sec ; use in glider ratio
21 unsigned long lastCommand2Micros ; // used to avoid some task (reading voltage sensor, currentsensor, ..) when barometric data should be soon available for reading
22 // = micro divided by 2 to avoid overflow on comparison
23 float difPressureAdc_zero ;
26 extern float actualPressure ;
28 class OXS_4525 {
29 public:
30 #ifdef DEBUG
31 OXS_4525(uint8_t addr, HardwareSerial &print);
32 #else
33 OXS_4525(uint8_t addr) ;
34 #endif
35 AIRSPEEDDATA airSpeedData ;
36 // int64_t rawPressure; // in 1/10000 mBar
37 void setup();
38 void readSensor();
41 private:
43 // unsigned int _calibrationData[7]; // The factory calibration data of the ms5611
45 void SendCommand(byte command);
46 uint8_t _addr;
47 uint8_t I2CErrorCode4525 ;
48 long getData(byte command, byte del);
49 bool calibrated4525 ;
50 int calibrateCount4525 ;
51 int32_t difPressureSum ;
53 // unsigned long extended2Micros ; // used to temporarilly save micros() >> 1
54 uint8_t data[4]; // get the 4 bytes returned by MS4225
55 int32_t difPressureAdc; // in steps ADC
56 int32_t temperature4525Adc ; // in steps ADC
58 float offset4525 ;
59 float difPressureAdc_0 ;
60 float abs_deltaDifPressureAdc ;
61 float smoothDifPressureAdc ; // in steps ADC/
63 float expoSmooth4525_adc_auto ;
64 // float smoothAirSpeed ; //cm/sec
65 // float rawAirSpeed ; // cm/sec
67 unsigned long airSpeedMillis ; //save time when airspeed is made available
68 unsigned long nextAirSpeedMillis ; //next time that airspeed must be available
70 #ifdef DEBUG
71 HardwareSerial* printer;
72 #endif
73 }; // end class OXS_4525
75 extern int32_t test1Value ;// used in order to test the transmission of any value
76 extern bool test1ValueAvailable ;
77 extern int32_t test2Value ;// used in order to test the transmission of any value
78 extern bool test2ValueAvailable ;
79 extern int32_t test3Value ;// used in order to test the transmission of any value
80 extern bool test3ValueAvailable ;
83 #endif // OXS_4525