Library for interfacing to Sparkfun Weather Meters.
Dependents: WeatherStation Deneme testgeneral ... more
WeatherMeters.h@0:457832d52954, 2012-02-25 (annotated)
- Committer:
- AdamGreen
- Date:
- Sat Feb 25 03:23:51 2012 +0000
- Revision:
- 0:457832d52954
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
AdamGreen | 0:457832d52954 | 1 | /* Copyright 2012 Adam Green (http://mbed.org/users/AdamGreen/) |
AdamGreen | 0:457832d52954 | 2 | |
AdamGreen | 0:457832d52954 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); |
AdamGreen | 0:457832d52954 | 4 | you may not use this file except in compliance with the License. |
AdamGreen | 0:457832d52954 | 5 | You may obtain a copy of the License at |
AdamGreen | 0:457832d52954 | 6 | |
AdamGreen | 0:457832d52954 | 7 | http://www.apache.org/licenses/LICENSE-2.0 |
AdamGreen | 0:457832d52954 | 8 | |
AdamGreen | 0:457832d52954 | 9 | Unless required by applicable law or agreed to in writing, software |
AdamGreen | 0:457832d52954 | 10 | distributed under the License is distributed on an "AS IS" BASIS, |
AdamGreen | 0:457832d52954 | 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
AdamGreen | 0:457832d52954 | 12 | See the License for the specific language governing permissions and |
AdamGreen | 0:457832d52954 | 13 | limitations under the License. |
AdamGreen | 0:457832d52954 | 14 | */ |
AdamGreen | 0:457832d52954 | 15 | /* Header file for class to interface with Sparkfun Weather Meters: |
AdamGreen | 0:457832d52954 | 16 | http://www.sparkfun.com/products/8942 |
AdamGreen | 0:457832d52954 | 17 | */ |
AdamGreen | 0:457832d52954 | 18 | #ifndef _WEATHER_METERS_H_ |
AdamGreen | 0:457832d52954 | 19 | #define _WEATHER_METERS_H_ |
AdamGreen | 0:457832d52954 | 20 | |
AdamGreen | 0:457832d52954 | 21 | #include "WindVane.h" |
AdamGreen | 0:457832d52954 | 22 | #include "RainGauge.h" |
AdamGreen | 0:457832d52954 | 23 | #include "Anemometer.h" |
AdamGreen | 0:457832d52954 | 24 | |
AdamGreen | 0:457832d52954 | 25 | |
AdamGreen | 0:457832d52954 | 26 | namespace AFP |
AdamGreen | 0:457832d52954 | 27 | { |
AdamGreen | 0:457832d52954 | 28 | |
AdamGreen | 0:457832d52954 | 29 | /** A class to interface with the Sparkfun Weather Meters. |
AdamGreen | 0:457832d52954 | 30 | http://www.sparkfun.com/products/8942 |
AdamGreen | 0:457832d52954 | 31 | |
AdamGreen | 0:457832d52954 | 32 | This set of weather meters from Sparkfun includes anemometer (wind speed), |
AdamGreen | 0:457832d52954 | 33 | wind vane, and rain gauge. All of the sensors use reed switches so that |
AdamGreen | 0:457832d52954 | 34 | the electronics can detect motion/location in the sensor hardware via |
AdamGreen | 0:457832d52954 | 35 | magnets placed in the sensors without actually exposing the electonic |
AdamGreen | 0:457832d52954 | 36 | switches themselves to the elements. A reed switch closes as the |
AdamGreen | 0:457832d52954 | 37 | anemometer spins and the rain gauge empties. The wind vane includes |
AdamGreen | 0:457832d52954 | 38 | 8 reed switches, each with a different valued resistor attached so that |
AdamGreen | 0:457832d52954 | 39 | the voltage will vary depending on where the magnet in the vane is |
AdamGreen | 0:457832d52954 | 40 | located. |
AdamGreen | 0:457832d52954 | 41 | * Example: |
AdamGreen | 0:457832d52954 | 42 | * @code |
AdamGreen | 0:457832d52954 | 43 | #include <mbed.h> |
AdamGreen | 0:457832d52954 | 44 | #include "WeatherMeters.h" |
AdamGreen | 0:457832d52954 | 45 | |
AdamGreen | 0:457832d52954 | 46 | int main() |
AdamGreen | 0:457832d52954 | 47 | { |
AdamGreen | 0:457832d52954 | 48 | CWeatherMeters WeatherMeters(p9, p10, p15); |
AdamGreen | 0:457832d52954 | 49 | for (;;) |
AdamGreen | 0:457832d52954 | 50 | { |
AdamGreen | 0:457832d52954 | 51 | CWeatherMeters::SMeasurements Measurements; |
AdamGreen | 0:457832d52954 | 52 | |
AdamGreen | 0:457832d52954 | 53 | WeatherMeters.GetMeasurements(&Measurements); |
AdamGreen | 0:457832d52954 | 54 | |
AdamGreen | 0:457832d52954 | 55 | printf("Direction: %s\n", Measurements.WindDirectionString); |
AdamGreen | 0:457832d52954 | 56 | printf("Depth: %f\n",Measurements.Rainfall); |
AdamGreen | 0:457832d52954 | 57 | printf("Current speed: %f\n", Measurements.WindSpeed); |
AdamGreen | 0:457832d52954 | 58 | printf("Maximum speed: %f\n", Measurements.MaximumWindSpeed); |
AdamGreen | 0:457832d52954 | 59 | |
AdamGreen | 0:457832d52954 | 60 | wait(1.0f); |
AdamGreen | 0:457832d52954 | 61 | } |
AdamGreen | 0:457832d52954 | 62 | } |
AdamGreen | 0:457832d52954 | 63 | * @endcode |
AdamGreen | 0:457832d52954 | 64 | */ |
AdamGreen | 0:457832d52954 | 65 | class CWeatherMeters |
AdamGreen | 0:457832d52954 | 66 | { |
AdamGreen | 0:457832d52954 | 67 | protected: |
AdamGreen | 0:457832d52954 | 68 | CAnemometer m_Anemometer; |
AdamGreen | 0:457832d52954 | 69 | CRainGauge m_RainGauge; |
AdamGreen | 0:457832d52954 | 70 | CWindVane m_WindVane; |
AdamGreen | 0:457832d52954 | 71 | |
AdamGreen | 0:457832d52954 | 72 | public: |
AdamGreen | 0:457832d52954 | 73 | /** A structure in which the current measurements registered by the weather |
AdamGreen | 0:457832d52954 | 74 | meters are returned from the GetMeasurements() method. |
AdamGreen | 0:457832d52954 | 75 | */ |
AdamGreen | 0:457832d52954 | 76 | struct SMeasurements |
AdamGreen | 0:457832d52954 | 77 | { |
AdamGreen | 0:457832d52954 | 78 | const char* WindDirectionString; /**< String representing current wind direction. Example: "North" */ |
AdamGreen | 0:457832d52954 | 79 | float WindDirectionAngle; /**< Wind direction in degrees from north. */ |
AdamGreen | 0:457832d52954 | 80 | float WindSpeed; /**< Current wind speed in km/hour. */ |
AdamGreen | 0:457832d52954 | 81 | float MaximumWindSpeed; /**< Maximum wind speed measured since last reset. Measured in km/hour. */ |
AdamGreen | 0:457832d52954 | 82 | float Rainfall; /**< Amount of rainfall since last reset. Measured in mm. */ |
AdamGreen | 0:457832d52954 | 83 | }; |
AdamGreen | 0:457832d52954 | 84 | |
AdamGreen | 0:457832d52954 | 85 | /** Create a CWeatherMeters object, binds it to the specified input pins, |
AdamGreen | 0:457832d52954 | 86 | and initializes the required interrupt handlers. |
AdamGreen | 0:457832d52954 | 87 | |
AdamGreen | 0:457832d52954 | 88 | @param AnemometerPin The mbed pin which is connected to the anemometer |
AdamGreen | 0:457832d52954 | 89 | sensor. Must be a pin on which the mbed supports InterruptIn. |
AdamGreen | 0:457832d52954 | 90 | @param RainGauagePin The mbed pin which is connected to the rain gauge |
AdamGreen | 0:457832d52954 | 91 | sensor. Must be a pin on which the mbed supports InterruptIn. |
AdamGreen | 0:457832d52954 | 92 | @param WindVanePin The mbed pin which is connected to the wind vane |
AdamGreen | 0:457832d52954 | 93 | sensor. Must be a pin on which the mbed supports AnalogIn. |
AdamGreen | 0:457832d52954 | 94 | @param WindVaneSeriesResistance The value of the resistance which is |
AdamGreen | 0:457832d52954 | 95 | in series with the wind vane sensor and along with the |
AdamGreen | 0:457832d52954 | 96 | varying resistance of the wind vane sensor itself, acts as a |
AdamGreen | 0:457832d52954 | 97 | voltage divider. |
AdamGreen | 0:457832d52954 | 98 | */ |
AdamGreen | 0:457832d52954 | 99 | CWeatherMeters(PinName AnemometerPin, |
AdamGreen | 0:457832d52954 | 100 | PinName RainGaugePin, |
AdamGreen | 0:457832d52954 | 101 | PinName WindVanePin, |
AdamGreen | 0:457832d52954 | 102 | float WindVaneSeriesResistance = 10000.0f); |
AdamGreen | 0:457832d52954 | 103 | |
AdamGreen | 0:457832d52954 | 104 | /** Gets current weather meter measurements. |
AdamGreen | 0:457832d52954 | 105 | |
AdamGreen | 0:457832d52954 | 106 | NOTE: Should call this method on a regular basis (every 15 minutes or |
AdamGreen | 0:457832d52954 | 107 | less) to keep internal timers from overflowing. |
AdamGreen | 0:457832d52954 | 108 | |
AdamGreen | 0:457832d52954 | 109 | @param pMeasurements points to the measurement structure to be filled in |
AdamGreen | 0:457832d52954 | 110 | with the current measurement from the sensors. The historical |
AdamGreen | 0:457832d52954 | 111 | values in this structure such as rainfall and maximum wind |
AdamGreen | 0:457832d52954 | 112 | speed can be reset by calls to ResetRainfall(), |
AdamGreen | 0:457832d52954 | 113 | ResetMaximumWindSpeed(), and Reset(). |
AdamGreen | 0:457832d52954 | 114 | */ |
AdamGreen | 0:457832d52954 | 115 | void GetMeasurements(SMeasurements* pMeasurements); |
AdamGreen | 0:457832d52954 | 116 | |
AdamGreen | 0:457832d52954 | 117 | /** Resets all historical measurements: rainfall and maximum wind speed. */ |
AdamGreen | 0:457832d52954 | 118 | void Reset(); |
AdamGreen | 0:457832d52954 | 119 | |
AdamGreen | 0:457832d52954 | 120 | /** Resets the cumulative rainfall measurement. */ |
AdamGreen | 0:457832d52954 | 121 | void ResetRainfall(); |
AdamGreen | 0:457832d52954 | 122 | |
AdamGreen | 0:457832d52954 | 123 | /** Resets the maximum wind speed measurement. */ |
AdamGreen | 0:457832d52954 | 124 | void ResetMaximumWindSpeed(); |
AdamGreen | 0:457832d52954 | 125 | }; |
AdamGreen | 0:457832d52954 | 126 | |
AdamGreen | 0:457832d52954 | 127 | } // namespace AFP |
AdamGreen | 0:457832d52954 | 128 | using namespace AFP; |
AdamGreen | 0:457832d52954 | 129 | |
AdamGreen | 0:457832d52954 | 130 | #endif // _WEATHER_METERS_H_ |