upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
mpl3115a2.hpp
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.hpp>
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 
82 class MPL3115A2 {
83  public:
91  MPL3115A2(int bus, int devAddr=MPL3115A2_I2C_ADDRESS, uint8_t mode=6);
92 
104  int testSensor(void);
105 
111  int resetSensor(void);
112 
116  void dumpSensor(void);
117 
123  int sampleData(void);
124 
130  int32_t getPressureReg(int reg);
131 
137  int32_t getTempReg(int reg);
138 
144  float getPressure(int bSampleData = true);
145 
151  float getTemperature(int bSampleData = true);
152 
160  float getSealevelPressure(float altitudeMeters = 0.0);
161 
169  float getAltitude (float sealevelPressure = 101325.0);
170 
178  void setOversampling(uint8_t oversampling);
179 
183  uint8_t getOversampling(void);
184 
188  float getTemperatureMax(void);
189 
193  float getTemperatureMin(void);
194 
198  float getPressureMax (void);
199 
203  float getPressureMin (void);
204 
210  float convertTempCtoF(float fTemp);
211 
219  float convertPaToinHg(float fPressure);
220 
227  mraa::Result i2cWriteReg (uint8_t reg, uint8_t value);
228 
234  uint16_t i2cReadReg_16 (int reg);
235 
241  uint8_t i2cReadReg_8 (int reg);
242 
243  private:
244  std::string m_name;
245 
246  int m_controlAddr;
247  int m_bus;
248  mraa::I2c m_i2ControlCtx;
249 
250  uint8_t m_oversampling;
251  int32_t m_iPressure;
252  int32_t m_iTemperature;
253 };
254 
255 }
256 
float getPressureMax(void)
Definition: mpl3115a2.cpp:266
int sampleData(void)
Definition: mpl3115a2.cpp:146
void setOversampling(uint8_t oversampling)
Definition: mpl3115a2.cpp:240
int32_t getTempReg(int reg)
Definition: mpl3115a2.cpp:189
float convertTempCtoF(float fTemp)
Definition: mpl3115a2.cpp:278
float getTemperatureMax(void)
Definition: mpl3115a2.cpp:254
API for the MPL3115A2 Atmospheric Pressure Sensor.
Definition: mpl3115a2.hpp:82
float getAltitude(float sealevelPressure=101325.0)
Definition: mpl3115a2.cpp:234
float getTemperature(int bSampleData=true)
Definition: mpl3115a2.cpp:211
C++ API wrapper for the bh1749 driver.
Definition: a110x.hpp:29
int32_t getPressureReg(int reg)
Definition: mpl3115a2.cpp:184
uint8_t i2cReadReg_8(int reg)
Definition: mpl3115a2.cpp:320
float convertPaToinHg(float fPressure)
Definition: mpl3115a2.cpp:287
MPL3115A2(int bus, int devAddr=MPL3115A2_I2C_ADDRESS, uint8_t mode=6)
Definition: mpl3115a2.cpp:39
float getPressureMin(void)
Definition: mpl3115a2.cpp:272
int resetSensor(void)
Definition: mpl3115a2.cpp:134
mraa::Result i2cWriteReg(uint8_t reg, uint8_t value)
Definition: mpl3115a2.cpp:297
uint8_t getOversampling(void)
Definition: mpl3115a2.cpp:248
float getSealevelPressure(float altitudeMeters=0.0)
Definition: mpl3115a2.cpp:228
float getTemperatureMin(void)
Definition: mpl3115a2.cpp:260
int testSensor(void)
Definition: mpl3115a2.cpp:73
uint16_t i2cReadReg_16(int reg)
Definition: mpl3115a2.cpp:310
void dumpSensor(void)
Definition: mpl3115a2.cpp:113
float getPressure(int bSampleData=true)
Definition: mpl3115a2.cpp:194