Paparazzi UAS  v5.2.2_stable-0-gd6b9f29
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures 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 "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  pBaroRaw = 0;
66 }
67 
68 
69 void baro_hca_read_periodic( void ) {
72  }
73 }
74 
75 
76 void baro_hca_read_event( void ) {
77  pBaroRaw = 0;
78  // Get raw altimeter from buffer
80 
81  if (pBaroRaw == 0)
83  else
85 
86 
87  if (baro_hca_valid) {
88  //Cut RAW Min and Max
93 
94  float pressure = BARO_HCA_SCALE*(float)pBaroRaw + BARO_HCA_PRESSURE_OFFSET;
95  AbiSendMsgBARO_ABS(BARO_HCA_SENDER_ID, &pressure);
96  }
98 
99  uint16_t foo = 0;
100  float bar = 0;
101 #ifdef SENSOR_SYNC_SEND
102  DOWNLINK_SEND_BARO_ETS(DefaultChannel, DefaultDevice, &pBaroRaw, &foo, &bar)
103 #else
104  RunOnceEvery(10, DOWNLINK_SEND_BARO_ETS(DefaultChannel, DefaultDevice, &pBaroRaw, &foo, &bar));
105 #endif
106 
107 }
108 
109 
110 
111 
112 
113 
114 
115 
116 
117 
118 
119 
120 
121 
122 
void baro_hca_read_event(void)
Definition: baro_hca.c:76
unsigned short uint16_t
Definition: types.h:16
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
#define BARO_HCA_I2C_DEV
Definition: baro_hca.c:51
I2C transaction structure.
Definition: i2c.h:93
bool_t baro_hca_valid
Definition: baro_hca.c:56
Main include for ABI (AirBorneInterface).
struct i2c_transaction baro_hca_i2c_trans
Definition: baro_hca.c:60
uint16_t pBaroRaw
Definition: baro_hca.c:55
#define FALSE
Definition: imu_chimu.h:141
#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:54
#define BARO_HCA_SCALE
Definition: baro_hca.c:42
enum I2CTransactionStatus status
Transaction status.
Definition: i2c.h:126
#define TRUE
Definition: imu_chimu.h:144
volatile uint8_t buf[I2C_BUF_LEN]
Transaction buffer With I2C_BUF_LEN number of bytes.
Definition: i2c.h:122
#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:69
bool_t 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:248
Architecture independent I2C (Inter-Integrated Circuit Bus) API.