upm  0.6.2
Sensor/Actuator repository for libmraa (v0.10.1)
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
bmpx8x.h
1 /*
2  * Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
3  * Contributions: Jon Trulson <jtrulson@ics.com>
4  * Copyright (c) 2014 Intel Corporation.
5  *
6  * Credits to Adafruit.
7  * Based on Adafruit BMP085 library.
8  *
9  * Permission is hereby granted, free of charge, to any person obtaining
10  * a copy of this software and associated documentation files (the
11  * "Software"), to deal in the Software without restriction, including
12  * without limitation the rights to use, copy, modify, merge, publish,
13  * distribute, sublicense, and/or sell copies of the Software, and to
14  * permit persons to whom the Software is furnished to do so, subject to
15  * the following conditions:
16  *
17  * The above copyright notice and this permission notice shall be
18  * included in all copies or substantial portions of the Software.
19  *
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27  */
28 #pragma once
29 
30 #include <string>
31 #include <mraa/i2c.hpp>
32 #include <math.h>
33 #include "upm/iTemperatureSensor.h"
34 
35 #define ADDR 0x77 // device address
36 
37 // registers address
38 #define BMP085_ULTRALOWPOWER 0
39 #define BMP085_STANDARD 1
40 #define BMP085_HIGHRES 2
41 #define BMP085_ULTRAHIGHRES 3
42 #define BMP085_CAL_AC1 0xAA // R Calibration data (16 bits)
43 #define BMP085_CAL_AC2 0xAC // R Calibration data (16 bits)
44 #define BMP085_CAL_AC3 0xAE // R Calibration data (16 bits)
45 #define BMP085_CAL_AC4 0xB0 // R Calibration data (16 bits)
46 #define BMP085_CAL_AC5 0xB2 // R Calibration data (16 bits)
47 #define BMP085_CAL_AC6 0xB4 // R Calibration data (16 bits)
48 #define BMP085_CAL_B1 0xB6 // R Calibration data (16 bits)
49 #define BMP085_CAL_B2 0xB8 // R Calibration data (16 bits)
50 #define BMP085_CAL_MB 0xBA // R Calibration data (16 bits)
51 #define BMP085_CAL_MC 0xBC // R Calibration data (16 bits)
52 #define BMP085_CAL_MD 0xBE // R Calibration data (16 bits)
53 
54 #define BMP085_CONTROL 0xF4
55 #define BMP085_TEMPDATA 0xF6
56 #define BMP085_PRESSUREDATA 0xF6
57 #define BMP085_READTEMPCMD 0x2E
58 #define BMP085_READPRESSURECMD 0x34
59 
60 #define HIGH 1
61 #define LOW 0
62 
63 namespace upm {
64 
92 class BMPX8X : public ITemperatureSensor {
93  public:
101  BMPX8X (int bus, int devAddr=0x77, uint8_t mode=BMP085_ULTRAHIGHRES);
102 
113  int32_t getPressure ();
114 
119  int32_t getPressureRaw ();
120 
124  int16_t getTemperatureRaw ();
125 
129  float getTemperature ();
130 
136  int32_t getSealevelPressure(float altitudeMeters = 0);
137 
143  float getAltitude (float sealevelPressure = 101325);
144 
149  int getTemperatureCelcius();
150 
156  const char* getModuleName();
157 
163  int32_t computeB5 (int32_t UT);
164 
170  uint16_t i2cReadReg_16 (int reg);
171 
178  mraa::Result i2cWriteReg (uint8_t reg, uint8_t value);
179 
185  uint8_t i2cReadReg_8 (int reg);
186 
187  private:
188  std::string m_name;
189 
190  int m_controlAddr;
191  int m_bus;
192  mraa::I2c m_i2ControlCtx;
193 
194  uint8_t oversampling;
195  int16_t ac1, ac2, ac3, b1, b2, mb, mc, md;
196  uint16_t ac4, ac5, ac6;
197 };
198 
199 }
int32_t computeB5(int32_t UT)
Definition: bmpx8x.cxx:186
uint8_t i2cReadReg_8(int reg)
Definition: bmpx8x.cxx:222
BMPX8X(int bus, int devAddr=0x77, uint8_t mode=BMP085_ULTRAHIGHRES)
Definition: bmpx8x.cxx:35
int32_t getPressureRaw()
Definition: bmpx8x.cxx:111
Interface for Temperature Sensors.
Definition: iTemperatureSensor.h:34
int16_t getTemperatureRaw()
Definition: bmpx8x.cxx:136
int32_t getSealevelPressure(float altitudeMeters=0)
Definition: bmpx8x.cxx:157
float getTemperature()
Definition: bmpx8x.cxx:143
API for the GY65/BMP085 and BMP180 Atmospheric Pressure Sensors.
Definition: bmpx8x.h:92
int getTemperatureCelcius()
Definition: bmpx8x.cxx:175
uint16_t i2cReadReg_16(int reg)
Definition: bmpx8x.cxx:205
mraa::Result i2cWriteReg(uint8_t reg, uint8_t value)
Definition: bmpx8x.cxx:194
const char * getModuleName()
Definition: bmpx8x.cxx:180
float getAltitude(float sealevelPressure=101325)
Definition: bmpx8x.cxx:163
int32_t getPressure()
Definition: bmpx8x.cxx:74