Added constants for light sensor values

This commit is contained in:
adamdunkels 2010-01-14 20:23:02 +00:00
parent 9ae29c3be5
commit 46753473fa
2 changed files with 22 additions and 20 deletions

View file

@ -28,7 +28,7 @@
* *
* This file is part of the Contiki operating system. * This file is part of the Contiki operating system.
* *
* @(#)$Id: light-sensor.c,v 1.2 2010/01/14 15:50:14 joxe Exp $ * @(#)$Id: light-sensor.c,v 1.3 2010/01/14 20:23:02 adamdunkels Exp $
*/ */
#include <stdlib.h> #include <stdlib.h>
@ -37,7 +37,7 @@
#include "contiki.h" #include "contiki.h"
#include "lib/sensors.h" #include "lib/sensors.h"
#include "dev/light.h" #include "dev/light-sensor.h"
const struct sensors_sensor light_sensor; const struct sensors_sensor light_sensor;
@ -45,8 +45,8 @@ const struct sensors_sensor light_sensor;
* Initialize periodic readings from the 2 photo diodes. The most * Initialize periodic readings from the 2 photo diodes. The most
* recent readings will be stored in ADC internal registers/memory. * recent readings will be stored in ADC internal registers/memory.
*/ */
void static void
static light_sensor_init(void) light_sensor_init(void)
{ {
P6SEL |= 0x30; P6SEL |= 0x30;
P6DIR = 0xff; P6DIR = 0xff;
@ -64,17 +64,19 @@ static light_sensor_init(void)
ADC12CTL0 |= ENC; // enable conversion ADC12CTL0 |= ENC; // enable conversion
ADC12CTL0 |= ADC12SC; // sample & convert ADC12CTL0 |= ADC12SC; // sample & convert
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static int static int
value(int type) value(int type)
{ {
/* should be constants */
switch (type) { switch(type) {
/* Photosynthetically Active Radiation. */ /* Photosynthetically Active Radiation. */
case 0: return ADC12MEM0; case LIGHT_SENSOR_PHOTOSYNTHETIC:
/* Total Solar Radiation. */ return ADC12MEM0;
case 1: return ADC12MEM1;
/* Total Solar Radiation. */
case LIGHT_SENSOR_TOTAL_SOLAR:
return ADC12MEM1;
} }
return 0; return 0;
} }
@ -82,7 +84,7 @@ value(int type)
static int static int
status(int type) status(int type)
{ {
switch (type) { switch(type) {
case SENSORS_ACTIVE: case SENSORS_ACTIVE:
case SENSORS_READY: case SENSORS_READY:
return (ADC12CTL0 & (ADC12ON + REFON)) == (ADC12ON + REFON); return (ADC12CTL0 & (ADC12ON + REFON)) == (ADC12ON + REFON);
@ -94,10 +96,10 @@ status(int type)
static int static int
configure(int type, int c) configure(int type, int c)
{ {
switch (type) { switch(type) {
case SENSORS_ACTIVE: case SENSORS_ACTIVE:
if (c) { if(c) {
if (!status(SENSORS_ACTIVE)) { if(!status(SENSORS_ACTIVE)) {
light_sensor_init(); light_sensor_init();
} }
} else { } else {

View file

@ -26,17 +26,15 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* This file is part of the Configurable Sensor Network Application
* Architecture for sensor nodes running the Contiki operating system.
* *
* $Id: light-sensor.h,v 1.1 2010/01/14 13:53:06 joxe Exp $ * $Id: light-sensor.h,v 1.2 2010/01/14 20:23:02 adamdunkels Exp $
* *
* ----------------------------------------------------------------- * -----------------------------------------------------------------
* *
* Author : Adam Dunkels, Joakim Eriksson, Niclas Finne * Author : Adam Dunkels, Joakim Eriksson, Niclas Finne
* Created : 2010-01-08 * Created : 2010-01-08
* Updated : $Date: 2010/01/14 13:53:06 $ * Updated : $Date: 2010/01/14 20:23:02 $
* $Revision: 1.1 $ * $Revision: 1.2 $
*/ */
#ifndef __LIGHT_SENSOR_H__ #ifndef __LIGHT_SENSOR_H__
@ -46,6 +44,8 @@
extern const struct sensors_sensor light_sensor; extern const struct sensors_sensor light_sensor;
#define LIGHT_SENSOR_PHOTOSYNTHETIC 0
#define LIGHT_SENSOR_TOTAL_SOLAR 1
#endif /* __LIGHT-SENSOR_H__ */ #endif /* __LIGHT-SENSOR_H__ */