Contiki 2.5
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  * @(#)$Id: light.c,v 1.0 2011/02/27 ecalvo $
39  */
40 
41 #include <stdlib.h>
42 #include "contiki.h"
43 #include "dev/light.h"
44 
45 /*
46  * Initialize periodic readings from the 2 photo diodes. The most
47  * recent readings will be stored in ADC internal registers/memory.
48  */
49 void
50 sensors_light_init(void)
51 {
52 }
53 
54 /* Photosynthetically Active Radiation. */
55 unsigned
56 sensors_light1(void)
57 {
58  return 0;
59 }
60 
61 /* Total Solar Radiation. */
62 unsigned
63 sensors_light2(void)
64 {
65  return 0;
66 }
67 
68 /*
69  * Most of this information taken from
70  * http://www.moteiv.com/community/Getting_Data_from_Tmote_Sky%27s_Sensors
71  *
72  * The Photosynthetically Active Radiation (PAR) sensor as well as the
73  * Total Solar Radiation (TSR) sensor uses the 2.5V reference voltage
74  * to produce the raw ADC value.
75 
76  * The voltage across each sensor is:
77  *
78  * VsensorPAR = ADCValuePAR/4096 * Vref (1a)
79  * VsensorTSR = ADCValueTSR/4096 * Vref (1b)
80  * where Vref = 2.5V
81  *
82  * This voltage creates a current through a resistor R=100KOhm and this
83  * current has a linear relationship with the light intensity in Lux.
84  * IPAR = VsensorPAR / 100,000 (2a)
85  * ITSR = VsensorTSR / 100,000 (2b)
86  *
87  * S1087 (PAR) lx = 1e6 * IPAR * 1000 (3a)
88  * S1087-01 (TSR) lx = 1e5 * ITSR * 1000 (3b)
89  *
90  * lxPAR = 10e9 * ADCValuePAR *(1/4096)* Vref * 10e-5 or
91  * lxPAR = 3125* ADCvaluePAR / 512
92  * and
93  * lxTSR = 10e8 * ADCValueTSR *(1/4096)* Vref * 10e-5 or
94  * lxTSR = 625* ADCvalueTSR / 1024
95 */
96 
97 #if 0
98 /* Photosynthetically Active Radiation in Lux units. */
99 unsigned
100 sensors_light1_lux(void)
101 {
102  unsigned temp;
103  temp = (uint32_t)ADC12MEM0;
104 
105  temp = (temp*3125)>> 9;
106  return (uint16_t)(temp & 0xFFFF);
107 }
108 
109 /* Total Solar Radiation in Lux units. */
110 unsigned
111 sensors_light2_lux(void)
112 {
113  unsigned temp;
114  temp = (uint32_t)ADC12MEM1;
115 
116  temp = (temp*625)>> 10;
117  return (uint16_t)(temp & 0xFFFF);
118 }
119 #endif