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
dust_gp2y.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2010 Martin Mueller
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 
32 #include "mcu_periph/i2c.h"
33 #include "mcu_periph/sys_time.h"
34 #include "mcu_periph/uart.h"
35 #include "messages.h"
37 
41 
43 
44 #ifndef DOWNLINK_DEVICE
45 #define DOWNLINK_DEVICE DOWNLINK_AP_DEVICE
46 #endif
47 
48 #ifndef GP2Y_I2C_DEV
49 #define GP2Y_I2C_DEV i2c0
50 #endif
51 
52 #define GP2Y_SLAVE_ADDR 0xED
53 
54 void dust_gp2y_init( void ) {
56 }
57 
58 void dust_gp2y_periodic( void ) {
61  }
62  else if (dust_gp2y_status == DUST_GP2Y_UNINIT && sys_time.nb_sec > 1) {
64  }
65 }
66 
67 void dust_gp2y_event( void ) {
69  /* read two byte particle density */
72 
73  /* "just for reference and not for guarantee" */
74  dust_gp2y_density_f = ((dust_gp2y_density / 1024.) * 3.3 * (51. / 33.) - 0.6) * (0.5 / 3.);
75  if (dust_gp2y_density_f < 0)
77 
78  DOWNLINK_SEND_GP2Y_STATUS(DefaultChannel, DefaultDevice, &dust_gp2y_density, &dust_gp2y_density_f);
79 
81  }
82 }
unsigned short uint16_t
Definition: types.h:16
#define GP2Y_I2C_DEV
Definition: dust_gp2y.c:49
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
void dust_gp2y_event(void)
Definition: dust_gp2y.c:67
void dust_gp2y_periodic(void)
Definition: dust_gp2y.c:58
#define DUST_GP2Y_UNINIT
Definition: dust_gp2y.h:6
float dust_gp2y_density_f
Definition: dust_gp2y.c:40
void dust_gp2y_init(void)
Definition: dust_gp2y.c:54
uint16_t dust_gp2y_density
Definition: dust_gp2y.c:39
Architecture independent timing functions.
enum I2CTransactionStatus status
Definition: i2c.h:83
volatile uint8_t buf[I2C_BUF_LEN]
Definition: i2c.h:82
unsigned char uint8_t
Definition: types.h:14
volatile uint32_t nb_sec
full seconds since startup
Definition: sys_time.h:69
#define GP2Y_SLAVE_ADDR
Definition: dust_gp2y.c:52
#define DUST_GP2Y_IDLE
Definition: dust_gp2y.h:7
struct i2c_transaction gp2y_trans
Definition: dust_gp2y.c:42
uint8_t dust_gp2y_status
Definition: dust_gp2y.c:38
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.