upm  0.2.0
Sensor/Actuator repository for libmraa (v0.6.1)
mpl3115a2.h
1 /*
2  * Author: William Penner <william.penner@intel.com>
3  * Copyright (c) 2014 Intel Corporation.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a copy
6  * of this software and associated documentation files (the "Software"), to deal
7  * in the Software without restriction, including without limitation the rights
8  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9  * copies of the Software, and to permit persons to whom the Software is
10  * furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in
13  * all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21  * THE SOFTWARE.
22  */
23 
24 #pragma once
25 
26 #include <string>
27 #include <mraa/i2c.h>
28 #include <math.h>
29 
30 #define MPL3115A2_NAME "mpl3115a2"
31 
32 #define MPL3115A2_I2C_ADDRESS 0x60
33 #define MPL3115A2_DEVICE_ID 0xc4
34 
35 #define MPL3115A2_STATUS 0x00
36 #define MPL3115A2_OUT_PRESS 0x01 /* MSB first, 20 bit */
37 #define MPL3115A2_OUT_TEMP 0x04 /* MSB first, 12 bit */
38 #define MPL3115A2_WHO_AM_I 0x0c
39 #define MPL3115A2_PT_DATA_CFG 0x13
40 #define MPL3115A2_P_MIN 0x1C
41 #define MPL3115A2_T_MIN 0x1F
42 #define MPL3115A2_P_MAX 0x21
43 #define MPL3115A2_T_MAX 0x24
44 #define MPL3115A2_CTRL_REG1 0x26
45 
46 // CTRL_REG1
47 #define MPL3115A2_CTRL_SBYB 0x01 /* Standby (not) */
48 #define MPL3115A2_CTRL_OST 0x02 /* One-shot trigger */
49 #define MPL3115A2_CTRL_RESET 0x04 /* RESET device */
50 #define MPL3115A2_CTRL_ALT_MODE 0x80 /* Altitude mode */
51 
52 #define MPL3115A2_SETOVERSAMPLE(a) ((a & 7) << 3)
53 #define MPL3115A2_GETOVERSAMPLE(a) ((a >> 3) & 7)
54 #define MPL3115A2_MAXOVERSAMPLE 7
55 
56 namespace upm {
57 
81 class MPL3115A2 {
82  public:
90  MPL3115A2(int bus, int devAddr=MPL3115A2_I2C_ADDRESS, uint8_t mode=6);
91 
95  ~MPL3115A2();
96 
101  int testSensor(void);
102 
108  int resetSensor(void);
109 
113  void dumpSensor(void);
114 
120  int sampleData(void);
121 
127  int32_t getPressureReg(int reg);
128 
134  int32_t getTempReg(int reg);
135 
141  float getPressure(int bSampleData = true);
142 
148  float getTemperature(int bSampleData = true);
149 
157  float getSealevelPressure(float altitudeMeters = 0.0);
158 
166  float getAltitude (float sealevelPressure = 101325.0);
167 
175  void setOversampling(uint8_t oversampling);
176 
180  uint8_t getOversampling(void);
181 
185  float getTemperatureMax(void);
186 
190  float getTemperatureMin(void);
191 
195  float getPressureMax (void);
196 
200  float getPressureMin (void);
201 
207  float convertTempCtoF(float fTemp);
208 
216  float convertPaToinHg(float fPressure);
217 
224  mraa_result_t i2cWriteReg (uint8_t reg, uint8_t value);
225 
231  uint16_t i2cReadReg_16 (int reg);
232 
238  uint8_t i2cReadReg_8 (int reg);
239 
240  private:
241  std::string m_name;
242 
243  int m_controlAddr;
244  int m_bus;
245  mraa_i2c_context m_i2ControlCtx;
246 
247  uint8_t m_oversampling;
248  int32_t m_iPressure;
249  int32_t m_iTemperature;
250 };
251 
252 }
253 
float getPressureMax(void)
Definition: mpl3115a2.cpp:269
int sampleData(void)
Definition: mpl3115a2.cpp:146
void setOversampling(uint8_t oversampling)
Definition: mpl3115a2.cpp:243
int32_t getTempReg(int reg)
Definition: mpl3115a2.cpp:192
float convertTempCtoF(float fTemp)
Definition: mpl3115a2.cpp:281
~MPL3115A2()
Definition: mpl3115a2.cpp:60
float getTemperatureMax(void)
Definition: mpl3115a2.cpp:257
C++ API for MPL3115A2 chip (Atmospheric Pressure Sensor)
Definition: mpl3115a2.h:81
mraa_result_t i2cWriteReg(uint8_t reg, uint8_t value)
Definition: mpl3115a2.cpp:300
float getAltitude(float sealevelPressure=101325.0)
Definition: mpl3115a2.cpp:237
float getTemperature(int bSampleData=true)
Definition: mpl3115a2.cpp:214
Definition: a110x.h:29
int32_t getPressureReg(int reg)
Definition: mpl3115a2.cpp:187
uint8_t i2cReadReg_8(int reg)
Definition: mpl3115a2.cpp:322
float convertPaToinHg(float fPressure)
Definition: mpl3115a2.cpp:290
MPL3115A2(int bus, int devAddr=MPL3115A2_I2C_ADDRESS, uint8_t mode=6)
Definition: mpl3115a2.cpp:37
float getPressureMin(void)
Definition: mpl3115a2.cpp:275
int resetSensor(void)
Definition: mpl3115a2.cpp:134
uint8_t getOversampling(void)
Definition: mpl3115a2.cpp:251
float getSealevelPressure(float altitudeMeters=0.0)
Definition: mpl3115a2.cpp:231
float getTemperatureMin(void)
Definition: mpl3115a2.cpp:263
int testSensor(void)
Definition: mpl3115a2.cpp:72
uint16_t i2cReadReg_16(int reg)
Definition: mpl3115a2.cpp:311
void dumpSensor(void)
Definition: mpl3115a2.cpp:113
float getPressure(int bSampleData=true)
Definition: mpl3115a2.cpp:197