Update of /cvsroot/firebug/mts400/apps/TestTaos
In directory sc8-pr-cvs1:/tmp/cvs-serv11889
Added Files:
.cvsignore Makefile taos.nc taosM.nc
Log Message:
Test application for taos light sensor.
--- NEW FILE: .cvsignore ---
build *~
--- NEW FILE: Makefile ---
COMPONENT=taos
SENSORBOARD=taos
include ../Makelocal
include $(TOSROOT)/apps/Makerules
--- NEW FILE: taos.nc ---
/* -*- Mode: C; c-basic-indent: 3; indent-tabs-mode: nil -*- */
configuration taos {
}
implementation {
components Main,
taosM,
MicaWbSwitch,
TimerC,
NoLeds,
LedsC,
TaosPhoto;
Main.StdControl -> taosM;
Main.StdControl -> TimerC;
taosM.Leds -> LedsC;
taosM.Timer -> TimerC.Timer[unique("Timer")];
taosM.TaosControl -> TaosPhoto;
taosM.TaosCh0 -> TaosPhoto.ADC[0];
taosM.TaosCh1 -> TaosPhoto.ADC[1];
}
--- NEW FILE: taosM.nc ---
/* -*- Mode: C; c-basic-indent: 3; indent-tabs-mode: nil -*- */
/******************************************************************************
* Measures MTS400/420 weatherboard sensors & gps and converts to engineering units
* were possible.
*
* Output results through mica2 uart port. Connect serial cable from programming
* board to PC to monitor ouput. Use any terminal monitoring program set for
* 57600, N,8,1
*
* NOTE:
* No real power strategy; just turns sensors on sequentially.
* Should add BusArbitration routines, like mica2dotwb for better power control
*****************************************************************************/
module taosM {
provides interface StdControl;
uses {
interface Timer;
interface Leds;
interface SplitControl as TaosControl;
interface ADC as TaosCh0;
interface ADC as TaosCh1;
}
}
implementation {
#include "SODebug.h"
enum {START, BUSY, LIGHT_DONE, ACCEL_DONE};
uint16_t TaosData;
uint8_t state;
command result_t StdControl.init() {
atomic {
TaosData = 0;
}
init_debug();
call Leds.init();
call TaosControl.init();
return SUCCESS;
}
command result_t StdControl.start() {
call Leds.redOn();
call Leds.yellowOn();
call Leds.greenOn();
state = START;
call Timer.start(TIMER_REPEAT, 500);
return SUCCESS;
}
command result_t StdControl.stop() {
return SUCCESS;
}
event result_t Timer.fired() {
call Leds.redOff();
call Leds.yellowOff();
call Leds.greenOff();
switch (state) {
case START:
state = BUSY;
call TaosControl.start();
break;
case LIGHT_DONE:
state = START;
break;
default:
break;
}
return SUCCESS;
}
/**
* Taos- tsl2250 light sensor
* Two ADC channels:
* ADC Count Value (ACNTx) = INT(16.5*[CV-1]) +S*CV
* where CV = 2^^C
* C = (data & 0x7) >> 4
* S = data & 0xF
* Light level (lux) = ACNT0*0.46*(e^^-3.13*R)
* R = ACNT1/ACNT0
*/
async event result_t TaosCh1.dataReady(uint16_t data) {
uint16_t CV1,CH1,ST1,ACNT0,ACNT1;
float CNT1,R,Lux;
call Leds.greenToggle();
atomic {
ST1 = TaosData & 0xf;
}
atomic {
CH1 = (TaosData & 0x70) >> 4;
}
CV1 = 1 << CH1;
CNT1 = (int)(16.5*(CV1-1)) + ST1*CV1;
ACNT0 = (int)CNT1;
atomic {
if (TaosData == 0xff) {
SODbg(DBG_USR2, "Taos Ch0 data: OVERFLOW \n") ;
}
}
SODbg(DBG_USR2, "Taos Ch0 data: %i Cord: %i Step: %i ADC Counts: %i \n", TaosData & 0x0FF, CH1,ST1,ACNT0);
data = data & 0xff;
ST1 = data & 0xf;
CH1 = (data & 0x70) >> 4;
CV1 = 1 << CH1;
CNT1 = (int)(16.5*(CV1-1)) + ST1*CV1;
ACNT1 = (int)CNT1;
R = (float)ACNT1/(float)ACNT0;
Lux = (float)ACNT0*0.46/exp(3.13*R);
if (data == 0xff) {
SODbg(DBG_USR2, "Taos Ch1 data: OVERFLOW \n");
}
SODbg(DBG_USR2, "Taos Ch1 data: %i Cord: %i Step: %i ADC Counts: %i Light(lux): %i \n", data & 0x0FF, CH1,ST1,ACNT1,(int)Lux);
call TaosControl.stop();
return SUCCESS;
}
async event result_t TaosCh0.dataReady(uint16_t data) {
atomic {
TaosData = data & 0xff;
}
SODbg(DBG_USR2, "Got Taos Ch0 data \n") ;
return call TaosCh1.getData();
}
event result_t TaosControl.startDone(){
return call TaosCh0.getData();
}
event result_t TaosControl.initDone() {
return SUCCESS;
}
event result_t TaosControl.stopDone() {
state = LIGHT_DONE;
return SUCCESS;
}
}
|