Paparazzi UAS
v5.18.0_stable
Paparazzi is a free software Unmanned Aircraft System.
Main Page
Related Pages
Modules
Data Structures
Data Structures
Data Structure Index
Data Fields
All
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Functions
Variables
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Files
File List
Globals
All
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Functions
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
Variables
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Typedefs
a
b
c
d
e
f
g
h
i
j
m
n
p
r
s
t
u
v
w
Enumerations
a
b
c
d
e
f
g
h
i
j
l
m
n
o
p
r
s
t
u
v
w
z
Enumerator
a
b
c
d
e
f
g
h
i
j
l
m
n
o
p
r
s
t
u
v
w
x
y
z
Macros
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
▼
Paparazzi UAS
►
MAIN README
►
Onboard Modules
►
Paparazzi Messages
Paparazzi Technical Primers
►
Math library
CATIA
E-Identification-FR
Todo List
Bibliography
►
Modules
►
Namespace Members
►
Data Structures
▼
Files
►
File List
►
Globals
•
All
Data Structures
Namespaces
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
31
#include "
modules/meteo/dust_gp2y.h
"
32
#include "
mcu_periph/i2c.h
"
33
#include "
mcu_periph/sys_time.h
"
34
#include "
mcu_periph/uart.h
"
35
#include "pprzlink/messages.h"
36
#include "
subsystems/datalink/downlink.h
"
37
38
uint8_t
dust_gp2y_status
;
39
uint16_t
dust_gp2y_density
;
40
float
dust_gp2y_density_f
;
41
42
struct
i2c_transaction
gp2y_trans
;
43
44
45
#ifndef GP2Y_I2C_DEV
46
#define GP2Y_I2C_DEV i2c0
47
#endif
48
49
#define GP2Y_SLAVE_ADDR 0xED
50
51
void
dust_gp2y_init
(
void
)
52
{
53
dust_gp2y_status
=
DUST_GP2Y_UNINIT
;
54
}
55
56
void
dust_gp2y_periodic
(
void
)
57
{
58
if
(
dust_gp2y_status
==
DUST_GP2Y_IDLE
) {
59
i2c_receive
(&
GP2Y_I2C_DEV
, &
gp2y_trans
,
GP2Y_SLAVE_ADDR
, 2);
60
}
else
if
(
dust_gp2y_status
==
DUST_GP2Y_UNINIT
&&
sys_time
.
nb_sec
> 1) {
61
dust_gp2y_status
=
DUST_GP2Y_IDLE
;
62
}
63
}
64
65
void
dust_gp2y_event
(
void
)
66
{
67
if
(
gp2y_trans
.
status
==
I2CTransSuccess
) {
68
/* read two byte particle density */
69
dust_gp2y_density
=
gp2y_trans
.
buf
[0] << 8;
70
dust_gp2y_density
|=
gp2y_trans
.
buf
[1];
71
72
/* "just for reference and not for guarantee" */
73
dust_gp2y_density_f
= ((
dust_gp2y_density
/ 1024.) * 3.3 * (51. / 33.) - 0.6) * (0.5 / 3.);
74
if
(
dust_gp2y_density_f
< 0) {
75
dust_gp2y_density_f
= 0;
76
}
77
78
DOWNLINK_SEND_GP2Y_STATUS(
DefaultChannel
,
DefaultDevice
, &
dust_gp2y_density
, &
dust_gp2y_density_f
);
79
80
gp2y_trans
.
status
=
I2CTransDone
;
81
}
82
}
dust_gp2y_status
uint8_t dust_gp2y_status
Definition:
dust_gp2y.c:38
uint16_t
unsigned short uint16_t
Definition:
types.h:16
i2c_transaction::buf
volatile uint8_t buf[I2C_BUF_LEN]
Transaction buffer With I2C_BUF_LEN number of bytes.
Definition:
i2c.h:122
dust_gp2y_density_f
float dust_gp2y_density_f
Definition:
dust_gp2y.c:40
GP2Y_I2C_DEV
#define GP2Y_I2C_DEV
Definition:
dust_gp2y.c:46
DUST_GP2Y_UNINIT
#define DUST_GP2Y_UNINIT
Definition:
dust_gp2y.h:6
GP2Y_SLAVE_ADDR
#define GP2Y_SLAVE_ADDR
Definition:
dust_gp2y.c:49
dust_gp2y_periodic
void dust_gp2y_periodic(void)
Definition:
dust_gp2y.c:56
dust_gp2y_init
void dust_gp2y_init(void)
Definition:
dust_gp2y.c:51
dust_gp2y_density
uint16_t dust_gp2y_density
Definition:
dust_gp2y.c:39
I2CTransSuccess
@ I2CTransSuccess
transaction successfully finished by I2C driver
Definition:
i2c.h:57
uart.h
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
dust_gp2y.h
sys_time.h
Architecture independent timing functions.
uint8_t
unsigned char uint8_t
Definition:
types.h:14
i2c_transaction::status
enum I2CTransactionStatus status
Transaction status.
Definition:
i2c.h:126
gp2y_trans
struct i2c_transaction gp2y_trans
Definition:
dust_gp2y.c:42
i2c_transaction
I2C transaction structure.
Definition:
i2c.h:93
downlink.h
Common code for AP and FBW telemetry.
sys_time
Definition:
sys_time.h:71
I2CTransDone
@ I2CTransDone
transaction set to done by user level
Definition:
i2c.h:59
DefaultChannel
#define DefaultChannel
Definition:
downlink.h:42
DUST_GP2Y_IDLE
#define DUST_GP2Y_IDLE
Definition:
dust_gp2y.h:7
DefaultDevice
#define DefaultDevice
Definition:
downlink.h:46
sys_time::nb_sec
volatile uint32_t nb_sec
full seconds since startup
Definition:
sys_time.h:72
dust_gp2y_event
void dust_gp2y_event(void)
Definition:
dust_gp2y.c:65
i2c.h
i2c_receive
bool i2c_receive(struct i2c_periph *p, struct i2c_transaction *t, uint8_t s_addr, uint16_t len)
Submit a read only transaction.
Definition:
i2c.c:334
sw
airborne
modules
meteo
dust_gp2y.c
Generated on Tue Feb 1 2022 13:51:16 for Paparazzi UAS by
1.8.17