Paparazzi UAS  v5.15_devel-230-gc96ce27
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
baro_board.c
Go to the documentation of this file.
1 /*
2 * Copyright (C) 2010-2013 Gautier Hattenberger
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 
24 /* driver for the analog Barometer Mpxa6115 using ADC ads1114 (16 bits I2C 860SpS max) from Texas instruments
25  * Navarro & Gorraz & Hattenberger
26  */
27 
28 #include "std.h"
29 #include "baro_board.h"
31 #include "peripherals/ads1114.h"
32 #include "subsystems/abi.h"
33 #include "led.h"
34 
35 // ADC for absolute pressure
36 #ifndef BARO_ABS_ADS
37 #define BARO_ABS_ADS ads1114_1
38 #endif
39 
40 // FIXME
41 #ifndef UMARIM_BARO_SENS
42 #define UMARIM_BARO_SENS 0.0274181
43 #endif
44 
45 /* Counter to init ads1114 at startup */
46 #define BARO_STARTUP_COUNTER 200
48 
49 void baro_init(void)
50 {
51  ads1114_init();
52 #ifdef BARO_LED
53  LED_OFF(BARO_LED);
54 #endif
56 }
57 
58 void baro_periodic(void)
59 {
60 
61  // Run some loops to get correct readings from the adc
62  if (startup_cnt > 0) {
63  --startup_cnt;
64 #ifdef BARO_LED
65  LED_TOGGLE(BARO_LED);
66  if (startup_cnt == 0) {
67  LED_ON(BARO_LED);
68  }
69 #endif
70  }
71  // Read the ADC
73 }
74 
76 {
77  Ads1114Event();
78  if (BARO_ABS_ADS.data_available) {
79  if (startup_cnt == 0) {
80  uint32_t now_ts = get_sys_time_usec();
81  float pressure = UMARIM_BARO_SENS * Ads1114GetValue(BARO_ABS_ADS);
82  AbiSendMsgBARO_ABS(BARO_BOARD_SENDER_ID, now_ts, pressure);
83  }
84  BARO_ABS_ADS.data_available = false;
85  }
86 }
87 
unsigned short uint16_t
Definition: types.h:16
uint16_t startup_cnt
Definition: baro_board.c:72
Common barometric sensor implementation.
#define BARO_STARTUP_COUNTER
Definition: baro_board.c:46
#define LED_OFF(i)
Definition: led_hw.h:52
Main include for ABI (AirBorneInterface).
void baro_init(void)
Definition: baro_board.c:76
#define BARO_ABS_ADS
Definition: baro_board.c:37
#define UMARIM_BARO_SENS
Definition: baro_board.c:42
void ads1114_read(struct ads1114_periph *p)
Definition: ads1114.c:63
void baro_periodic(void)
Definition: baro_board.c:90
void ads1114_init(void)
Definition: ads1114.c:37
unsigned long uint32_t
Definition: types.h:18
#define Ads1114GetValue(_p)
Definition: ads1114.h:165
#define BARO_BOARD_SENDER_ID
default onboard baro
#define LED_TOGGLE(i)
Definition: led_hw.h:53
void umarim_baro_event(void)
Definition: baro_board.c:75
arch independent LED (Light Emitting Diodes) API
#define LED_ON(i)
Definition: led_hw.h:51
uint32_t get_sys_time_usec(void)
Get the time in microseconds since startup.
Definition: sys_time_arch.c:68
#define Ads1114Event()
Definition: ads1114.h:158