UBlox M10 Support
[openXsensor.git] / openXsensor / oXs_ads1115.h
blobcf0969a9f8c3849f0de36a108e6375a1c972d054
1 #ifndef OXS_ADS1115_h
2 #define OXS_ADS1115_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"
9 #include "oXs_curr.h"
10 #include "oXs_4525.h"
12 // values to say how to use a ads measurement
13 #define ADS_VOLT_1 0
14 #define ADS_VOLT_2 1
15 #define ADS_VOLT_3 2
16 #define ADS_VOLT_4 3
17 #define ADS_VOLT_5 4
18 #define ADS_VOLT_6 5
19 #define ADS_AIRSPEED 6
20 #define ADS_CURRENT 7
21 #define ADS_NOT_USED 8
23 // values to configure the ads multiplexer
24 #define A0_TO_A1 0
25 #define A0_TO_A3 1
26 #define A1_TO_A3 2
27 #define A2_TO_A3 3
28 #define A0_TO_GND 4
29 #define A1_TO_GND 5
30 #define A2_TO_GND 6
31 #define A3_TO_GND 7
32 #define ADS_OFF 8
34 // values to configure the programable ads gain amplifier
35 #define MV6144 0
36 #define MV4096 1
37 #define MV2048 2
38 #define MV1024 3
39 #define MV512 4
40 #define MV256 5
42 // value to configure the rate of ads conversion (value is the delay in msec that must be wait before getting the conversion ; this take care of the tolerance of 10% foreseen in the datasheet
43 #define MS137 0
44 #define MS69 1
45 #define MS35 2
46 #define MS18 3
47 #define MS9 4
48 #define MS5 5
49 #define MS3 6
50 #define MS2 7
53 extern const uint8_t ads_Measure[4] ;
54 extern const uint8_t ads_Gain[4] ;
55 extern const uint8_t ads_Rate[4] ;
56 extern const float ads_Offset[4] ;
57 extern const float ads_Scale[4] ;
58 extern const uint8_t ads_MaxCount[4] ;
61 extern uint32_t ads_MilliAskConv ;
62 extern uint8_t ads_Addr;
63 extern uint8_t ads_CurrentIdx ;
64 extern uint8_t I2CErrorCodeAds1115 ;
65 extern int32_t ads_SumOfConv[4] ; // summarise all conversion in order to calculate average
66 extern uint8_t ads_Counter[4] ;
67 extern struct ONE_MEASUREMENT ads_Conv[4] ; //averaged conversion including offset and scale
68 extern uint8_t ads_Last_Conv_Idx ;
72 class OXS_ADS1115 {
73 public:
74 #ifdef DEBUG
75 OXS_ADS1115(uint8_t addr, HardwareSerial &print);
76 #else
77 OXS_ADS1115(uint8_t addr) ;
78 #endif
80 void setup();
81 boolean readSensor( void ); //return true if an averaged has just been calculated
82 void ads_requestNextConv(void) ;
83 void ads_calculateCurrent(void) ;
84 void ads_calculate_airspeed( int16_t ads_difPressureADC ) ;
85 #if defined(AN_ADS1115_IS_CONNECTED) && (AN_ADS1115_IS_CONNECTED == YES ) && defined(ADS_MEASURE) && defined(ADS_CURRENT_BASED_ON)
86 struct CURRENTDATA adsCurrentData ;
87 float floatConsumedMilliAmps ; // in mA
88 #endif
90 #if defined(AN_ADS1115_IS_CONNECTED) && (AN_ADS1115_IS_CONNECTED == YES ) && defined(ADS_MEASURE) && defined(ADS_AIRSPEED_BASED_ON)
91 struct AIRSPEEDDATA adsAirSpeedData ;
92 #endif
94 private:
95 #ifdef DEBUG
96 HardwareSerial* printer;
97 #endif
98 }; // end class OXS_ADS1115
102 #endif // OXS_ADS1115