upm  1.3.0
Sensor/Actuator repository for libmraa (v1.7.0)
 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 
71  class BMPX8X : public IPressureSensor, public ITemperatureSensor {
72  public:
80  BMPX8X(int bus=BMPX8X_DEFAULT_I2C_BUS,
81  int addr=BMPX8X_DEFAULT_I2C_ADDR);
82 
86  virtual ~BMPX8X();
87 
96  void update();
97 
105  void reset();
106 
117  void init(BMPX8X_OSS_T oss=BMPX8X_OSS_ULTRAHIGHRES);
118 
127  void setOversampling(BMPX8X_OSS_T oss=BMPX8X_OSS_ULTRAHIGHRES);
128 
135  int getPressure();
136 
143  float getTemperature();
144 
153  int getSealevelPressure(float meters);
154 
163  {
165  }
166 
177  float getAltitude(int sealevelPressure = 101325);
178 
186  {
187  update();
188  return (int)getTemperature();
189  }
190 
198  {
199  update();
200  return getPressure();
201  }
202 
208  const char *getModuleName()
209  {
210  return "BMPX8X";
211  }
212 
213  protected:
214  // our underlying C context.
215  bmpx8x_context m_bmpx8x;
216 
223  uint8_t readReg(uint8_t reg);
224 
233  int readRegs(uint8_t reg, uint8_t *buffer, int len);
234 
242  void writeReg(uint8_t reg, uint8_t val);
243 
244  private:
245  /* Disable implicit copy and assignment operators */
246  BMPX8X(const BMPX8X&) = delete;
247  BMPX8X &operator=(const BMPX8X&) = delete;
248  };
249 }
Definition: bmpx8x.h:56
int getTemperatureCelsius()
Definition: bmpx8x.hpp:185
const char * getModuleName()
Definition: bmpx8x.hpp:208
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:197
int getSealevelPressure()
Definition: bmpx8x.hpp:162
API for the GY65/BMP085 and BMP180 Atmospheric Pressure Sensors.
Definition: bmpx8x.hpp:71
int getPressure()
Definition: bmpx8x.cxx:102
float getAltitude(int sealevelPressure=101325)
Definition: bmpx8x.cxx:117
Definition: iPressureSensor.hpp:36
void update()
Definition: bmpx8x.cxx:61
C API for the bmpx8x driver.