Paparazzi UAS  v6.2_unstable
Paparazzi is a free software Unmanned Aircraft System.
baro_bmp280_i2c.c
Go to the documentation of this file.
1 /*
2  * Chris Efstathiou hendrixgr@gmail.com
3  * This file is part of paparazzi.
4  *
5  * paparazzi is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2, or (at your option)
8  * any later version.
9  *
10  * paparazzi is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with paparazzi; see the file COPYING. If not, see
17  * <http://www.gnu.org/licenses/>.
18  *
19  */
20 
29 #include "baro_bmp280_i2c.h"
30 
31 #include "modules/core/abi.h"
32 #include "mcu_periph/uart.h"
33 #include "pprzlink/messages.h"
35 #include "math/pprz_isa.h"
36 
37 #if DOWNLINK && !defined(BMP280_SYNC_SEND)
39 #endif
40 
42 #ifndef BMP280_SLAVE_ADDR
43 #define BMP280_SLAVE_ADDR BMP280_I2C_ADDR
44 #endif
45 
46 float baro_alt = 0;
47 float baro_temp = 0;
48 float baro_press = 0;
49 bool baro_alt_valid = 0;
50 
51 
53 
54 #if DOWNLINK && !defined(BMP280_SYNC_SEND)
55 static void send_baro_bmp_data(struct transport_tx *trans, struct link_device *dev)
56 {
57  int32_t baro_altitude = (int32_t)(baro_alt * 100);
58  int32_t baro_pressure = (int32_t)(baro_press);
59  int32_t baro_temperature = (int32_t)(baro_temp * 100);
60 
61  pprz_msg_send_BMP_STATUS(trans, dev, AC_ID, &baro_altitude, &baro_altitude , &baro_pressure, & baro_temperature);
62 
63  return;
64 }
65 #endif
66 
67 
68 void baro_bmp280_init(void)
69 {
70 
71  bmp280_i2c_init(&baro_bmp280, &BMP280_I2C_DEV, BMP280_SLAVE_ADDR);
72 #if DOWNLINK && !defined(BMP280_SYNC_SEND)
74 #endif
75 }
76 
78 {
80 }
81 
83 {
85 
87  uint32_t now_ts = get_sys_time_usec();
88  // send ABI message
89  AbiSendMsgBARO_ABS(BARO_BMP_SENDER_ID, now_ts, baro_bmp280.pressure);
90  AbiSendMsgTEMPERATURE(BARO_BMP_SENDER_ID, baro_bmp280.temperature);
93  baro_alt_valid = true;
95  baro_temp = ((float)baro_bmp280.temperature) / 100;
96 
97 #if defined(BMP280_SYNC_SEND)
102  DOWNLINK_SEND_BMP_STATUS(DefaultChannel, DefaultDevice, &up, &ut, &p, &t);
103 #endif
104  }
105 }
bmp280_i2c_init
void bmp280_i2c_init(struct Bmp280_I2c *bmp, struct i2c_periph *i2c_p, uint8_t addr)
Definition: bmp280_i2c.c:41
baro_alt
float baro_alt
Definition: baro_bmp280_i2c.c:46
uint32_t
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
Definition: vl53l1_types.h:78
baro_bmp280_event
void baro_bmp280_event(void)
Definition: baro_bmp280_i2c.c:82
abi.h
baro_bmp280_i2c.h
Bmp280_I2c::data_available
volatile bool data_available
data ready flag
Definition: bmp280_i2c.h:40
baro_temp
float baro_temp
Definition: baro_bmp280_i2c.c:47
baro_bmp280_init
void baro_bmp280_init(void)
Definition: baro_bmp280_i2c.c:68
up
uint16_t up[LIGHT_NB]
Definition: light_solar.c:48
bmp280_i2c_event
void bmp280_i2c_event(struct Bmp280_I2c *bmp)
Definition: bmp280_i2c.c:104
get_sys_time_usec
uint32_t get_sys_time_usec(void)
Get the time in microseconds since startup.
Definition: sys_time_arch.c:75
telemetry.h
baro_bmp280_periodic
void baro_bmp280_periodic(void)
Definition: baro_bmp280_i2c.c:77
uart.h
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
pprz_isa_altitude_of_pressure
static float pprz_isa_altitude_of_pressure(float pressure)
Get absolute altitude from pressure (using simplified equation).
Definition: pprz_isa.h:82
Bmp280_I2c::raw_pressure
uint32_t raw_pressure
uncompensated pressure
Definition: bmp280_i2c.h:42
BARO_BMP_SENDER_ID
#define BARO_BMP_SENDER_ID
Definition: abi_sender_ids.h:48
dev
static const struct usb_device_descriptor dev
Definition: usb_ser_hw.c:74
register_periodic_telemetry
int8_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint8_t _id, telemetry_cb _cb)
Register a telemetry callback function.
Definition: telemetry.c:51
baro_press
float baro_press
Definition: baro_bmp280_i2c.c:48
baro_bmp280
struct Bmp280_I2c baro_bmp280
Definition: baro_bmp280_i2c.c:52
baro_alt_valid
bool baro_alt_valid
Definition: baro_bmp280_i2c.c:49
Bmp280_I2c::temperature
float temperature
temperature in deg Celcius
Definition: bmp280_i2c.h:45
int32_t
int int32_t
Typedef defining 32 bit int type.
Definition: vl53l1_types.h:83
Bmp280_I2c::raw_temperature
uint32_t raw_temperature
uncompensated temperature
Definition: bmp280_i2c.h:43
send_baro_bmp_data
static void send_baro_bmp_data(struct transport_tx *trans, struct link_device *dev)
Definition: baro_bmp280_i2c.c:55
Bmp280_I2c
Definition: bmp280_i2c.h:35
bmp280_i2c_periodic
void bmp280_i2c_periodic(struct Bmp280_I2c *bmp)
Definition: bmp280_i2c.c:57
BMP280_SLAVE_ADDR
#define BMP280_SLAVE_ADDR
default slave address
Definition: baro_bmp280_i2c.c:43
DefaultPeriodic
#define DefaultPeriodic
Set default periodic telemetry.
Definition: telemetry.h:66
p
static float p[2][2]
Definition: ins_alt_float.c:268
pprz_isa.h
Paparazzi atmospheric pressure conversion utilities.
Bmp280_I2c::pressure
float pressure
pressure in Pascal
Definition: bmp280_i2c.h:44