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
light_solar.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2011 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 
30 #include "mcu_periph/adc.h"
31 #include "mcu_periph/uart.h"
32 #include "messages.h"
35 
36 #ifndef ADC_CHANNEL_LIGHT_SOLAR_UP
37 #define ADC_CHANNEL_LIGHT_SOLAR_UP ADC_1
38 #endif
39 #ifndef ADC_CHANNEL_LIGHT_SOLAR_DN
40 #define ADC_CHANNEL_LIGHT_SOLAR_DN ADC_2
41 #endif
42 
43 #ifndef ADC_CHANNEL_LIGHT_NB_SAMPLES
44 #define ADC_CHANNEL_LIGHT_NB_SAMPLES 16
45 #endif
46 
47 #ifndef DOWNLINK_DEVICE
48 #define DOWNLINK_DEVICE DOWNLINK_AP_DEVICE
49 #endif
50 
53 
54 static struct adc_buf buf_light_sol_up;
55 static struct adc_buf buf_light_sol_dn;
56 
57 void light_solar_init( void ) {
60 
61  light_cnt = 0;
62 }
63 
64 void light_solar_periodic( void ) {
67 
68  /* 10k/10k voltage divider, 10 bits adc, 3.3V max */
69 
70  if (++light_cnt >= LIGHT_NB) {
71  DOWNLINK_SEND_SOLAR_RADIATION(DefaultChannel, DefaultDevice,
72  &up[0], &dn[0], &up[1], &dn[1], &up[2], &dn[2], &up[3], &dn[3],
73  &up[4], &dn[4], &up[5], &dn[5], &up[6], &dn[6], &up[7], &dn[7],
74  &up[8], &dn[8], &up[9], &dn[9]);
75  light_cnt = 0;
76  }
77 }
78 
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:54
int32_t light_cnt
Definition: light_solar.c:52
void adc_buf_channel(uint8_t adc_channel, struct adc_buf *s, uint8_t av_nb_sample)
Registers a buffer to be used to store the specified converted channel Usage:
Definition: adc_arch.c:59
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:40
uint16_t up[LIGHT_NB]
Definition: light_solar.c:51
uint16_t dn[LIGHT_NB]
Definition: light_solar.c:51
Generic interface for all ADC hardware drivers, independent from microcontroller architecture.
Definition: adc.h:60
void light_solar_periodic(void)
Definition: light_solar.c:64
#define ADC_CHANNEL_LIGHT_NB_SAMPLES
Definition: light_solar.c:44
signed long int32_t
Definition: types.h:19
void light_solar_init(void)
Definition: light_solar.c:57
static struct adc_buf buf_light_sol_dn
Definition: light_solar.c:55
#define LIGHT_NB
Definition: light_solar.h:6
#define ADC_CHANNEL_LIGHT_SOLAR_UP
Definition: light_solar.c:37