From: smckown Date: Sat, 7 Nov 2009 23:59:04 +0000 (+0000) Subject: May or may not use these X-Git-Tag: release/2.1.0-2~15 X-Git-Url: https://oss.titaniummirror.com/gitweb/?p=tinyos-2.x.git;a=commitdiff_plain;h=8355da388aa1b904782e436ceead8254f852107f May or may not use these --- diff --git a/tos/platforms/tmirws/sensors/AeroVaneC.nc b/tos/platforms/tmirws/sensors/AeroVaneC.nc new file mode 100644 index 00000000..020b1369 --- /dev/null +++ b/tos/platforms/tmirws/sensors/AeroVaneC.nc @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2008, Titanium Mirror, Inc. + * 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 Titanium Mirror, Inc. 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 COPYRIGHT + * OWNER 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. + */ + +/** + * Aerovane sensor, measuring wind speed and direction + * + * @author R. Steve McKown + */ + +#include "AeroVane.h" + +configuration AeroVaneC { + provides interface ReadRef; +} +implementation { + components AeroVaneP; + ReadRef = AeroVaneP; + + components SoftwareRtcC as RtcC; + AeroVaneP.Second -> RtcC; + + components HalAeroVaneC; + AeroVaneP.CPSA -> HalAeroVaneC.CPSA; + AeroVaneP.CPSB -> HalAeroVaneC.CPSB; +} diff --git a/tos/platforms/tmirws/sensors/AeroVaneP.nc b/tos/platforms/tmirws/sensors/AeroVaneP.nc new file mode 100644 index 00000000..7c127267 --- /dev/null +++ b/tos/platforms/tmirws/sensors/AeroVaneP.nc @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2008, Titanium Mirror, Inc. + * 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 Titanium Mirror, Inc. 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 COPYRIGHT + * OWNER 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. + */ + +/** + * Aerovane sensor, measuring wind speed and direction + * + * @author R. Steve McKown + */ + +#include "AeroVane.h" + +module AeroVaneP { + provides interface ReadRef; + uses { + interface Tick as Second; + interface AsyncGet as CPSA; + interface AsyncGet as CPSB; + } +} +implementation { + aerovane_t* m_data; + uint8_t minSpeed = 255; + uint8_t maxSpeed; + + + /*** Support functions ***/ + + + /* Convert counts per second to mph */ + uint8_t toMph(uint8_t cps) + { + return 2.25 * cps + 0.5; + } + + + /*** Method implementations ***/ + + + async event void Second.fired() + { + uint8_t speed = call CPSA.get(); + + if (speed < minSpeed) + minSpeed = speed; + if (speed > maxSpeed) + maxSpeed = speed; + } + + task void readSpeed(); + + command error_t ReadRef.read(aerovane_t* data) + { + if (!data) + return EINVAL; + else if (m_data) + return EBUSY; + else { + m_data = data; + post readSpeed(); + return SUCCESS; + } + } + + void signalDone(error_t); + + task void readSpeed() + { + atomic { + m_data->min = toMph(minSpeed); + m_data->avg = toMph(call CPSB.get()); + m_data->max = toMph(maxSpeed); + minSpeed = 255; + maxSpeed = 0; + } + signalDone(SUCCESS); + } + + void signalDone(error_t error) + { + aerovane_t* tmp = m_data; + + m_data = 0; + signal ReadRef.readDone(error, tmp); + } +}