Paparazzi UAS  v4.2.2_stable-4-gcc32f65
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
charge_sens.c
Go to the documentation of this file.
1 /*
2  * $Id$
3  *
4  * Copyright (C) 2011 Martin Mueller <martinmm@pfump.org>
5  *
6  * This file is part of paparazzi.
7  *
8  * paparazzi is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2, or (at your option)
11  * any later version.
12  *
13  * paparazzi is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with paparazzi; see the file COPYING. If not, write to
20  * the Free Software Foundation, 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  *
23  */
24 
31 #include "mcu_periph/i2c.h"
32 #include "mcu_periph/uart.h"
33 #include "messages.h"
35 
36 #ifndef DOWNLINK_DEVICE
37 #define DOWNLINK_DEVICE DOWNLINK_AP_DEVICE
38 #endif
39 
40 #ifndef CHARGE_SENS_DEV
41 #define CHARGE_SENS_DEV i2c0
42 #endif
43 
44 #define CHARGE_SENS_I2C_ADDR 0x78
45 #define CHARGE_NB 10
46 
50 
51 void charge_sens_init( void ) {
52  charge_cnt = 0;
53 }
54 
55 void charge_sens_periodic( void ) {
57 }
58 
59 void charge_sens_event( void ) {
61  /* read two byte atmosphere charge */
62  charge[charge_cnt] = charge_trans.buf[1] << 8;
65 
66  if (++charge_cnt >= CHARGE_NB) {
67  DOWNLINK_SEND_ATMOSPHERE_CHARGE(DefaultChannel, DefaultDevice,
68  &charge[0], &charge[1], &charge[2], &charge[3], &charge[4],
69  &charge[5], &charge[6], &charge[7], &charge[8], &charge[9]);
70  charge_cnt = 0;
71  }
72  }
73 }
#define CHARGE_NB
Definition: charge_sens.c:45
unsigned short uint16_t
Definition: types.h:16
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
#define I2CReceive(_p, _t, _s_addr, _len)
Definition: i2c.h:140
uint16_t charge[CHARGE_NB]
Definition: charge_sens.c:48
void charge_sens_periodic(void)
Definition: charge_sens.c:55
void charge_sens_event(void)
Definition: charge_sens.c:59
#define CHARGE_SENS_DEV
Definition: charge_sens.c:41
int32_t charge_cnt
Definition: charge_sens.c:49
void charge_sens_init(void)
Definition: charge_sens.c:51
enum I2CTransactionStatus status
Definition: i2c.h:47
signed long int32_t
Definition: types.h:19
volatile uint8_t buf[I2C_BUF_LEN]
Definition: i2c.h:46
struct i2c_transaction charge_trans
Definition: charge_sens.c:47
#define CHARGE_SENS_I2C_ADDR
Definition: charge_sens.c:44