Paparazzi UAS  v4.2.2_stable-4-gcc32f65
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
baro_board.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2010 ENAC
3  *
4  * This file is part of paparazzi.
5  *
6  * paparazzi is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * paparazzi is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with paparazzi; see the file COPYING. If not, write to
18  * the Free Software Foundation, 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  *
21  */
22 
23 /* driver for the analog Barometer Mpxa6115 using ADC ads1114 (16 bits I2C 860SpS max) from Texas instruments
24  * Navarro & Gorraz & Hattenberger
25  */
26 
27 
28 
29 #ifndef BOARDS_UMARIM_BARO_H
30 #define BOARDS_UMARIM_BARO_H
31 
32 
33 #include "std.h"
34 #include "peripherals/ads1114.h"
35 
36 #define BARO_FILTER_GAIN 5
37 
38 /* There is no differential pressure on the board but
39  * it can be available from an external sensor
40  * */
41 #define DIFF_FILTER_GAIN 5
42 
43 #if USE_BARO_AS_ALTIMETER
44 extern float baro_alt;
45 extern float baro_alt_offset;
46 #define BaroAltHandler() { baro_alt = BARO_SENS*(baro_alt_offset - (float)baro.absolute); }
47 #endif
48 
49 #define BARO_ABS_ADS ads1114_1
50 
51 #define BaroAbs(_ads, _handler) { \
52  if (_ads.data_available) { \
53  baro.absolute = (baro.absolute + BARO_FILTER_GAIN*Ads1114GetValue(_ads)) / (BARO_FILTER_GAIN+1); \
54  if (baro.status == BS_RUNNING) { \
55  _handler(); \
56  _ads.data_available = FALSE; \
57  } \
58  } \
59 }
60 
61 #ifndef BaroDiff // Allow custom redefinition ?
62 
63 #if USE_BARO_DIFF
64 
65 #ifndef BARO_DIFF_ADS
66 #define BARO_DIFF_ADS ads1114_2
67 #endif
68 #define BaroDiff(_ads, _handler) { \
69  if (_ads.data_available) { \
70  baro.differential = (baro.differential + DIFF_FILTER_GAIN*Ads1114GetValue(_ads)) / (DIFF_FILTER_GAIN+1); \
71  if (baro.status == BS_RUNNING) { \
72  _handler(); \
73  _ads.data_available = FALSE; \
74  } \
75  } \
76 }
77 
78 #else // Not using differential with ADS1114
79 #define BaroDiff(_a, _h) {}
80 #endif
81 
82 #endif // ifndef BaroDiff
83 
84 #define BaroEvent(_b_abs_handler, _b_diff_handler) { \
85  Ads1114Event(); \
86  BaroAbs(BARO_ABS_ADS,_b_abs_handler); \
87  BaroDiff(BARO_DIFF_ADS,_b_diff_handler); \
88 }
89 
90 #endif // BOARDS_UMARIM_BARO_H
float baro_alt