Contiki 3.x
light.c
1 /*
2  * Copyright (c) 2011, Zolertia(TM) is a trademark of Advancare,SL
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the Institute nor the names of its contributors
14  * may be used to endorse or promote products derived from this software
15  * without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  * This file is part of the Contiki operating system.
30  *
31  *
32  * \file
33  * Dummy light-sensor to allow as many programs for sky to compile for Z1
34  *
35  * \author
36  * Enric M. Calvo <ecalvo@zolertia.com>, adapted from previous work
37  *
38  */
39 
40 #include <stdlib.h>
41 #include "contiki.h"
42 #include "dev/light.h"
43 
44 /*
45  * Initialize periodic readings from the 2 photo diodes. The most
46  * recent readings will be stored in ADC internal registers/memory.
47  */
48 void
49 sensors_light_init(void)
50 {
51 }
52 
53 /* Photosynthetically Active Radiation. */
54 unsigned
55 sensors_light1(void)
56 {
57  return 0;
58 }
59 
60 /* Total Solar Radiation. */
61 unsigned
62 sensors_light2(void)
63 {
64  return 0;
65 }
66 
67 /*
68  * Most of this information taken from
69  * http://www.moteiv.com/community/Getting_Data_from_Tmote_Sky%27s_Sensors
70  *
71  * The Photosynthetically Active Radiation (PAR) sensor as well as the
72  * Total Solar Radiation (TSR) sensor uses the 2.5V reference voltage
73  * to produce the raw ADC value.
74 
75  * The voltage across each sensor is:
76  *
77  * VsensorPAR = ADCValuePAR/4096 * Vref (1a)
78  * VsensorTSR = ADCValueTSR/4096 * Vref (1b)
79  * where Vref = 2.5V
80  *
81  * This voltage creates a current through a resistor R=100KOhm and this
82  * current has a linear relationship with the light intensity in Lux.
83  * IPAR = VsensorPAR / 100,000 (2a)
84  * ITSR = VsensorTSR / 100,000 (2b)
85  *
86  * S1087 (PAR) lx = 1e6 * IPAR * 1000 (3a)
87  * S1087-01 (TSR) lx = 1e5 * ITSR * 1000 (3b)
88  *
89  * lxPAR = 10e9 * ADCValuePAR *(1/4096)* Vref * 10e-5 or
90  * lxPAR = 3125* ADCvaluePAR / 512
91  * and
92  * lxTSR = 10e8 * ADCValueTSR *(1/4096)* Vref * 10e-5 or
93  * lxTSR = 625* ADCvalueTSR / 1024
94 */
95 
96 #if 0
97 /* Photosynthetically Active Radiation in Lux units. */
98 unsigned
99 sensors_light1_lux(void)
100 {
101  unsigned temp;
102  temp = (uint32_t)ADC12MEM0;
103 
104  temp = (temp*3125)>> 9;
105  return (uint16_t)(temp & 0xFFFF);
106 }
107 
108 /* Total Solar Radiation in Lux units. */
109 unsigned
110 sensors_light2_lux(void)
111 {
112  unsigned temp;
113  temp = (uint32_t)ADC12MEM1;
114 
115  temp = (temp*625)>> 10;
116  return (uint16_t)(temp & 0xFFFF);
117 }
118 #endif