Paparazzi UAS  v5.12_stable-4-g9b43e9b
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
baro_hca.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 Gautier Hattenberger (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 #include "sensors/baro_hca.h"
24 #include "mcu_periph/i2c.h"
25 #include "subsystems/abi.h"
26 #include <math.h>
27 
28 //Messages
29 #include "mcu_periph/uart.h"
30 #include "pprzlink/messages.h"
32 
33 
34 #define BARO_HCA_ADDR 0xF0
35 #define BARO_HCA_MAX_PRESSURE 1100 // mBar
36 #define BARO_HCA_MIN_PRESSURE 800 // mBar
37 #define BARO_HCA_MAX_OUT 27852 //dec
38 #define BARO_HCA_MIN_OUT 1638 //dec
39 
40 // FIXME
41 #ifndef BARO_HCA_SCALE
42 #define BARO_HCA_SCALE 1.0
43 #endif
44 
45 // FIXME
46 #ifndef BARO_HCA_PRESSURE_OFFSET
47 #define BARO_HCA_PRESSURE_OFFSET 101325.0
48 #endif
49 
50 #ifndef BARO_HCA_I2C_DEV
51 #define BARO_HCA_I2C_DEV i2c0
52 #endif
53 
54 // Global variables
57 float baro_hca_p;
58 
59 
61 
62 void baro_hca_init(void)
63 {
64  pBaroRaw = 0;
65  baro_hca_valid = true;
67 }
68 
69 
71 {
74  }
75 }
76 
77 
79 {
80  pBaroRaw = 0;
81  // Get raw altimeter from buffer
83 
84  if (pBaroRaw == 0) {
85  baro_hca_valid = false;
86  } else {
87  baro_hca_valid = true;
88  }
89 
90 
91  if (baro_hca_valid) {
92  //Cut RAW Min and Max
93  if (pBaroRaw < BARO_HCA_MIN_OUT) {
95  }
96  if (pBaroRaw > BARO_HCA_MAX_OUT) {
98  }
99 
100  float pressure = BARO_HCA_SCALE * (float)pBaroRaw + BARO_HCA_PRESSURE_OFFSET;
101  AbiSendMsgBARO_ABS(BARO_HCA_SENDER_ID, pressure);
102  }
104 
105  uint16_t foo = 0;
106  float bar = 0;
107 #ifdef SENSOR_SYNC_SEND
108  DOWNLINK_SEND_BARO_ETS(DefaultChannel, DefaultDevice, &pBaroRaw, &foo, &bar)
109 #else
110  RunOnceEvery(10, DOWNLINK_SEND_BARO_ETS(DefaultChannel, DefaultDevice, &pBaroRaw, &foo, &bar));
111 #endif
112 
113 }
114 
115 
116 
117 
118 
119 
120 
121 
122 
123 
124 
125 
126 
127 
128 
void baro_hca_read_event(void)
Definition: baro_hca.c:78
unsigned short uint16_t
Definition: types.h:16
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
volatile uint8_t buf[I2C_BUF_LEN]
Transaction buffer With I2C_BUF_LEN number of bytes.
Definition: i2c.h:122
#define BARO_HCA_I2C_DEV
Definition: baro_hca.c:51
Main include for ABI (AirBorneInterface).
bool baro_hca_valid
Definition: baro_hca.c:56
struct i2c_transaction baro_hca_i2c_trans
Definition: baro_hca.c:60
uint16_t pBaroRaw
Definition: baro_hca.c:55
#define BARO_HCA_ADDR
Definition: baro_hca.c:34
#define BARO_HCA_SENDER_ID
#define BARO_HCA_PRESSURE_OFFSET
Definition: baro_hca.c:47
transaction set to done by user level
Definition: i2c.h:59
void baro_hca_init(void)
Definition: baro_hca.c:62
uint16_t foo
Definition: main_demo5.c:59
#define BARO_HCA_SCALE
Definition: baro_hca.c:42
I2C transaction structure.
Definition: i2c.h:93
enum I2CTransactionStatus status
Transaction status.
Definition: i2c.h:126
bool i2c_receive(struct i2c_periph *p, struct i2c_transaction *t, uint8_t s_addr, uint16_t len)
Submit a read only transaction.
Definition: i2c.c:268
#define BARO_HCA_MAX_OUT
Definition: baro_hca.c:37
#define BARO_HCA_MIN_OUT
Definition: baro_hca.c:38
float baro_hca_p
Definition: baro_hca.c:57
void baro_hca_read_periodic(void)
Definition: baro_hca.c:70
Architecture independent I2C (Inter-Integrated Circuit Bus) API.