changed sky sensors to new api

This commit is contained in:
joxe 2010-01-14 13:53:06 +00:00
parent 84d969ce85
commit 4a3953204f
6 changed files with 236 additions and 120 deletions

View File

@ -26,14 +26,14 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: acc-sensor.c,v 1.3 2009/05/08 16:03:50 joxe Exp $
* $Id: acc-sensor.c,v 1.4 2010/01/14 13:53:06 joxe Exp $
*
* -----------------------------------------------------------------
*
* Author : Adam Dunkels, Joakim Eriksson, Niclas Finne
* Created : 2005-11-01
* Updated : $Date: 2009/05/08 16:03:50 $
* $Revision: 1.3 $
* Updated : $Date: 2010/01/14 13:53:06 $
* $Revision: 1.4 $
*/
#include "dev/acc-sensor.h"
@ -43,19 +43,8 @@
#include <stdio.h>
const struct sensors_sensor acc_sensor;
static uint8_t active;
/*---------------------------------------------------------------------------*/
static void
init(void)
{
}
/*---------------------------------------------------------------------------*/
static int
irq(void)
{
return 0;
}
/*---------------------------------------------------------------------------*/
static void
activate(void)
@ -87,6 +76,7 @@ activate(void)
ADC12CTL0 |= ENC | ADC12SC;
/* Irq_adc12_activate(&acc_sensor, 6, (INCH_11 + SREF_1)); */
active = 1;
}
/*---------------------------------------------------------------------------*/
static void
@ -94,12 +84,7 @@ deactivate(void)
{
/* irq_adc12_deactivate(&acc_sensor, 6);
acc_value = 0;*/
}
/*---------------------------------------------------------------------------*/
static int
active(void)
{
return 0; /* irq_adc12_active(6);*/
active = 0;
}
/*---------------------------------------------------------------------------*/
static unsigned int
@ -121,15 +106,27 @@ value(int type)
static int
configure(int type, void *c)
{
switch(type) {
case SENSORS_ACTIVE:
if (c) {
activate();
} else {
deactivate();
}
}
return 0;
}
/*---------------------------------------------------------------------------*/
static void *
status(int type)
{
switch (type) {
case SENSORS_ACTIVE:
case SENSORS_READY:
return (void *) active;
}
return NULL;
}
/*---------------------------------------------------------------------------*/
SENSORS_SENSOR(acc_sensor, ACC_SENSOR,
init, irq, activate, deactivate, active,
value, configure, status);

View File

@ -26,14 +26,14 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: battery-sensor.c,v 1.2 2008/09/18 21:29:06 joxe Exp $
* $Id: battery-sensor.c,v 1.3 2010/01/14 13:53:06 joxe Exp $
*
* -----------------------------------------------------------------
*
* Author : Adam Dunkels, Joakim Eriksson, Niclas Finne
* Created : 2005-11-01
* Updated : $Date: 2008/09/18 21:29:06 $
* $Revision: 1.2 $
* Updated : $Date: 2010/01/14 13:53:06 $
* $Revision: 1.3 $
*/
#include "dev/battery-sensor.h"
@ -41,21 +41,7 @@
#include "dev/irq.h"
const struct sensors_sensor battery_sensor;
/*static unsigned int battery_value;*/
/*---------------------------------------------------------------------------*/
static void
init(void)
{
/* battery_value = 0;*/
}
/*---------------------------------------------------------------------------*/
static int
irq(void)
{
/* battery_value = ADC12MEM6;*/
return 0;
}
/*---------------------------------------------------------------------------*/
static void
activate(void)
@ -67,32 +53,26 @@ activate(void)
P6DIR = 0xff;
P6OUT = 0x00;
/* stop converting immediately */
ADC12CTL0 &= ~ENC;
ADC12CTL1 &= ~CONSEQ_3;
ADC12CTL1 &= ~CONSEQ_3;
/* Configure ADC12_2 to sample channel 11 (voltage) and use */
/* the Vref+ as reference (SREF_1) since it is a stable reference */
ADC12MCTL2 = (INCH_11 + SREF_1);
ADC12CTL1 |= CONSEQ_3;
ADC12CTL0 |= ENC | ADC12SC;
ADC12CTL0 |= ENC | ADC12SC;
/* Irq_adc12_activate(&battery_sensor, 6, (INCH_11 + SREF_1)); */
active = 1;
}
/*---------------------------------------------------------------------------*/
static void
deactivate(void)
{
/* irq_adc12_deactivate(&battery_sensor, 6);
battery_value = 0;*/
}
/*---------------------------------------------------------------------------*/
static int
active(void)
{
return 0; /* irq_adc12_active(6);*/
active = 0;
}
/*---------------------------------------------------------------------------*/
static unsigned int
@ -104,15 +84,27 @@ value(int type)
static int
configure(int type, void *c)
{
switch(type) {
case SENSORS_ACTIVE:
if (c) {
activate();
} else {
deactivate();
}
}
return 0;
}
/*---------------------------------------------------------------------------*/
static void *
status(int type)
{
switch (type) {
case SENSORS_ACTIVE:
case SENSORS_READY:
return (void *) active;
}
return NULL;
}
/*---------------------------------------------------------------------------*/
SENSORS_SENSOR(battery_sensor, BATTERY_SENSOR,
init, irq, activate, deactivate, active,
value, configure, status);

