[Firebug-cvs] firebug/project/src/sensordata Makefile,NONE,1.1 TestMTS400.nc,NONE,1.1 TestMTS400M.nc
Brought to you by:
doolin
From: <do...@us...> - 2003-08-22 02:58:30
|
Update of /cvsroot/firebug/firebug/project/src/sensordata In directory sc8-pr-cvs1:/tmp/cvs-serv13342 Added Files: Makefile TestMTS400.nc TestMTS400M.nc Log Message: xbow test data demo app for new fireboard. --- NEW FILE: Makefile --- #/* -*- Mode: Makefile; c-basic-indent: 2; -*- */ #/* $Id: Makefile,v 1.1 2003/08/21 20:31:05 doolin Exp $ */ #/*////////////////////////////////////////////////////////*/ #/** # * Max Min Chen, David Doolin, Anshuman Sharma # */ #/*////////////////////////////////////////////////////////*/ ifndef XBOWROOT echo Please set the XBOWROOT environment variable endif UISP = uisp UISP_FLAGS = -dprog=dapa $(UISP_EXTRA_FLAGS) # FIXME: TOSROOT needs to go away, maybe change to # BLASTROOT TOSROOT=/cygdrive/c PLATFORMS= mica mica2 pc #DATASTRUCTURE=$(TOSROOT)/broken/experimental/terence/tos/lib/DataStructure #ROUTESTACK=$(TOSROOT)/broken/experimental/terence/apps/mh6 #INCLUDES=-I$(DATASTRUCTURE) -I$(ROUTESTACK) #CC1000=-I/cygdrive/d/tinyos-1.x/tos/platform/mica2 INCLUDES=-I$(TOSROOT)/Blast-0.1/Sender \ -I$(TOSROOT)/Blast-0.1/Interface \ -I$(TOSROOT)/Blast-0.1/DataStructure \ -I$(TOSROOT)/Blast-0.1/VirtualComm \ -I$(TOSROOT)/Blast-0.1/ParentSelection \ -I$(TOSROOT)/tinyos-1.x/tos \ -I$(XBOWROOT)/tos/sensorboards/mts400 \ -I$(XBOWROOT)/tos/interfaces PFLAGS := $(PFLAGS) -Wall -Wshadow -DDEF_TOS_AM_GROUP=0x7d PLATAUX=$(PLATFORMS) all PLATFORM := $(filter $(PLATAUX), $(MAKECMDGOALS)) PFLAGS := -target=$(PLATFORM) $(PFLAGS) MAKECMDGOALS := $(filter-out $(PLATAUX), $(MAKECMDGOALS)) BUILDDIR= build/$(PLATFORM) MAIN_EXE= $(BUILDDIR)/main.exe MAIN_SREC= $(BUILDDIR)/main.srec TARGETS= CollectDataFB BaseStation TestMTS400 TARGET := $(filter $(TARGETS), $(MAKECMDGOALS)) MAKECMDGOALS := $(filter-out $(TARGET), $(MAKECMDGOALS)) ifeq ($(PLATFORM), pc) PFLAGS := -g -O0 -pthread $(PFLAGS) -fnesc-nido-tosnodes=1000 -fnesc-cfile=$(BUILDDIR)/app.c MAIN_TARGET = $(MAIN_EXE) else PFLAGS := -Os $(PFLAGS) -finline-limit=100000 -fnesc-cfile=$(BUILDDIR)/app.c MAIN_TARGET = $(MAIN_SREC) endif NCC := ncc -board=micasb ###################################################################### # top-level rules. switch based on MAKECMDGOALS ###################################################################### # # rules for make clean # ifeq ($(MAKECMDGOALS)_x, clean_x) PLATFORM= $(PLATAUX): @echo "" else ifeq ($(PLATFORM)_x,_x) $(error $(PLATAUX) $(MAKECMDGOALS) $(USAGE)) endif MAKECMDGOALS := $(patsubst install.%,install,$(MAKECMDGOALS)) MAKECMDGOALS := $(patsubst reinstall.%,reinstall,$(MAKECMDGOALS)) # # rules for make install <platform> # ifeq ($(MAKECMDGOALS)_x, install_x) $(PLATAUX): @true else ifeq ($(MAKECMDGOALS)_x, reinstall_x) $(PLATAUX): @true else all: for platform in $(PLATFORMS); do \ $(MAKE) $$platform $(DOCS) || exit 1; \ done $(PLATFORMS): build endif endif endif ## Make a pc build ## -Wshadow warns when globals are shadowed by locals. build: $(MAIN_TARGET) install: $(MAIN_SREC) FORCE @$(MAKE) $(PLATFORM) re$@ install.%: $(MAIN_SREC) FORCE $(MAKE) $(PLATFORM) re$@ reinstall: FORCE @echo " installing $(PLATFORM) binary" $(UISP) $(UISP_FLAGS) --erase sleep 1 $(UISP) $(UISP_FLAGS) --upload if=$(MAIN_SREC) sleep 1 $(UISP) $(UISP_FLAGS) --verify if=$(MAIN_SREC) reinstall.%: FORCE @echo " installing $(PLATFORM) binary " set-mote-id $(BUILDDIR)/main.srec $(BUILDDIR)/main.srec.out `echo $@ |sed 's:reinstall.::g'` $(UISP) $(UISP_FLAGS) --erase sleep 1 $(UISP) $(UISP_FLAGS) --upload if=$(BUILDDIR)/main.srec.out sleep 1 $(UISP) $(UISP_FLAGS) --verify if=$(BUILDDIR)/main.srec.out $(MAIN_EXE): $(BUILDDIR) FORCE @echo " compiling $(TARGET) to a $(PLATFORM) binary" $(NCC) -o $(MAIN_EXE) $(PFLAGS) $(CFLAGS) $(INCLUDES) $(TARGET).nc -lm $(LDFLAGS) @echo " compiled $(COMPONENT) to $@" @objdump -h $(MAIN_EXE) | perl -ne '$$b{$$1}=hex $$2 if /^\s*\d+\s*\.(text|data|bss)\s+(\S+)/; END { printf("%16d bytes in ROM\n%16d bytes in RAM\n",$$b{text}+$$b{data},$$b{bss}); }' $(MAIN_SREC): $(MAIN_EXE) avr-objcopy --output-target=srec $(MAIN_EXE) $(MAIN_SREC) $(BUILDDIR): mkdir -p $(BUILDDIR) clean: rm -rf $(BUILDDIR) rm -f core.* rm -f *~ FORCE: .phony: FORCE --- NEW FILE: TestMTS400.nc --- /* tab:4 * * * "Copyright (c) 2000-2002 The Regents of the University of California. * All rights reserved. * * Permission to use, copy, modify, and distribute this software and its * documentation for any purpose, without fee, and without written agreement is * hereby granted, provided that the above copyright notice, the following * two paragraphs and the author appear in all copies of this software. * * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS." * */ /* tab:4 * IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. By * downloading, copying, installing or using the software you agree to * this license. If you do not agree to this license, do not download, * install, copy or use the software. * * Intel Open Source License * * Copyright (c) 2002 Intel Corporation * All rights reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 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. * Neither the name of the Intel Corporation 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 COPYRIGHT HOLDERS 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 INTEL OR ITS * 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. * * */ configuration TestMTS400 { } implementation { components Main, TestMTS400M, SensirionHumidity, \ IntersemaPressure,MicaWbSwitch,UARTGpsPacket,TimerC, NoLeds,LedsC, Accel, TaosPhoto; Main.StdControl -> TestMTS400M; Main.StdControl -> TimerC; // Wiring for gps TestMTS400M.GpsControl -> UARTGpsPacket; TestMTS400M.GpsSend -> UARTGpsPacket; TestMTS400M.GpsReceive -> UARTGpsPacket; TestMTS400M.GpsCmd -> UARTGpsPacket.GpsCmd; // Wiring for Taos light sensor TestMTS400M.TaosControl -> TaosPhoto; TestMTS400M.TaosCh0 -> TaosPhoto.ADC[0]; TestMTS400M.TaosCh1 -> TaosPhoto.ADC[1]; // Wiring for Accelerometer TestMTS400M.AccelControl->Accel.StdControl; TestMTS400M.AccelCmd -> Accel.AccelCmd; TestMTS400M.AccelX -> Accel.AccelX; TestMTS400M.AccelY -> Accel.AccelY; // Wiring for Sensirion humidity/temperature sensor TestMTS400M.TempHumControl -> SensirionHumidity; TestMTS400M.Humidity -> SensirionHumidity.Humidity; TestMTS400M.Temperature -> SensirionHumidity.Temperature; TestMTS400M.HumidityError -> SensirionHumidity.HumidityError; TestMTS400M.TemperatureError -> SensirionHumidity.TemperatureError; // Wiring for Intersema barometric pressure/temperature sensor TestMTS400M.IntersemaCal -> IntersemaPressure; TestMTS400M.PressureControl -> IntersemaPressure; TestMTS400M.IntersemaPressure -> IntersemaPressure.Pressure; TestMTS400M.IntersemaTemp -> IntersemaPressure.Temperature; // TestMTS400M.HumidityError -> SensirionHumidity.HumidityError; // TestMTS400M.TemperatureError -> SensirionHumidity.TemperatureError; TestMTS400M.Leds -> LedsC; TestMTS400M.Timer -> TimerC.Timer[unique("Timer")]; } --- NEW FILE: TestMTS400M.nc --- /* tab:4 * * * "Copyright (c) 2000-2002 The Regents of the University of California. * All rights reserved. * * Permission to use, copy, modify, and distribute this software and its * documentation for any purpose, without fee, and without written agreement is * hereby granted, provided that the above copyright notice, the following * two paragraphs and the author appear in all copies of this software. * * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS." * */ /* tab:4 * IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. By * downloading, copying, installing or using the software you agree to * this license. If you do not agree to this license, do not download, * install, copy or use the software. * * Intel Open Source License * * Copyright (c) 2002 Intel Corporation * All rights reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 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. * Neither the name of the Intel Corporation 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 COPYRIGHT HOLDERS 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 INTEL OR ITS * 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. * * */ /* History: created 1/25/2001 * * */ /* TestMTS350: - Tests Crossbow MTS350 sensor board for: gps, temperature, humidity, light, accel */ /****************************************************************************** * 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 *------------------------------------------------------------------------------ * Runs in one of two modes: * gps_active = TRUE : turns on gps and outputs messages; weather sensors not used * = FALSE: turns off gps ; measure weather sensors *------------------------------------------------------------------------------ * NOTE: * No real power strategy; just turns sensors on sequentially. * Should add BusArbitration routines, like mica2dotwb for better power control *****************************************************************************/ module TestMTS400M { provides interface StdControl; uses { //gps interface I2CSwitchCmds as GpsCmd; interface StdControl as GpsControl; interface BareSendMsg as GpsSend; interface ReceiveMsg as GpsReceive; //Accels interface StdControl as AccelControl; interface I2CSwitchCmds as AccelCmd; interface ADC as AccelX; interface ADC as AccelY; //Intersema interface SplitControl as PressureControl; //interface StdControl as PressureControl; interface ADC as IntersemaTemp; interface ADC as IntersemaPressure; interface Calibration as IntersemaCal; //Sensirion interface SplitControl as TempHumControl; interface ADC as Humidity; interface ADC as Temperature; interface ADCError as HumidityError; interface ADCError as TemperatureError; //Taos interface SplitControl as TaosControl; interface ADC as TaosCh0; interface ADC as TaosCh1; interface Timer; interface Leds; } } implementation { #include "SODebug.h" #include "gps.h" enum {START, BUSY, HUMIDITY_DONE, PRESSURE_DONE, LIGHT_DONE, ACCEL_DONE}; char count; uint16_t calibration[6]; uint16_t C1,C2,C3,C4,C5,C6; //intersema calibration coefficients uint16_t TaosData; uint16_t HumData; uint16_t PressureData; uint16_t AccelData; uint8_t state; bool gps_active; //true if gps is active command result_t StdControl.init() { gps_active = FALSE; //change to FALSE to measure weather sensors //gps_active = TRUE; TaosData = 0; init_debug(); call Leds.init(); call GpsControl.init(); // call GpsControl.start(); // call GpsCmd.PowerSwitch(0); //turn off GPS power, after reset it will be on. // call GpsControl.stop(); call TaosControl.init(); call AccelControl.init(); //initialize accelerometer call TempHumControl.init(); //init Sensirion call PressureControl.init(); // init Intersema return SUCCESS; } command result_t StdControl.start() { call HumidityError.enable(); //in case Sensirion doesn't respond call TemperatureError.enable(); // " if (gps_active){ call Leds.redOn(); call GpsControl.start(); SODbg(DBG_USR2, "Power GPS... \n"); if (! call GpsCmd.PowerSwitch(1)) { //turn on GPS power SODbg(DBG_USR2, "Failed to power on gps \n"); } } else{ call Leds.redOn(); call Leds.yellowOn(); call Leds.greenOn(); state = START; call Timer.start(TIMER_REPEAT, 500); //start up weather sensor measurements } return SUCCESS; } command result_t StdControl.stop() { return SUCCESS; } /****************************************************************************** * Timer fired, test GPS, humidity/temp * async for test only *****************************************************************************/ async event result_t Timer.fired() { call Leds.redOff(); call Leds.yellowOff(); call Leds.greenOff(); if ( state == ACCEL_DONE) state = START; if (state == START){ state = BUSY; call TempHumControl.start(); } if (state == HUMIDITY_DONE){ state = BUSY; call PressureControl.start(); } if (state == PRESSURE_DONE){ state = BUSY; call TaosControl.start(); } if (state == LIGHT_DONE){ state = BUSY; call AccelCmd.PowerSwitch(1); } return SUCCESS; } /****************************************************************************** * Packet received from GPS - ASCII msg * 1st byte in pkt is number of ascii bytes * async used only for testing *****************************************************************************/ async event TOS_MsgPtr GpsReceive.receive(TOS_MsgPtr data) { //change to GPS packet!! uint8_t i; GPS_MsgPtr gps_data = (GPS_MsgPtr)data; call Leds.greenToggle(); for (i = 0; i <= gps_data->data[0] ; i++) UARTPutChar(gps_data->data[i]); SODbg(DBG_USR2, "\n"); return data; } event result_t GpsSend.sendDone(TOS_MsgPtr msg, result_t success) { return SUCCESS; } event result_t GpsCmd.SwitchesSet(uint8_t PowerState){ gps_active = TRUE; SODbg(DBG_USR2, "Gps power on \n"); call Leds.yellowOn(); return SUCCESS; } /****************************************************************************** * Intersema MS5534A barometric pressure/temperature sensor * - 6 cal coefficients (C1..C6) are extracted from 4, 16 bit,words from sensor * - Temperature measurement: * UT1=8*C5+20224 * dT=data-UT1 * Temp=(degC x10)=200+dT(C6+50)/1024 * - Pressure measurement: * OFF=C2*4 + ((C4-512)*dT)/1024 * SENS=C1+(C3*dT)/1024 + 24576 * X=(SENS*(PressureData-7168))/16384 - OFF * Press(mbar)= X/32+250 *****************************************************************************/ event result_t IntersemaTemp.dataReady(uint16_t data) { float UT1,dT,Temp; float OFF,SENS,X,Press; //temperature UT1=8*(float)C5+20224; dT = (float)data-UT1; Temp = 200.0 + dT*((float)C6+50.0)/1024.0; //pressure OFF = (float)C2*4 + (((float)C4-512.0)*dT)/1024; SENS = (float)C1 + ((float)C3*dT)/1024 + 24576; X = (SENS*((float)PressureData-7168.0))/16384 - OFF; Press = X/32.0 + 250.0; SODbg(DBG_USR2, "Pressure: Temp(adc): %i Press(adc): %i Temp(degCx10): %i Press(mbar): %i \n", data,PressureData,(int)Temp, (int)Press); call PressureControl.stop(); return SUCCESS; } event result_t IntersemaPressure.dataReady(uint16_t data) { PressureData = data; return call IntersemaTemp.getData(); } event result_t IntersemaCal.dataReady(char word, uint16_t value) { // make sure we get all the calibration bytes count++; // SODbg(DBG_USR2, " cal word %i value %x \n",word,value); calibration[word-1] = value; if (count == 4) { SODbg(DBG_USR2, "Pressure cal words (1..4): %x,%x,%x,%x \n", calibration[0],calibration[1],calibration[2],calibration[3] ); C1 = calibration[0] >> 1; C2 = ((calibration[2] & 0x3f) << 6) | (calibration[3] & 0x3f); C3 = calibration[3] >> 6; C4 = calibration[2] >> 6; C5 = ((calibration[0] & 1) << 10) | (calibration[1] >> 6); C6 = calibration[1] & 0x3f; // SODbg(DBG_USR2, "Pressure C1:%x C2:%x C3:%x C4:%x C5:%x C6:%x \n", // C1,C2,C3,C4,C5,C6 ); SODbg(DBG_USR2, "Pressure C1:%i C2:%i C3:%i C4:%i C5:%i C6:%i \n", C1,C2,C3,C4,C5,C6 ); call IntersemaPressure.getData(); } return SUCCESS; } event result_t PressureControl.initDone() { return SUCCESS; } event result_t PressureControl.stopDone() { state = PRESSURE_DONE; return SUCCESS; } event result_t PressureControl.startDone() { count = 0; call IntersemaCal.getData(); return SUCCESS; } /****************************************************************************** * Sensirion SHT11 humidity/temperature sensor * - Humidity data is 12 bit: * Linear calc (no temp correction) * fRH = -4.0 + 0.0405 * data -0.0000028 * data^2 'RH linear * With temperature correction: * fRH = (fTemp - 25) * (0.01 + 0.00008 * data) + fRH 'RH true * - Temperature data is 14 bit * Temp(degC) = -38.4 + 0.0098 * data *****************************************************************************/ event result_t Temperature.dataReady(uint16_t data) { float fTemp, fHumidity; fTemp = -38.4 + 0.0098*(float)data; fHumidity = -4.0 + 0.0405 * HumData -0.0000028 * HumData * HumData; fHumidity= (fTemp-25.0)* (0.01 + 0.00008 * HumData) + fHumidity; fTemp = 10*fTemp; SODbg(DBG_USR2, "Humidity: Temp(adc): %i Humidity(adc): %i Temp(degCx10): %i Humidity(%): %i \n", data,HumData,(int)fTemp, (int)fHumidity); call TempHumControl.stop(); return SUCCESS; } event result_t Humidity.dataReady(uint16_t data) { HumData = data; //pressure data return call Temperature.getData(); } event result_t TempHumControl.startDone() { call Humidity.getData(); return SUCCESS; } event result_t TempHumControl.initDone() { return SUCCESS; } event result_t TempHumControl.stopDone() { state = HUMIDITY_DONE; return SUCCESS; } event result_t HumidityError.error(uint8_t token) { call Leds.redOff(); call Leds.yellowOff(); call Temperature.getData(); return SUCCESS; } event result_t TemperatureError.error(uint8_t token) { call TempHumControl.stop(); call Leds.yellowOff(); 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; ST1 = TaosData & 0xf; CH1 = (TaosData & 0x70) >> 4; CV1 = 1 << CH1; CNT1 = (int)(16.5*(CV1-1)) + ST1*CV1; ACNT0 = (int)CNT1; 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) { 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; } /****************************************************************************** * ADXL202E Accelerometer * At 3.0 supply this sensor's sensitivty is ~167mv/g * 0 g is at ~1.5V or ~VCC/2 - this varies alot. * For an accurate calibration measure each axis at +/- 1 g and * compute the center point (0 g level) as 1/2 of difference. * Note: this app doesn't measure the battery voltage, it assumes 3.2 volts * To getter better accuracy measure the battery voltage as this effects the * full scale of the Atmega128 ADC. * bits/mv = 1024/(1000*VBATT) * bits/g = 1024/(1000*VBATT)(bits/mv) * 167(mv/g) * = 171/VBATT (bits/g) * C = 0.171/VBATT (bits/mg) * Accel(mg) ~ (ADC DATA - 512) /C *****************************************************************************/ event result_t AccelY.dataReady(uint16_t data){ float Accel, C; float VBATT = 3.2; C = 0.171/VBATT; Accel = ((float)AccelData - 512.0)/C; SODbg(DBG_BOOT, "AccelX data %i AcceX(mg) %i \n",AccelData, (int)Accel); Accel = ((float)data - 512.0)/C; SODbg(DBG_BOOT, "AccelY data %i AcceY(mg) %i \n",data, (int)Accel); call AccelCmd.PowerSwitch(0); //power off return SUCCESS; } event result_t AccelX.dataReady(uint16_t data){ AccelData = data; // SODbg(DBG_BOOT, "AccelX data %i \n",AccelData); call AccelY.getData(); return SUCCESS; } event result_t AccelCmd.SwitchesSet(uint8_t PowerState){ //power on/off //SODbg(DBG_BOOT, "Accel switch set %i \n",PowerState); if (PowerState) call AccelX.getData(); //start measuring X accel axis else state = ACCEL_DONE; return SUCCESS; } } |