--- /dev/null
+/*
+ * 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 <rsmckown@gmail.com>
+ */
+
+#include "AeroVane.h"
+
+configuration AeroVaneC {
+ provides interface ReadRef<aerovane_t>;
+}
+implementation {
+ components AeroVaneP;
+ ReadRef = AeroVaneP;
+
+ components SoftwareRtcC as RtcC;
+ AeroVaneP.Second -> RtcC;
+
+ components HalAeroVaneC;
+ AeroVaneP.CPSA -> HalAeroVaneC.CPSA;
+ AeroVaneP.CPSB -> HalAeroVaneC.CPSB;
+}
--- /dev/null
+/*
+ * 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 <rsmckown@gmail.com>
+ */
+
+#include "AeroVane.h"
+
+module AeroVaneP {
+ provides interface ReadRef<aerovane_t>;
+ uses {
+ interface Tick as Second;
+ interface AsyncGet<uint8_t> as CPSA;
+ interface AsyncGet<uint8_t> 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);
+ }
+}