View File

@ -28,67 +28,39 @@
*
* This file is part of the Contiki operating system.
*
* @(#)$Id: button-sensor.c,v 1.1 2007/03/15 21:44:51 adamdunkels Exp $
* @(#)$Id: button-sensor.c,v 1.2 2010/01/14 13:53:06 joxe Exp $
*/
#include "lib/sensors.h"
#include "dev/hwconf.h"
#include "dev/button-sensor.h"
#include "dev/leds.h"
#include <signal.h>
const struct sensors_sensor button_sensor;
static struct timer debouncetimer;
static void* status(int type);
HWCONF_PIN(BUTTON, 2, 7);
HWCONF_IRQ(BUTTON, 2, 7);
/*---------------------------------------------------------------------------*/
static void
init(void)
interrupt(PORT2_VECTOR)
irq_p2(void)
{
timer_set(&debouncetimer, 0);
BUTTON_IRQ_EDGE_SELECTD();
ENERGEST_ON(ENERGEST_TYPE_IRQ);
BUTTON_SELECT();
BUTTON_MAKE_INPUT();
}
/*---------------------------------------------------------------------------*/
static int
irq(void)
{
if(BUTTON_CHECK_IRQ()) {
if(timer_expired(&debouncetimer)) {
timer_set(&debouncetimer, CLOCK_SECOND / 4);
sensors_changed(&button_sensor);
return 1;
LPM4_EXIT;
}
}
P2IFG = 0x00;
ENERGEST_OFF(ENERGEST_TYPE_IRQ);
}
/*---------------------------------------------------------------------------*/
return 0;
}
/*---------------------------------------------------------------------------*/
static void
activate(void)
{
sensors_add_irq(&button_sensor, BUTTON_IRQ_PORT());
BUTTON_ENABLE_IRQ();
}
/*---------------------------------------------------------------------------*/
static void
deactivate(void)
{
BUTTON_DISABLE_IRQ();
sensors_remove_irq(&button_sensor, BUTTON_IRQ_PORT());
}
/*---------------------------------------------------------------------------*/
static int
active(void)
{
return BUTTON_IRQ_ENABLED();
}
/*---------------------------------------------------------------------------*/
static unsigned int
value(int type)
{
@ -98,15 +70,35 @@ value(int type)
static int
configure(int type, void *c)
{
switch (type) {
case SENSORS_ACTIVE:
if (c) {
if(!status(SENSORS_ACTIVE)) {
timer_set(&debouncetimer, 0);
BUTTON_IRQ_EDGE_SELECTD();
BUTTON_SELECT();
BUTTON_MAKE_INPUT();
BUTTON_ENABLE_IRQ();
}
} else {
BUTTON_DISABLE_IRQ();
}
}
return 0;
}
/*---------------------------------------------------------------------------*/
static void *
status(int type)
{
switch (type) {
case SENSORS_ACTIVE:
case SENSORS_READY:
return BUTTON_IRQ_ENABLED();
}
return NULL;
}
/*---------------------------------------------------------------------------*/
SENSORS_SENSOR(button_sensor, BUTTON_SENSOR,
init, irq, activate, deactivate, active,
value, configure, status);

View File

@ -0,0 +1,112 @@
/*
* Copyright (c) 2005, Swedish Institute of Computer Science
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* This file is part of the Contiki operating system.
*
* @(#)$Id: light-sensor.c,v 1.1 2010/01/14 13:53:06 joxe Exp $
*/
#include <stdlib.h>
#include <io.h>
#include "contiki.h"
#include "lib/sensors.h"
#include "dev/light.h"
const struct sensors_sensor light_sensor;
/*
* Initialize periodic readings from the 2 photo diodes. The most
* recent readings will be stored in ADC internal registers/memory.
*/
void
static light_sensor_init(void)
{
P6SEL |= 0x30;
P6DIR = 0xff;
P6OUT = 0x00;
/* Set up the ADC. */
ADC12CTL0 = REF2_5V + SHT0_6 + SHT1_6 + MSC; // Setup ADC12, ref., sampling time
ADC12CTL1 = SHP + CONSEQ_3 + CSTARTADD_0; // Use sampling timer, repeat-sequenc-of-channels
ADC12MCTL0 = (INCH_4 + SREF_0); // photodiode 1 (P64)
ADC12MCTL1 = (INCH_5 + SREF_0); // photodiode 2 (P65)
ADC12CTL0 |= ADC12ON + REFON;
ADC12CTL0 |= ENC; // enable conversion
ADC12CTL0 |= ADC12SC; // sample & convert
}
/*---------------------------------------------------------------------------*/
static unsigned int
value(int type)
{
/* should be constants */
switch (type) {
/* Photosynthetically Active Radiation. */
case 0: return ADC12MEM0;
/* Total Solar Radiation. */
case 1: return ADC12MEM1;
}
return 0;
}
/*---------------------------------------------------------------------------*/
static void *
status(int type)
{
switch (type) {
case SENSORS_ACTIVE:
case SENSORS_READY:
return (ADC12CTL0 & (ADC12ON + REFON)) == (ADC12ON + REFON);
}
return NULL;
}
/*---------------------------------------------------------------------------*/
static int
configure(int type, void *c)
{
switch (type) {
case SENSORS_ACTIVE:
if (c) {
if (!status(SENSORS_ACTIVE)) {
light_sensor_init();
}
} else {
/* shut down sensing */
ADC12CTL0 = 0;
}
}
return 0;
}
/*---------------------------------------------------------------------------*/
SENSORS_SENSOR(light_sensor, "Light",
value, configure, status);

View File

@ -0,0 +1,51 @@
/*
* Copyright (c) 2010, Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* 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 $
*
* -----------------------------------------------------------------
*
* Author : Adam Dunkels, Joakim Eriksson, Niclas Finne
* Created : 2010-01-08
* Updated : $Date: 2010/01/14 13:53:06 $
* $Revision: 1.1 $
*/
#ifndef __LIGHT_SENSOR_H__
#define __LIGHT_SENSOR_H__
#include "lib/sensors.h"
extern const struct sensors_sensor light_sensor;
#endif /* __LIGHT-SENSOR_H__ */

View File

@ -28,7 +28,7 @@
*
* This file is part of the Contiki operating system.
*
* @(#)$Id: radio-sensor.c,v 1.3 2008/07/02 09:05:41 adamdunkels Exp $
* @(#)$Id: radio-sensor.c,v 1.4 2010/01/14 13:53:06 joxe Exp $
*/
#include "lib/sensors.h"
@ -38,33 +38,6 @@
const struct sensors_sensor radio_sensor;
/*---------------------------------------------------------------------------*/
static void
init(void)
{
}
/*---------------------------------------------------------------------------*/
static int
irq(void)
{
return 0;
}
/*---------------------------------------------------------------------------*/
static void
activate(void)
{
}
/*---------------------------------------------------------------------------*/
static void
deactivate(void)
{
}
/*---------------------------------------------------------------------------*/
static int
active(void)
{
return 0;
}
/*---------------------------------------------------------------------------*/
static unsigned int
value(int type)
@ -91,5 +64,4 @@ status(int type)
}
/*---------------------------------------------------------------------------*/
SENSORS_SENSOR(radio_sensor, RADIO_SENSOR,
init, irq, activate, deactivate, active,
value, configure, status);