Paparazzi UAS  v5.14.0_stable-0-g3f680d1
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
infrared_adc.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2003-2010 The Paparazzi Team
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 
30 #include <stdlib.h>
31 
33 #include "mcu_periph/adc.h"
34 
35 #include BOARD_CONFIG
36 #include "generated/airframe.h"
37 
38 // TODO Specific sim implementation
39 #if ! (defined SITL || defined HITL)
40 static struct adc_buf buf_ir1;
41 static struct adc_buf buf_ir2;
42 
43 #ifdef ADC_CHANNEL_IR_TOP
44 static struct adc_buf buf_ir3;
45 #endif
46 #endif
47 
48 #ifndef ADC_CHANNEL_IR_NB_SAMPLES
49 #define ADC_CHANNEL_IR_NB_SAMPLES DEFAULT_AV_NB_SAMPLE
50 #endif
51 
53 
54 // Standard infrared implementation
55 void infrared_init(void)
56 {
58 }
59 
60 void infrared_update(void)
61 {
63 }
64 
65 /* No event with adc ir */
66 void infrared_event(void) {}
67 
72 {
73 #if ! (defined SITL || defined HITL)
76 #ifdef ADC_CHANNEL_IR_TOP
77  adc_buf_channel(ADC_CHANNEL_IR_TOP, &buf_ir3, ADC_CHANNEL_IR_NB_SAMPLES);
78 #endif
79 #endif
80 
82 
83 #if ! (defined ADC_CHANNEL_IR_TOP || defined HITL || defined SITL)
84  ir_adc.ir3 = IR_DEFAULT_CONTRAST;
85 #endif
86 }
87 
88 
93 {
94 #if ! (defined SITL || defined HITL)
95  ir_adc.ir1 = (int32_t)(buf_ir1.sum / buf_ir1.av_nb_sample) - IR_ADC_IR1_NEUTRAL;
96  ir_adc.ir2 = (int32_t)(buf_ir2.sum / buf_ir2.av_nb_sample) - IR_ADC_IR2_NEUTRAL;
97 #ifdef ADC_CHANNEL_IR_TOP
98  ir_adc.ir3 = (int32_t)(buf_ir3.sum / buf_ir3.av_nb_sample) - IR_ADC_TOP_NEUTRAL;
99 #endif // IR_TOP
101 #endif /* !SITL && !HITL */
102 }
103 
uint8_t av_nb_sample
Definition: adc.h:57
#define ADC_CHANNEL_IR_NB_SAMPLES
Definition: infrared_adc.c:49
void infrared_init(void)
Definition: infrared_adc.c:55
void infrared_update(void)
Definition: infrared_adc.c:60
int16_t ir1
Definition: infrared.h:112
void adc_buf_channel(uint8_t adc_channel, struct adc_buf *s, uint8_t av_nb_sample)
Link between ChibiOS ADC drivers and Paparazzi adc_buffers.
Definition: adc_arch.c:281
uint32_t sum
Definition: adc.h:54
struct Infrared_raw ir_adc
Definition: infrared_adc.c:52
int16_t ir3
Definition: infrared.h:114
void infrared_event(void)
Definition: infrared_adc.c:66
arch independent ADC (Analog to Digital Converter) API
Generic interface for all ADC hardware drivers, independent from microcontroller architecture.
Definition: adc.h:53
void infrared_struct_init(void)
Initialisation of ir structure.
Definition: infrared.c:34
#define UpdateIRValue(_v)
Definition: infrared.h:149
signed long int32_t
Definition: types.h:19
void infrared_adc_init(void)
Initialisation of ir.
Definition: infrared_adc.c:71
static struct adc_buf buf_ir1
Definition: infrared_adc.c:40
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:92
int16_t ir2
Definition: infrared.h:113
static struct adc_buf buf_ir2
Definition: infrared_adc.c:41