Paparazzi UAS v7.1_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
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 "modules/core/abi.h"
26#include "mcu_periph/sys_time.h"
27#include <math.h>
28
29//Messages
30#include "mcu_periph/uart.h"
31#include "pprzlink/messages.h"
33
34
35#define BARO_HCA_ADDR 0xF0
36#define BARO_HCA_MAX_PRESSURE 1100 // mBar
37#define BARO_HCA_MIN_PRESSURE 800 // mBar
38#define BARO_HCA_MAX_OUT 27852 //dec
39#define BARO_HCA_MIN_OUT 1638 //dec
40
41// FIXME
42#ifndef BARO_HCA_SCALE
43#define BARO_HCA_SCALE 1.0
44#endif
45
46// FIXME
47#ifndef BARO_HCA_PRESSURE_OFFSET
48#define BARO_HCA_PRESSURE_OFFSET 101325.0
49#endif
50
51#ifndef BARO_HCA_I2C_DEV
52#define BARO_HCA_I2C_DEV i2c0
53#endif
54
55// Global variables
59
60
62
63void baro_hca_init(void)
64{
65 pBaroRaw = 0;
66 baro_hca_valid = true;
68}
69
70
77
78
80{
81 pBaroRaw = 0;
82 // Get raw altimeter from buffer
84
85 if (pBaroRaw == 0) {
86 baro_hca_valid = false;
87 } else {
88 baro_hca_valid = true;
89 }
90
91
92 if (baro_hca_valid) {
93 //Cut RAW Min and Max
96 }
99 }
100
101 uint32_t now_ts = get_sys_time_usec();
102 float pressure = BARO_HCA_SCALE * (float)pBaroRaw + BARO_HCA_PRESSURE_OFFSET;
103 AbiSendMsgBARO_ABS_RAW(BARO_HCA_SENDER_ID, now_ts, pressure);
104 }
106
107
108}
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
Main include for ABI (AirBorneInterface).
#define BARO_HCA_SENDER_ID
static uint16_t pBaroRaw
Definition baro_amsys.c:72
#define BARO_HCA_MIN_OUT
Definition baro_hca.c:39
void baro_hca_init(void)
Definition baro_hca.c:63
float baro_hca_p
Definition baro_hca.c:58
#define BARO_HCA_PRESSURE_OFFSET
Definition baro_hca.c:48
bool baro_hca_valid
Definition baro_hca.c:57
#define BARO_HCA_I2C_DEV
Definition baro_hca.c:52
#define BARO_HCA_ADDR
Definition baro_hca.c:35
#define BARO_HCA_SCALE
Definition baro_hca.c:43
#define BARO_HCA_MAX_OUT
Definition baro_hca.c:38
void baro_hca_read_event(void)
Definition baro_hca.c:79
void baro_hca_read_periodic(void)
Definition baro_hca.c:71
struct i2c_transaction baro_hca_i2c_trans
Definition baro_hca.c:61
uint32_t get_sys_time_usec(void)
Get the time in microseconds since startup.
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:212
@ I2CTransDone
transaction set to done by user level
Definition i2c.h:60
I2C transaction structure.
Definition i2c.h:94
Architecture independent I2C (Inter-Integrated Circuit Bus) API.
Architecture independent timing functions.
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.