JeeLib
An easy interface to the port headers, the RF12 driver library, timers, low-power code, and more.
 All Classes Files Functions Variables Enumerations Macros Pages
PortsBMP085.h
Go to the documentation of this file.
1 // 2009-02-17 <jc@wippler.nl> http://opensource.org/licenses/mit-license.php
2 
3 /// @file
4 /// Port library interface to BMP085 sensors connected via I2C.
5 /// See https://jeelabs.net/projects/hardware/wiki/pp1
6 
7 /// Interface for the Pressure Plug - see https://jeelabs.org/pp
8 class BMP085 : public DeviceI2C {
9  int16_t ac1, ac2, ac3, b1, b2, mb, mc, md;
10  uint16_t ac4, ac5, ac6;
11 
12  uint16_t readWord(uint8_t last) const
13  { uint16_t v = read(0) << 8; return v | read(last); }
14  void readFromReg(uint8_t reg) const
15  { send(); write(reg); receive(); }
16 
17 public:
18  enum { TEMP, PRES };
19  int32_t meas[2];
20  uint8_t oss;
21 
22  /// Constructor for BMP085 class.
23  /// @param p I2C port to be used.
24  /// @param osrs 0..3 Oversampling setting.
25  BMP085 (const PortI2C& p, uint8_t osrs =0)
26  : DeviceI2C (p, 0x77), oss (osrs) {}
27 
28  /// Set the oversampling setting for the high resolution mode.
29  /// @param osrs 0..3.
30  void setOverSampling(uint8_t osrs) { oss = osrs; }
31 
32  /// Start a measurement.
33  /// @param type BMP::TEMP for temperature or BMP::PRES for pressure.
34  uint8_t startMeas(uint8_t type) const;
35  /// Get the results from the last measurement.
36  /// @param type BMP::TEMP for temperature or BMP::PRES for pressure.
37  int32_t getResult(uint8_t type);
38 
39  /// Take a measurement.
40  /// @param type BMP::TEMP for temperature or BMP::PRES for pressure.
41  int32_t measure(uint8_t type)
42  { delay(startMeas(type)); return getResult(type); }
43 
44  void getCalibData();
45  void calculate(int16_t& tval, int32_t& pval) const;
46 };
BMP085(const PortI2C &p, uint8_t osrs=0)
Constructor for BMP085 class.
Definition: PortsBMP085.h:25
void calculate(int16_t &tval, int32_t &pval) const
Calculate the temperature and pressure based on the values stored by the last call to measure()...
Definition: PortsBMP085.cpp:55
void setOverSampling(uint8_t osrs)
Set the oversampling setting for the high resolution mode.
Definition: PortsBMP085.h:30
uint8_t receive() const
Create a start condition on the I2C bus, and set things up for receiving data from this device...
Definition: Ports.h:284
Can be used to drive a software (bit-banged) I2C bus via a Port interface.
Definition: Ports.h:213
int32_t measure(uint8_t type)
Take a measurement.
Definition: PortsBMP085.h:41
uint8_t write(uint8_t data) const
Write a byte to the currently addressed device.
Definition: Ports.h:293
Each device on the I2C bus needs to be defined using a DeviceI2C instance.
Definition: Ports.h:266
uint8_t startMeas(uint8_t type) const
Start a measurement.
Definition: PortsBMP085.cpp:15
int32_t getResult(uint8_t type)
Get the results from the last measurement.
Definition: PortsBMP085.cpp:23
void getCalibData()
Call this during setup() if you want to use calculate() later on.
Definition: PortsBMP085.cpp:36
uint8_t send() const
Create a start condition on the I2C bus, and set things up for sending data to this device...
Definition: Ports.h:279
uint8_t read(uint8_t last) const
Read a byte from the currently addressed device.
Definition: Ports.h:300
Interface for the Pressure Plug - see https://jeelabs.org/pp.
Definition: PortsBMP085.h:8