1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/**
* <rc/bmp.h>
*
* @brief Interface to the BMP280 barometer
*
*
* @author James Strawson
* @date 3/14/2018
*
* @addtogroup Barometer_BMP
* @{
*/
#ifndef RC_BMP_H
#define RC_BMP_H
#ifdef __cplusplus
extern "C" {
#endif
/**
* Setting given to rc_bmp_init which defines the oversampling
* done internally to the barometer. For example, if BMP_OVERSAMPLE_16 is used
* then the barometer will average 16 samples before updating the data
* registers. The more oversampling used, the slower the data registers will
* update. You should pick an oversample that provides an update rate slightly
* slower than the rate at which you will be reading the barometer.
*/
typedef enum rc_bmp_oversample_t{
BMP_OVERSAMPLE_1 = (0x01<<2), ///< update rate 182 HZ
BMP_OVERSAMPLE_2 = (0x02<<2), ///< update rate 133 HZ
BMP_OVERSAMPLE_4 = (0x03<<2), ///< update rate 87 HZ
BMP_OVERSAMPLE_8 = (0x04<<2), ///< update rate 51 HZ
BMP_OVERSAMPLE_16 = (0x05<<2) ///< update rate 28 HZ
} rc_bmp_oversample_t;
/**
* Setting given to rc_bmp_init to configure the coefficient of the internal
* first order filter. We recommend disabling the filter with BMP_FILTER_OFF and
* doing your own filtering with the discrete filter functions below.
*/
typedef enum rc_bmp_filter_t{
BMP_FILTER_OFF = (0x00<<2),
BMP_FILTER_2 = (0x01<<2),
BMP_FILTER_4 = (0x02<<2),
BMP_FILTER_8 = (0x03<<2),
BMP_FILTER_16 = (0x04<<2)
}rc_bmp_filter_t;
/**
* struct to hold the data retreived during one read of the barometer.
*/
typedef struct rc_bmp_data_t{
double temp_c; ///< temperature in degrees celcius
double alt_m; ///< altitude in meters
double pressure_pa; ///< current pressure in pascals
} rc_bmp_data_t;
/**
* @brief powers on the barometer and initializes it with the given
* oversample and filter settings.
*
* Optionally call rc_bmp_set_sea_level_pressure_pa afterwards to change the sea
* level pressure from default.
*
* @param[in] oversample see rc_bmp_oversample_t
* @param[in] filter see rc_bmp_filter_t
*
* @return 0 on success, otherwise -1.
*/
int rc_bmp_init(rc_bmp_oversample_t oversample, rc_bmp_filter_t filter);
/**
* @brief If you know the current sea level pressure for your region and
* weather, you can use this to correct the altititude reading.
*
* This is not necessary if you only care about differential altitude from a
* starting point. Must be called after rc_bmp_init to have an effect.
*
* @param[in] pa sea level pressure in pascals
*
* @return 0 on success, -1 on failure
*/
int rc_bmp_set_sea_level_pressure_pa(double pa);
/**
* @brief Puts the barometer into a low power state, should be called at
* the end of your program before close.
*
* @return 0 on success, -1 on failure
*/
int rc_bmp_power_off(void);
/**
* @brief Reads the newest temperature and pressure measurments from the
* barometer over the I2C bus.
*
* @param data pointer to data struct where new data will be written.
*
* @return 0 on success, -1 on failure
*/
int rc_bmp_read(rc_bmp_data_t* data);
#ifdef __cplusplus
}
#endif
#endif // RC_BMP_H
/** @} end group Barometer */