moon

Dependencies:   Hexi_OLED_SSD1351

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Barometer.h Source File

Barometer.h

00001 
00002 #ifndef MPL3115A2_H
00003 #define MPL3115A2_H
00004 
00005 #include "mbed.h"
00006 
00007 // Oversampling value and minimum time between sample
00008 #define OVERSAMPLE_1      0       // 6 ms
00009 #define OVERSAMPLE_2      1       // 10 ms
00010 #define OVERSAMPLE_4      2       // 18 ms
00011 #define OVERSAMPLE_8      3       // 34 ms
00012 #define OVERSAMPLE_16     4       // 66 ms
00013 #define OVERSAMPLE_32     5       // 130 ms
00014 #define OVERSAMPLE_64     6       // 258 ms
00015 #define OVERSAMPLE_128    7       // 512 ms
00016 
00017 /* Mode */
00018 #define MODE_ALT      1
00019 #define MODE_BAR     2
00020 
00021 
00022 class DEVICE
00023 {
00024 public:
00025 
00026     DEVICE(PinName sda, PinName scl, int addr);  //return the value of 0xC4
00027 
00028     uint8_t requestDeviceID();
00029 
00030     /**
00031     * Return the STATUS register value
00032     *
00033     * @returns STATUS register value
00034     */
00035     unsigned char statusRequest( void);
00036 
00037     /**
00038     * Get the altimeter value
00039     *
00040     * @returns altimeter value as float
00041     */
00042     float requestAltimeter( void);
00043 
00044     /**
00045     * Get the altimeter value in raw mode
00046     *
00047     * @param    dt      pointer to unsigned char array
00048     * @returns 1 if data are available, 0 if not.
00049     */
00050     unsigned int getAltimeterRaw( unsigned char *dt);
00051 
00052     /**
00053     * Get the pressure value
00054     *
00055     * @returns pressure value as float
00056     */
00057     float requestPressure( void);
00058 
00059     /**
00060     * Get the pressure value in raw mode
00061     *
00062     * @param    dt      pointer to unsigned char array
00063     * @returns 1 if data are available, 0 if not.
00064     */
00065     unsigned int  getPressureRaw( unsigned char *dt);
00066 
00067     /**
00068     * Get the temperature value
00069     *
00070     * @returns temperature value as float
00071     */
00072     float requestTemperature( void);
00073 
00074     /**
00075     * Get the temperature value in raw mode
00076     *
00077     * @param    dt      pointer to unsigned char array
00078     * @returns 1 if data are available, 0 if not.
00079     */
00080     unsigned int getTemperatureRaw( unsigned char *dt);
00081 
00082     /**
00083     * Set the Altimeter Mode
00084     *
00085     * @returns none
00086     */
00087     void Altimeter( void);
00088 
00089     /**
00090     * Set the Barometric Mode
00091     *
00092     * @returns none
00093     */
00094     void Barometric( void);
00095 
00096     /**
00097     * Get the altimeter or pressure and temperature values
00098     *
00099     * @param array of float f[2]
00100     * @returns 0 no data available, 1 for data available
00101     */
00102     unsigned int  requestAllData( float *f);
00103 
00104     /**
00105     * Get the altimeter or pressure and temperature values and the delta values
00106     *
00107     * @param array of float f[2], array of float d[2]
00108     * @returns 0 no data available, 1 for data available
00109     */
00110     unsigned int requestAllData( float *f, float *d);
00111 
00112     /**
00113     * Get the altimeter or pressure and temperature captured maximum value
00114     *
00115     * @param array of float f[2]
00116     * @returns 0 no data available, 1 for data available
00117     */
00118     void requestAllMaximumData( float *f);
00119 
00120     /**
00121     * Get the altimeter or pressure and temperature captured minimum value
00122     *
00123     * @param array of float f[2]
00124     * @returns 0 no data available, 1 for data available
00125     */
00126     void requestAllMinimumData( float *f);
00127 
00128     /**
00129     * Get the altimeter or pressure, and temperature values in raw mode
00130     *
00131     * @param array of unsigned char[5]
00132     * @returns 1 if data are available, 0 if not.
00133     */
00134     unsigned int getAllDataRaw( unsigned char *dt);
00135 
00136     /**
00137     * Return if there are date available
00138     *
00139     * @return 0 for no data available, bit0 set for Temp data available, bit1 set for Press/Alti data available
00140     *         bit2 set for both Temp and Press/Alti data available
00141     */
00142     unsigned int isDataAvailable( void);
00143 
00144     /**
00145     * Set the oversampling rate value
00146     *
00147     * @param oversampling values. See MPL3115A2.h
00148     * @return none
00149     */
00150     void sampling_Ratio( unsigned int ratio);
00151 
00152     /**
00153     * Configure the sensor to streaming data using Interrupt
00154     *
00155     * @param user functin callback, oversampling values. See MPL3115A2.h
00156     * @return none
00157     */
00158     void DReady( void(*fptr)(void), unsigned char OS);
00159 
00160 
00161     void AltitudeTrigger( void(*fptr)(void), unsigned short level);
00162 
00163     /**
00164     * Soft Reset
00165     *
00166     * @param none
00167     * @return none
00168     */
00169     void Reset( void);
00170 
00171     /**
00172     * Configure the Pressure offset.
00173     * Pressure user accessible offset trim value expressed as an 8-bit 2's complement number.
00174     * The user offset registers may be adjusted to enhance accuracy and optimize the system performance.
00175     * Range is from -512 to +508 Pa, 4 Pa per LSB.
00176     * In RAW output mode no scaling or offsets will be applied in the digital domain
00177     *
00178     * @param    offset
00179     * @return   none
00180     */
00181     void SetPressureOffset( char offset);
00182 
00183     /**
00184     * Configure the Temperature offset.
00185     * Temperature user accessible offset trim value expressed as an 8-bit 2's complement number.
00186     * The user offset registers may be adjusted to enhance accuracy and optimize the system performance.
00187     * Range is from -8 to +7.9375°C 0.0625°C per LSB.
00188     * In RAW output mode no scaling or offsets will be applied in the digital domain
00189     *
00190     * @param    offset
00191     * @return   none
00192     */
00193     void SetTemperatureOffset( char offset);
00194 
00195     /**
00196     * Configure the Altitude offset.
00197     * Altitude Data User Offset Register (OFF_H) is expressed as a 2’s complement number in meters.
00198     * The user offset register provides user adjustment to the vertical height of the Altitude output.
00199     * The range of values are from -128 to +127 meters.
00200     * In RAW output mode no scaling or offsets will be applied in the digital domain
00201     *
00202     * @param    offset
00203     * @return   none
00204     */
00205     void SetAltitudeOffset( char offset);
00206 
00207 private:
00208     I2C m_i2c;
00209     int m_addr;
00210     unsigned char Device_mode;
00211     unsigned char Device_oversampling;
00212     void DReady_IRQ( void);
00213     void AltitudeTrg_IRQ( void);
00214 
00215     /** Set the device in active mode
00216     */
00217     void Active( void);
00218 
00219     /** Set the device in standby mode
00220     */
00221     void Standby( void);
00222 
00223     /** Get the altimiter value from the sensor.
00224     *
00225     * @param    reg the register from which read the data.
00226     *           Can be: REG_ALTIMETER_MSB for altimeter value
00227     *                   REG_ALTI_MIN_MSB for the minimum value captured
00228     *                   REG_ALTI_MAX_MSB for the maximum value captured
00229     */
00230     float requestAltimeter( unsigned char reg);
00231 
00232     /** Get the pressure value from the sensor.
00233     *
00234     * @param    reg the register from which read the data.
00235     *           Can be: REG_PRESSURE_MSB for altimeter value
00236     *                   REG_PRES_MIN_MSB for the minimum value captured
00237     *                   REG_PRES_MAX_MSB for the maximum value captured
00238     */
00239     float requestPressure( unsigned char reg);
00240 
00241     /** Get the altimiter value from the sensor.
00242     *
00243     * @param    reg the register from which read the data.
00244     *           Can be: REG_TEMP_MSB for altimeter value
00245     *                   REG_TEMP_MIN_MSB for the minimum value captured
00246     *                   REG_TEMP_MAX_MSB for the maximum value captured
00247     */
00248     float requestTemperature( unsigned char reg);
00249 
00250     void readRegs(int addr, uint8_t * data, int len);
00251     void writeRegs(uint8_t * data, int len);
00252 
00253 };
00254 
00255 #endif
00256 
00257 
00258