00001 /*! \file WaspSensorEvent.h 00002 \brief Library for managing the Gas 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 WaspSensorGas_h 00029 \brief The library flag 00030 00031 */ 00032 #ifndef WaspSensorGas_h 00033 #define WaspSensorGas_h 00034 00035 /****************************************************************************** 00036 * Includes 00037 ******************************************************************************/ 00038 00039 #include <inttypes.h> 00040 00041 /****************************************************************************** 00042 * Definitions & Declarations 00043 ******************************************************************************/ 00044 00045 /*! \def SENS_ON 00046 \brief Sensor Board Power Modes. ON in this case 00047 00048 */ 00049 /*! \def SENS_OFF 00050 \brief Sensor Board Power Modes. OFF in this case 00051 00052 */ 00053 #define SENS_ON 0 00054 #define SENS_OFF 1 00055 00056 00057 /*! \def SENS_3V3 00058 \brief Sensor Board Types. 3V3 switch in this case 00059 00060 */ 00061 /*! \def SENS_5V 00062 \brief Sensor Board Types. 5V switch in this case 00063 00064 */ 00065 #define SENS_3V3 0 00066 #define SENS_5V 1 00067 00068 00069 /*! \def SENS_TEMPERATURE 00070 \brief Sensor types. Temperature sensor in this case 00071 00072 */ 00073 /*! \def SENS_HUMIDITY 00074 \brief Sensor types. Humidity sensor in this case 00075 00076 */ 00077 /*! \def SENS_PRESSURE 00078 \brief Sensor types. Pressure sensor in this case 00079 00080 */ 00081 /*! \def SENS_CO2 00082 \brief Sensor types. CO2 sensor in this case 00083 00084 */ 00085 /*! \def SENS_O2 00086 \brief Sensor types. O2 sensor in this case 00087 00088 */ 00089 /*! \def SENS_SOCKET2A 00090 \brief Sensor types. Socket2A sensor in this case (many sensors can be connected to this socket) 00091 00092 */ 00093 /*! \def SENS_NO2 00094 \brief Sensor types. NO2 sensor in this case 00095 00096 */ 00097 /*! \def SENS_SOCKET3A 00098 \brief Sensor types. Socket3A sensor in this case (many sensors can be connected to this socket) 00099 00100 */ 00101 /*! \def SENS_SOCKET3B 00102 \brief Sensor types. Socket3B sensor in this case (many sensors can be connected to this socket) 00103 00104 */ 00105 /*! \def SENS_SOCKET3C 00106 \brief Sensor types. Socket3C sensor in this case (many sensors can be connected to this socket) 00107 00108 */ 00109 /*! \def SENS_SOCKET4A 00110 \brief Sensor types. Socket4A sensor in this case (many sensors can be connected to this socket) 00111 00112 */ 00113 /*! \def SENS_SOCKET4B 00114 \brief Sensor types. Socket4B sensor in this case (many sensors can be connected to this socket) 00115 00116 */ 00117 /*! \def SENS_SOCKET4C 00118 \brief Sensor types. Socket4C sensor in this case (many sensors can be connected to this socket) 00119 00120 */ 00121 #define SENS_TEMPERATURE 0 00122 #define SENS_HUMIDITY 1 00123 #define SENS_PRESSURE 2 00124 #define SENS_CO2 4 00125 #define SENS_O2 8 00126 #define SENS_SOCKET2A 16 00127 #define SENS_NO2 32 00128 #define SENS_SOCKET3A 64 00129 #define SENS_SOCKET3B 128 00130 #define SENS_SOCKET3C 256 00131 #define SENS_SOCKET4A 512 00132 #define SENS_SOCKET4B 1024 00133 #define SENS_SOCKET4C 2048 00134 00135 00136 /*! \def SENS_AMPLI1 00137 \brief Sensor amplifiers and resistors. Amplifier1 in this case 00138 00139 */ 00140 /*! \def SENS_AMPLI2 00141 \brief Sensor amplifiers and resistors. Amplifier2 in this case 00142 00143 */ 00144 /*! \def SENS_AMPLI3 00145 \brief Sensor amplifiers and resistors. Amplifier3 in this case 00146 00147 */ 00148 /*! \def SENS_AMPLI4 00149 \brief Sensor amplifiers and resistors. Amplifier4 in this case 00150 00151 */ 00152 /*! \def SENS_R1 00153 \brief Sensor amplifiers and resistors. Resistor1 in this case 00154 00155 */ 00156 /*! \def SENS_R2 00157 \brief Sensor amplifiers and resistors. Resistor2 in this case 00158 00159 */ 00160 /*! \def SENS_R3 00161 \brief Sensor amplifiers and resistors. Resistor3 in this case 00162 00163 */ 00164 #define SENS_AMPLI1 0 00165 #define SENS_AMPLI2 1 00166 #define SENS_AMPLI3 2 00167 #define SENS_AMPLI4 4 00168 #define SENS_R1 8 00169 #define SENS_R2 16 00170 #define SENS_R3 32 00171 00172 #define DELAY_TIME 500 00173 00174 /****************************************************************************** 00175 * Class 00176 ******************************************************************************/ 00177 00178 //! WaspSensorGas Class 00179 /*! 00180 WaspSensorGas Class defines all the variables and functions used for managing the Gas Sensor Board 00181 */ 00182 class WaspSensorGas 00183 { 00184 private: 00185 00186 //! It configures the sensor resistors 00187 /*! 00188 \param uint8_t ampli : the amplifier to configure 00189 \param float resistor : the value to set the resistor to 00190 \return void 00191 */ 00192 void configureResistor(uint8_t ampli, float resistor); 00193 00194 //! It sets the resistor value 00195 /*! 00196 \param uint8_t address : the resistor address 00197 \param float value : the value to set the resistor to 00198 \return void 00199 */ 00200 void setResistor(uint8_t address, float value); 00201 00202 //! It configures the corresponding amplifier 00203 /*! 00204 \param uint8_t ampli : the amplifier to set 00205 \param uint8_t gain : the gain to set 00206 \return void 00207 */ 00208 void configureAmplifier(uint8_t ampli, uint8_t gain); 00209 00210 //! It sets the value of the gain 00211 /*! 00212 \param uint8_t address : the amplifier address 00213 \param uint8_t value : the value to set the amplifier to 00214 \return void 00215 */ 00216 void setAmplifier(uint8_t address, uint8_t value); 00217 00218 //! It sends a pulse to read the sensor value 00219 /*! 00220 \param uint16_t sensor : the sensor to read the value from 00221 \return the value returned by the sensor 00222 */ 00223 uint16_t pulse(uint16_t sensor); 00224 00225 public: 00226 00227 //! class constructor 00228 /*! 00229 It initializes the different digital pins 00230 \param void 00231 \return void 00232 */ 00233 WaspSensorGas(); 00234 00235 //! It sets board power mode, setting ON/OFF 3v3 and 5V switches 00236 /*! 00237 \param uint8_t mode : SENS_ON or SENS_OFF 00238 \return void 00239 */ 00240 void setBoardMode(uint8_t mode); 00241 00242 //! It configures the amplifier gain in the different sensors 00243 /*! 00244 \param uint16_t sensor : the sensor to configure 00245 \param uint8_t gain : the gain to set (range [1-101]) 00246 \return void 00247 */ 00248 void configureSensor(uint16_t sensor, uint8_t gain); 00249 00250 //! It configures the amplifier gain and load resistor in the different sensors 00251 /*! 00252 \param uint16_t sensor : the sensor to configure 00253 \param uint8_t gain : the gain to set (range [1-101]) 00254 \param float resistor : the load resistor to set (range [0-100] in KOhms) 00255 \return void 00256 */ 00257 void configureSensor(uint16_t sensor, uint8_t gain, float resistor); 00258 00259 //! It sets ON/OFF the different sensor switches 00260 /*! 00261 \param uint8_t mode : SENS_ON or SENS_OFF 00262 \param uint16_t sensor : the sensor to set ON/OFF 00263 \return void 00264 */ 00265 void setSensorMode(uint8_t mode, uint16_t sensor); 00266 00267 //! It reads the value measured by the sensor 00268 /*! 00269 \param uint16_t sensor : the sensor to read the value from 00270 \return the value measured by the sensor (range [0-3.3] Volts) 00271 */ 00272 float readValue(uint16_t sensor); 00273 }; 00274 00275 extern WaspSensorGas SensorGas; 00276 00277 #endif 00278
1.5.6