Paparazzi UAS  v4.0.4_stable-3-gf39211a
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
light_solar.c
Go to the documentation of this file.
1 /*
2  * $Id: light_solar.c $
3  *
4  * Copyright (C) 2011 Martin Mueller
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 "mcu_periph/adc.h"
33 #include "mcu_periph/uart.h"
34 #include "messages.h"
37 
38 #ifndef ADC_CHANNEL_LIGHT_SOLAR_UP
39 #define ADC_CHANNEL_LIGHT_SOLAR_UP ADC_1
40 #endif
41 #ifndef ADC_CHANNEL_LIGHT_SOLAR_DN
42 #define ADC_CHANNEL_LIGHT_SOLAR_DN ADC_2
43 #endif
44 
45 #ifndef ADC_CHANNEL_LIGHT_NB_SAMPLES
46 #define ADC_CHANNEL_LIGHT_NB_SAMPLES 16
47 #endif
48 
49 #ifndef DOWNLINK_DEVICE
50 #define DOWNLINK_DEVICE DOWNLINK_AP_DEVICE
51 #endif
52 
55 
56 static struct adc_buf buf_light_sol_up;
57 static struct adc_buf buf_light_sol_dn;
58 
59 void light_solar_init( void ) {
62 
63  light_cnt = 0;
64 }
65 
66 void light_solar_periodic( void ) {
69 
70  /* 10k/10k voltage divider, 10 bits adc, 3.3V max */
71 
72  if (++light_cnt >= LIGHT_NB) {
73  DOWNLINK_SEND_SOLAR_RADIATION(DefaultChannel, DefaultDevice,
74  &up[0], &dn[0], &up[1], &dn[1], &up[2], &dn[2], &up[3], &dn[3],
75  &up[4], &dn[4], &up[5], &dn[5], &up[6], &dn[6], &up[7], &dn[7],
76  &up[8], &dn[8], &up[9], &dn[9]);
77  light_cnt = 0;
78  }
79 }
80 
unsigned short uint16_t
Definition: types.h:16
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
static struct adc_buf buf_light_sol_up
Definition: light_solar.c:56
int32_t light_cnt
Definition: light_solar.c:54
uint8_t av_nb_sample
Definition: adc.h:64
arch independent ADC (Analog to Digital Converter) API
uint32_t sum
Definition: adc.h:61
#define ADC_CHANNEL_LIGHT_SOLAR_DN
Definition: light_solar.c:42
uint16_t up[LIGHT_NB]
Definition: light_solar.c:53
uint16_t dn[LIGHT_NB]
Definition: light_solar.c:53
Generic interface for all ADC hardware drivers, independent from microcontroller architecture.
Definition: adc.h:60
void light_solar_periodic(void)
Definition: light_solar.c:66
#define ADC_CHANNEL_LIGHT_NB_SAMPLES
Definition: light_solar.c:46
signed long int32_t
Definition: types.h:19
void light_solar_init(void)
Definition: light_solar.c:59
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
static struct adc_buf buf_light_sol_dn
Definition: light_solar.c:57
#define LIGHT_NB
Definition: light_solar.h:6
#define ADC_CHANNEL_LIGHT_SOLAR_UP
Definition: light_solar.c:39