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
infrared_adc.c
Go to the documentation of this file.
1 /*
2  * $Id$
3  *
4  * Copyright (C) 2003-2010 The Paparazzi Team
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 
32 #include <stdlib.h>
33 
35 #include "mcu_periph/adc.h"
36 
37 #include BOARD_CONFIG
38 #include "generated/airframe.h"
39 
40 // TODO Specific sim implementation
41 #if ! (defined SITL || defined HITL)
42 static struct adc_buf buf_ir1;
43 static struct adc_buf buf_ir2;
44 
45 #ifdef ADC_CHANNEL_IR_TOP
46 static struct adc_buf buf_ir3;
47 #endif
48 #endif
49 
50 #ifndef ADC_CHANNEL_IR_NB_SAMPLES
51 #define ADC_CHANNEL_IR_NB_SAMPLES DEFAULT_AV_NB_SAMPLE
52 #endif
53 
55 
56 // Standard infrared implementation
57 void infrared_init(void) {
59 }
60 
61 void infrared_update(void) {
63 }
64 
65 /* No event with adc ir */
66 void infrared_event(void) {}
67 
71 void infrared_adc_init(void) {
72 #if ! (defined SITL || defined HITL)
75 #ifdef ADC_CHANNEL_IR_TOP
76  adc_buf_channel(ADC_CHANNEL_IR_TOP, &buf_ir3, ADC_CHANNEL_IR_NB_SAMPLES);
77 #endif
78 #endif
79 
81 
82 #if ! (defined ADC_CHANNEL_IR_TOP || defined HITL || defined SITL)
83  ir_adc.ir3 = IR_DEFAULT_CONTRAST;
84 #endif
85 }
86 
87 
91 void infrared_adc_update(void) {
92 #if ! (defined SITL || defined HITL)
93  ir_adc.ir1 = (int32_t)(buf_ir1.sum/buf_ir1.av_nb_sample) - IR_ADC_IR1_NEUTRAL;
94  ir_adc.ir2 = (int32_t)(buf_ir2.sum/buf_ir2.av_nb_sample) - IR_ADC_IR2_NEUTRAL;
95 #ifdef ADC_CHANNEL_IR_TOP
96  ir_adc.ir3 = (int32_t)(buf_ir3.sum/buf_ir3.av_nb_sample) - IR_ADC_TOP_NEUTRAL;
97 #endif // IR_TOP
99 #endif /* !SITL && !HITL */
100 }
101 
#define ADC_CHANNEL_IR_NB_SAMPLES
Definition: infrared_adc.c:51
void infrared_init(void)
Definition: infrared_adc.c:57
void infrared_update(void)
Definition: infrared_adc.c:61
int16_t ir2
Definition: infrared.h:115
struct Infrared_raw ir_adc
Definition: infrared_adc.c:54
void infrared_event(void)
Definition: infrared_adc.c:66
uint8_t av_nb_sample
Definition: adc.h:64
arch independent ADC (Analog to Digital Converter) API
uint32_t sum
Definition: adc.h:61
void infrared_struct_init(void)
Initialisation of ir structure.
Definition: infrared.c:40
Generic interface for all ADC hardware drivers, independent from microcontroller architecture.
Definition: adc.h:60
#define UpdateIRValue(_v)
Definition: infrared.h:151
signed long int32_t
Definition: types.h:19
void adc_buf_channel(uint8_t adc_channel __attribute__((unused)), struct adc_buf *s __attribute__((unused)), uint8_t av_nb_sample __attribute__((unused)))
Required by infrared.c:ir_init()
Definition: jsbsim_ir.c:35
void infrared_adc_init(void)
Initialisation of ir.
Definition: infrared_adc.c:71
static struct adc_buf buf_ir1
Definition: infrared_adc.c:42
int16_t ir1
Definition: infrared.h:114
void infrared_adc_update(void)
Update ir_roll and ir_pitch from ADCs or from simulator message in HITL and SITL modes.
Definition: infrared_adc.c:91
static struct adc_buf buf_ir2
Definition: infrared_adc.c:43
int16_t ir3
Definition: infrared.h:116