00001 /*! \file WaspSensorAgr.h 00002 \brief Library for managing the Agriculture Sensor Board 00003 00004 Copyright (C) 2009 Libelium Comunicaciones Distribuidas S.L. 00005 http://www.libelium.com 00006 00007 This program is free software: you can redistribute it and/or modify 00008 it under the terms of the GNU Lesser General Public License as published by 00009 the Free Software Foundation, either version 2.1 of the License, or 00010 (at your option) any later version. 00011 00012 This program is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU Lesser General Public License for more details. 00016 00017 You should have received a copy of the GNU Lesser General Public License 00018 along with this program. If not, see <http://www.gnu.org/licenses/>. 00019 00020 Version: 0.1 00021 00022 Design: David Gascón 00023 00024 Implementation: Alberto Bielsa, Manuel Calahorra 00025 00026 */ 00027 00028 /*! \def WaspSensorAgr_h 00029 \brief The library flag 00030 00031 */ 00032 #ifndef WaspSensorAgr_h 00033 #define WaspSensorAgr_h 00034 00035 /****************************************************************************** 00036 * Includes 00037 ******************************************************************************/ 00038 00039 #include <inttypes.h> 00040 00041 /****************************************************************************** 00042 * Definitions & Declarations 00043 ******************************************************************************/ 00044 00045 /*! \def SENS_AGR_PLUVIOMETER 00046 \brief Sensor types. Pluviometer sensor in this case (two sensors may be connected to this socket) 00047 00048 */ 00049 /*! \def SENS_AGR_ANEMOMETER 00050 \brief Sensor types. Anemometer sensor in this case 00051 00052 */ 00053 /*! \def SENS_AGR_WATERMARK_1 00054 \brief Sensor types. Watermark sensor in this case 00055 00056 */ 00057 /*! \def SENS_AGR_WATERMARK_2 00058 \brief Sensor types. Watermark sensor in this case 00059 00060 */ 00061 /*! \def SENS_AGR_WATERMARK_3 00062 \brief Sensor types. Watermark sensor in this case 00063 00064 */ 00065 /*! \def SENS_AGR_VANE 00066 \brief Sensor types. Vane sensor in this case 00067 00068 */ 00069 /*! \def SENS_AGR_DENDROMETER 00070 \brief Sensor types. Dendrometer sensor in this case 00071 00072 */ 00073 /*! \def SENS_AGR_PT1000 00074 \brief Sensor types. PT1000 sensor in this case 00075 00076 */ 00077 /*! \def SENS_AGR_LEAF_WETNESS 00078 \brief Sensor types. Leaf wetness sensor in this case 00079 00080 */ 00081 /*! \def SENS_AGR_TEMPERATURE 00082 \brief Sensor types. Temperature sensor in this case 00083 00084 */ 00085 /*! \def SENS_AGR_HUMIDITY 00086 \brief Sensor types. Humidity sensor in this case 00087 00088 */ 00089 /*! \def SENS_AGR_RADIATION 00090 \brief Sensor types. Sun radiation sensor in this case (two sensors may be connected to this socket) 00091 00092 */ 00093 /*! \def SENS_AGR_SENSIRION 00094 \brief Sensor types. Sensirion sensor in this case (two sensors may be connected to this socket) 00095 00096 */ 00097 /*! \def SENS_AGR_PRESSURE 00098 \brief Sensor types. Pressure sensor in this case 00099 00100 */ 00101 00102 #define SENS_AGR_PLUVIOMETER 16 00103 #define SENS_AGR_ANEMOMETER 1 00104 #define SENS_AGR_WATERMARK_1 2 00105 #define SENS_AGR_WATERMARK_2 4 00106 #define SENS_AGR_WATERMARK_3 8 00107 #define SENS_AGR_VANE 0 00108 #define SENS_AGR_DENDROMETER 32 00109 #define SENS_AGR_PT1000 64 00110 #define SENS_AGR_LEAF_WETNESS 128 00111 #define SENS_AGR_TEMPERATURE 256 00112 #define SENS_AGR_HUMIDITY 512 00113 #define SENS_AGR_RADIATION 1024 00114 #define SENS_AGR_SENSIRION 2048 00115 #define SENS_AGR_PRESSURE 4096 00116 00117 00118 /*! \def SENS_SWITCH_1 00119 \brief Switches for powering the sensors 00120 00121 */ 00122 /*! \def SENS_SWITCH_2 00123 \brief Switches for powering the sensors 00124 00125 */ 00126 /*! \def SENS_SWITCH_3 00127 \brief Switches for powering the sensors 00128 00129 */ 00130 /*! \def SENS_SWITCH_4 00131 \brief Switches for powering the sensors 00132 00133 */ 00134 /*! \def SENS_MUX_SEL 00135 \brief Sensor multiplexer selector 00136 00137 */ 00138 #define SENS_SWITCH_1 DIGITAL7 00139 #define SENS_SWITCH_2 DIGITAL1 00140 #define SENS_SWITCH_3 ANA0 00141 #define SENS_SWITCH_4 DIGITAL5 00142 #define SENS_MUX_SEL DIGITAL3 00143 00144 00145 /*! \def SENS_CLK 00146 \brief Sensirion CLK pin 00147 00148 */ 00149 /*! \def SENS_DATA 00150 \brief Sensirion CLK data 00151 00152 */ 00153 /*! \def SENS_PREC_HIGH 00154 \brief Sensirion High Precision 00155 00156 */ 00157 /*! \def SENS_PREC_LOW 00158 \brief Sensirion Low Precision 00159 00160 */ 00161 /*! \def SENSIRION_TEMP 00162 \brief Sensirion Temperature 00163 00164 */ 00165 /*! \def SENSIRION_HUM 00166 \brief Sensirion Humidity 00167 00168 */ 00169 #define SENS_CLK DIGITAL8 00170 #define SENS_DATA DIGITAL6 00171 #define SENS_PREC_HIGH 1 00172 #define SENS_PREC_LOW 0 00173 #define SENSIRION_TEMP 0 00174 #define SENSIRION_HUM 1 00175 00176 00177 /*! \def SENS_AGR_VANE_N 00178 \brief Vane : North Direction 00179 00180 */ 00181 /*! \def SENS_AGR_VANE_NNE 00182 \brief Vane : North-NorthEast Direction 00183 00184 */ 00185 /*! \def SENS_AGR_VANE_NE 00186 \brief Vane : NorthEast Direction 00187 00188 */ 00189 /*! \def SENS_AGR_VANE_ENE 00190 \brief Vane : East-NorthEast Direction 00191 00192 */ 00193 /*! \def SENS_AGR_VANE_E 00194 \brief Vane : East Direction 00195 00196 */ 00197 /*! \def SENS_AGR_VANE_ESE 00198 \brief Vane : East-SouthEast Direction 00199 00200 */ 00201 /*! \def SENS_AGR_VANE_SE 00202 \brief Vane : SouthEast Direction 00203 00204 */ 00205 /*! \def SENS_AGR_VANE_SSE 00206 \brief Vane : South-SouthEast Direction 00207 00208 */ 00209 /*! \def SENS_AGR_VANE_S 00210 \brief Vane : South Direction 00211 00212 */ 00213 /*! \def SENS_AGR_VANE_SSW 00214 \brief Vane : South-SouthWest Direction 00215 00216 */ 00217 /*! \def SENS_AGR_VANE_SW 00218 \brief Vane : SouthWest Direction 00219 00220 */ 00221 /*! \def SENS_AGR_VANE_WSW 00222 \brief Vane : West-SouthWest Direction 00223 00224 */ 00225 /*! \def SENS_AGR_VANE_W 00226 \brief Vane : West Direction 00227 00228 */ 00229 /*! \def SENS_AGR_VANE_WNW 00230 \brief Vane : West-Northwest Direction 00231 00232 */ 00233 /*! \def SENS_AGR_VANE_NW 00234 \brief Vane : NorthWest Direction 00235 00236 */ 00237 /*! \def SENS_AGR_VANE_NNW 00238 \brief Vane : North-NorthWest Direction 00239 00240 */ 00241 #define SENS_AGR_VANE_N 0 00242 #define SENS_AGR_VANE_NNE 1 00243 #define SENS_AGR_VANE_NE 2 00244 #define SENS_AGR_VANE_ENE 4 00245 #define SENS_AGR_VANE_E 8 00246 #define SENS_AGR_VANE_ESE 16 00247 #define SENS_AGR_VANE_SE 32 00248 #define SENS_AGR_VANE_SSE 64 00249 #define SENS_AGR_VANE_S 128 00250 #define SENS_AGR_VANE_SSW 256 00251 #define SENS_AGR_VANE_SW 512 00252 #define SENS_AGR_VANE_WSW 1024 00253 #define SENS_AGR_VANE_W 2048 00254 #define SENS_AGR_VANE_WNW 4096 00255 #define SENS_AGR_VANE_NW 8192 00256 #define SENS_AGR_VANE_NNW 16384 00257 00258 00259 /****************************************************************************** 00260 * Class 00261 ******************************************************************************/ 00262 00263 //! WaspSensorAgr Class 00264 /*! 00265 WaspSensorAgr Class defines all the variables and functions used for managing the Agriculture Sensor Board 00266 */ 00267 class WaspSensorAgr 00268 { 00269 private: 00270 00271 //! It sets the Digipot threshold 00272 /*! 00273 \param uint8_t value : threshold 00274 \return void 00275 */ 00276 void setDigipot(float value); 00277 00278 //! It reads from the dendrometer 00279 /*! 00280 \return the value returned by the sensor 00281 */ 00282 float readDendrometer(); 00283 00284 //! It reads from the PT1000 00285 /*! 00286 \return the value returned by the sensor 00287 */ 00288 float readPT1000(); 00289 00290 //! It reads from the radiation sensors 00291 /*! 00292 \return the value returned by the sensor 00293 */ 00294 float readRadiation(); 00295 00296 //! It reads from the Watermark 00297 /*! 00298 \param uint8_t sens : the Watermark on use 00299 \return the value returned by the sensor 00300 */ 00301 float readWatermark(uint8_t sens); 00302 00303 //! It reads from the sensirion 00304 /*! 00305 \param uint8_t parameter : TEMPERATURE or HUMIDITY 00306 \return the value returned by the sensor 00307 */ 00308 float readSensirion(uint8_t parameter); 00309 00310 //! It reads from the pluviometer 00311 /*! 00312 \return the value returned by the sensor 00313 */ 00314 uint16_t readPluviometer(); 00315 00316 //! It converts data 00317 /*! 00318 \param byte data_input : the data to convert 00319 \param uint8_t type : temperature(1) or dendrometer(0) 00320 \return the value converted 00321 */ 00322 float conversion(byte data_input[3], uint8_t type); 00323 00324 //! It converts pressure 00325 /*! 00326 \param int readValue : the data to convert 00327 \return the value converted 00328 */ 00329 float pressure_conversion(int readValue); 00330 00331 //! It converts leaf wetness 00332 /*! 00333 \param int readValue : the data to convert 00334 \return the value converted 00335 */ 00336 float lws_conversion(int readValue); 00337 00338 //! It converts humidity 00339 /*! 00340 \param int readValue : the data to convert 00341 \return the value converted 00342 */ 00343 float humidity_conversion(int readValue); 00344 00345 //! It converts temperature 00346 /*! 00347 \param int readValue : the data to convert 00348 \return the value converted 00349 */ 00350 float temperature_conversion(int readValue); 00351 00352 //! It gets the direction of the wind 00353 /*! 00354 \param float vane : the voltage got from the vane 00355 \return nothing 00356 */ 00357 void getVaneDirection(float vane); 00358 00359 //! It converts the temperature returned by sensirion 00360 /*! 00361 \param int readValue : value returned by sensirion 00362 \param int precision : precission bits 00363 \return the converted value 00364 */ 00365 float temperature_conversion(int readValue, int precision); 00366 00367 //! It converts the humidity returned by sensirion 00368 /*! 00369 \param int readValue : value returned by sensirion 00370 \param int precision : precission bits 00371 \return the converted value 00372 */ 00373 float humidity_conversion(int readValue, int precision); 00374 00375 //! It converts the humidity returned by sencera 00376 /*! 00377 \param int readValue : value returned by sencera 00378 \return the converted value 00379 */ 00380 float sencera_conversion(int readValue); 00381 00382 //! It converts the temperature returned by mcp 00383 /*! 00384 \param int readValue : value returned by mcp 00385 \return the converted value 00386 */ 00387 float mcp_conversion(int readValue); 00388 00389 public: 00390 00391 //! Variable : specifies the wind direction 00392 /*! 00393 */ 00394 uint16_t vane_direction; 00395 00396 //! class constructor 00397 /*! 00398 It initializes the different digital pins 00399 \param void 00400 \return void 00401 */ 00402 WaspSensorAgr(); 00403 00404 //! It sets board power mode, setting ON/OFF 3v3 and 5V switches 00405 /*! 00406 \param uint8_t mode : SENS_ON or SENS_OFF 00407 \return void 00408 */ 00409 void setBoardMode(uint8_t mode); 00410 00411 //! It sets ON/OFF the different sensor switches 00412 /*! 00413 \param uint8_t mode : SENS_ON or SENS_OFF 00414 \param uint16_t sensor : the sensor to set ON/OFF 00415 \return void 00416 */ 00417 void setSensorMode(uint8_t mode, uint16_t sensor); 00418 00419 //! It reads the value measured by the sensor 00420 /*! 00421 \param uint16_t sensor : the sensor to read the value from 00422 \return the value measured by the sensor (range [0-3.3] Volts) 00423 */ 00424 float readValue(uint16_t sensor); 00425 00426 //! It reads the value measured by the sensor 00427 /*! 00428 \param uint16_t sensor : the sensor to read the value from 00429 \param uint8_t type : the type to read 00430 \return the value measured by the sensor (range [0-3.3] Volts) 00431 */ 00432 float readValue(uint16_t sensor, uint8_t type); 00433 00434 //! It sets threshold configuring digipots 00435 /*! 00436 \param uint8_t sensor : specifies the socket to set the threshold to ('SENS_SOCKETX') 00437 \param float threshold : the threshold to set (0-3.3V) 00438 \return void 00439 */ 00440 void setAnemometerThreshold(float threshold); 00441 00442 //! It sleeps Waspmote enabling the switches required for the agriculture board 00443 /*! 00444 \param const char* time2wake : string that indicates the time to wake up. It looks like "dd:hh:mm:ss" 00445 \param uint8_t offset : RTC_OFFSET or RTC_ABSOLUTE 00446 \param uint8_t mode : RTC_ALM1_MODE1, RTC_ALM1_MODE2, RTC_ALM1_MODE3, RTC_ALM1_MODE4 or RTC_ALM1_MODE5 00447 \param uint8_t option : ALL_OFF, SENS_OFF, UART0_OFF, UART1_OFF, BAT_OFF or RTC_OFF 00448 \return void 00449 */ 00450 void sleepAgr(const char* time2wake, uint8_t offset, uint8_t mode, uint8_t option); 00451 00452 //! It sleeps Waspmote enabling the switches required for the agriculture board 00453 /*! 00454 \param const char* time2wake : string that indicates the time to wake up. It looks like "dd:hh:mm:ss" 00455 \param uint8_t offset : RTC_OFFSET or RTC_ABSOLUTE 00456 \param uint8_t mode : RTC_ALM1_MODE1, RTC_ALM1_MODE2, RTC_ALM1_MODE3, RTC_ALM1_MODE4 or RTC_ALM1_MODE5 00457 \param uint8_t option : ALL_OFF, SENS_OFF, UART0_OFF, UART1_OFF, BAT_OFF or RTC_OFF 00458 \param uint8_t agr_interrupt : specifies the sensor we are enabling before going sleep (Anemometer and Pluviometer) 00459 \return void 00460 */ 00461 void sleepAgr(const char* time2wake, uint8_t offset, uint8_t mode, uint8_t option, uint8_t agr_interrupt); 00462 00463 //! It switches off the general switch enabling RTC interruption for the Agriculture Board 00464 /*! 00465 \param const char* time2wake : string that indicates the time to wake up. It looks like "dd:hh:mm:ss" 00466 \param uint8_t offset : RTC_OFFSET or RTC_ABSOLUTE 00467 \param uint8_t mode : RTC_ALM1_MODE1, RTC_ALM1_MODE2, RTC_ALM1_MODE3, RTC_ALM1_MODE4 or RTC_ALM1_MODE5 00468 \return void 00469 \sa sleep(uint8_t option), sleep(uint8_t timer, uint8_t option), deepSleep(const char* time2wake, uint8_t offset, uint8_t mode, uint8_t option) 00470 */ 00471 void attachInt(uint8_t sens); 00472 00473 //! It attaches the interruption 00474 /*! 00475 \param uint8_t sens: specifies the sensor (ANEMOMETER or PLUVIOMETER) which detaches the interruption 00476 \return void 00477 */ 00478 void detachInt(uint8_t sens); 00479 }; 00480 00481 extern WaspSensorAgr SensorAgr; 00482 00483 #endif 00484
1.5.6