Paparazzi UAS  v5.0.5_stable-7-g4b8bbb7
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
charge_sens.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2011 Martin Mueller <martinmm@pfump.org>
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 
29 #include "mcu_periph/i2c.h"
30 #include "mcu_periph/uart.h"
31 #include "messages.h"
33 
34 #ifndef DOWNLINK_DEVICE
35 #define DOWNLINK_DEVICE DOWNLINK_AP_DEVICE
36 #endif
37 
38 #ifndef CHARGE_SENS_DEV
39 #define CHARGE_SENS_DEV i2c0
40 #endif
41 
42 #define CHARGE_SENS_I2C_ADDR 0x78
43 #define CHARGE_NB 10
44 
48 
49 void charge_sens_init( void ) {
50  charge_cnt = 0;
51 }
52 
53 void charge_sens_periodic( void ) {
55 }
56 
57 void charge_sens_event( void ) {
59  /* read two byte atmosphere charge */
60  charge[charge_cnt] = charge_trans.buf[1] << 8;
63 
64  if (++charge_cnt >= CHARGE_NB) {
65  DOWNLINK_SEND_ATMOSPHERE_CHARGE(DefaultChannel, DefaultDevice,
66  &charge[0], &charge[1], &charge[2], &charge[3], &charge[4],
67  &charge[5], &charge[6], &charge[7], &charge[8], &charge[9]);
68  charge_cnt = 0;
69  }
70  }
71 }
#define CHARGE_NB
Definition: charge_sens.c:43
unsigned short uint16_t
Definition: types.h:16
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
uint16_t charge[CHARGE_NB]
Definition: charge_sens.c:46
void charge_sens_periodic(void)
Definition: charge_sens.c:53
void charge_sens_event(void)
Definition: charge_sens.c:57
#define CHARGE_SENS_DEV
Definition: charge_sens.c:39
int32_t charge_cnt
Definition: charge_sens.c:47
void charge_sens_init(void)
Definition: charge_sens.c:49
enum I2CTransactionStatus status
Definition: i2c.h:83
signed long int32_t
Definition: types.h:19
volatile uint8_t buf[I2C_BUF_LEN]
Definition: i2c.h:82
struct i2c_transaction charge_trans
Definition: charge_sens.c:45
#define CHARGE_SENS_I2C_ADDR
Definition: charge_sens.c:42
bool_t i2c_receive(struct i2c_periph *p, struct i2c_transaction *t, uint8_t s_addr, uint16_t len)
Definition: i2c.c:95
Architecture independent I2C (Inter-Integrated Circuit Bus) API.