Paparazzi UAS  v7.0_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 
52 struct Bmp280_I2c baro_bmp280;
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 }
Main include for ABI (AirBorneInterface).
#define BARO_BMP_SENDER_ID
#define BMP280_SLAVE_ADDR
default slave address
struct Bmp280_I2c baro_bmp280
float baro_press
void baro_bmp280_periodic(void)
bool baro_alt_valid
void baro_bmp280_init(void)
float baro_alt
static void send_baro_bmp_data(struct transport_tx *trans, struct link_device *dev)
float baro_temp
void baro_bmp280_event(void)
Bosch BMP280 I2C sensor interface.
void bmp280_i2c_event(struct Bmp280_I2c *bmp)
Definition: bmp280_i2c.c:104
void bmp280_i2c_periodic(struct Bmp280_I2c *bmp)
Definition: bmp280_i2c.c:57
void bmp280_i2c_init(struct Bmp280_I2c *bmp, struct i2c_periph *i2c_p, uint8_t addr)
Definition: bmp280_i2c.c:41
uint32_t raw_temperature
uncompensated temperature
Definition: bmp280_i2c.h:43
float pressure
pressure in Pascal
Definition: bmp280_i2c.h:44
float temperature
temperature in deg Celcius
Definition: bmp280_i2c.h:45
volatile bool data_available
data ready flag
Definition: bmp280_i2c.h:40
uint32_t raw_pressure
uncompensated pressure
Definition: bmp280_i2c.h:42
uint32_t get_sys_time_usec(void)
Get the time in microseconds since startup.
Definition: sys_time_arch.c:71
static float pprz_isa_altitude_of_pressure(float pressure)
Get absolute altitude from pressure (using simplified equation).
Definition: pprz_isa.h:82
static float p[2][2]
uint16_t up[LIGHT_NB]
Definition: light_solar.c:48
Paparazzi atmospheric pressure conversion utilities.
static const struct usb_device_descriptor dev
Definition: usb_ser_hw.c:74
int8_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint8_t _id, telemetry_cb _cb)
Register a telemetry callback function.
Definition: telemetry.c:51
Periodic telemetry system header (includes downlink utility and generated code).
#define DefaultPeriodic
Set default periodic telemetry.
Definition: telemetry.h:66
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
int int32_t
Typedef defining 32 bit int type.
Definition: vl53l1_types.h:83
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
Definition: vl53l1_types.h:78