upm  0.3.1
Sensor/Actuator repository for libmraa (v0.7.2)
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 
82 class MPL3115A2 {
83  public:
91  MPL3115A2(int bus, int devAddr=MPL3115A2_I2C_ADDRESS, uint8_t mode=6);
92 
96  ~MPL3115A2();
97 
102  int testSensor(void);
103 
109  int resetSensor(void);
110 
114  void dumpSensor(void);
115 
121  int sampleData(void);
122 
128  int32_t getPressureReg(int reg);
129 
135  int32_t getTempReg(int reg);
136 
142  float getPressure(int bSampleData = true);
143 
149  float getTemperature(int bSampleData = true);
150 
158  float getSealevelPressure(float altitudeMeters = 0.0);
159 
167  float getAltitude (float sealevelPressure = 101325.0);
168 
176  void setOversampling(uint8_t oversampling);
177 
181  uint8_t getOversampling(void);
182 
186  float getTemperatureMax(void);
187 
191  float getTemperatureMin(void);
192 
196  float getPressureMax (void);
197 
201  float getPressureMin (void);
202 
208  float convertTempCtoF(float fTemp);
209 
217  float convertPaToinHg(float fPressure);
218 
225  mraa_result_t i2cWriteReg (uint8_t reg, uint8_t value);
226 
232  uint16_t i2cReadReg_16 (int reg);
233 
239  uint8_t i2cReadReg_8 (int reg);
240 
241  private:
242  std::string m_name;
243 
244  int m_controlAddr;
245  int m_bus;
246  mraa_i2c_context m_i2ControlCtx;
247 
248  uint8_t m_oversampling;
249  int32_t m_iPressure;
250  int32_t m_iTemperature;
251 };
252 
253 }
254 
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
API for MPL3115A2 chip (Atmospheric Pressure Sensor)
Definition: mpl3115a2.h:82
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