upm  1.2.0
Sensor/Actuator repository for libmraa (v1.6.1)
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
bmpx8x.hpp
1 /*
2  * Author: Jon Trulson <jtrulson@ics.com>
3  * Copyright (c) 2017 Intel Corporation.
4  *
5  * This driver was rewritten based on the original driver written by:
6  * Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
7  *
8  * The MIT License
9  *
10  * Permission is hereby granted, free of charge, to any person obtaining
11  * a copy of this software and associated documentation files (the
12  * "Software"), to deal in the Software without restriction, including
13  * without limitation the rights to use, copy, modify, merge, publish,
14  * distribute, sublicense, and/or sell copies of the Software, and to
15  * permit persons to whom the Software is furnished to do so, subject to
16  * the following conditions:
17  *
18  * The above copyright notice and this permission notice shall be
19  * included in all copies or substantial portions of the Software.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28  */
29 #pragma once
30 
31 #include <string>
32 
33 #include "bmpx8x.h"
34 
35 #include "interfaces/iPressureSensor.hpp"
36 #include "interfaces/iTemperatureSensor.hpp"
37 
38 namespace upm {
39 
70  class BMPX8X : public IPressureSensor, public ITemperatureSensor {
71  public:
79  BMPX8X(int bus=BMPX8X_DEFAULT_I2C_BUS,
80  int addr=BMPX8X_DEFAULT_I2C_ADDR);
81 
85  virtual ~BMPX8X();
86 
95  void update();
96 
104  void reset();
105 
116  void init(BMPX8X_OSS_T oss=BMPX8X_OSS_ULTRAHIGHRES);
117 
126  void setOversampling(BMPX8X_OSS_T oss=BMPX8X_OSS_ULTRAHIGHRES);
127 
134  int getPressure();
135 
142  float getTemperature();
143 
152  int getSealevelPressure(float meters);
153 
162  {
164  }
165 
176  float getAltitude(int sealevelPressure = 101325);
177 
185  {
186  update();
187  return (int)getTemperature();
188  }
189 
197  {
198  update();
199  return getPressure();
200  }
201 
207  const char *getModuleName()
208  {
209  return "BMPX8X";
210  }
211 
212  protected:
213  // our underlying C context.
214  bmpx8x_context m_bmpx8x;
215 
222  uint8_t readReg(uint8_t reg);
223 
232  int readRegs(uint8_t reg, uint8_t *buffer, int len);
233 
241  void writeReg(uint8_t reg, uint8_t val);
242 
243  private:
244  };
245 
246 }
Definition: bmpx8x.h:56
int getTemperatureCelsius()
Definition: bmpx8x.hpp:184
const char * getModuleName()
Definition: bmpx8x.hpp:207
void init(BMPX8X_OSS_T oss=BMPX8X_OSS_ULTRAHIGHRES)
Definition: bmpx8x.cxx:54
void reset()
Definition: bmpx8x.cxx:68
virtual ~BMPX8X()
Definition: bmpx8x.cxx:49
void writeReg(uint8_t reg, uint8_t val)
Definition: bmpx8x.cxx:95
Interface for Temperature Sensors.
Definition: iTemperatureSensor.hpp:34
uint8_t readReg(uint8_t reg)
Definition: bmpx8x.cxx:80
BMPX8X(int bus=BMPX8X_DEFAULT_I2C_BUS, int addr=BMPX8X_DEFAULT_I2C_ADDR)
Definition: bmpx8x.cxx:41
int readRegs(uint8_t reg, uint8_t *buffer, int len)
Definition: bmpx8x.cxx:85
void setOversampling(BMPX8X_OSS_T oss=BMPX8X_OSS_ULTRAHIGHRES)
Definition: bmpx8x.cxx:75
float getTemperature()
Definition: bmpx8x.cxx:107
int getPressurePa()
Definition: bmpx8x.hpp:196
int getSealevelPressure()
Definition: bmpx8x.hpp:161
API for the GY65/BMP085 and BMP180 Atmospheric Pressure Sensors.
Definition: bmpx8x.hpp:70
int getPressure()
Definition: bmpx8x.cxx:102
float getAltitude(int sealevelPressure=101325)
Definition: bmpx8x.cxx:117
Definition: iPressureSensor.hpp:38
void update()
Definition: bmpx8x.cxx:61
C API for the bmpx8x driver.