COSA
An Object-Oriented Platform for Arduino Programming
BMP085.hh
Go to the documentation of this file.
1 
21 #ifndef COSA_BMP085_HH
22 #define COSA_BMP085_HH
23 
24 #include "Cosa/Types.h"
25 #include "Cosa/TWI.hh"
26 #include "Cosa/IOStream.hh"
27 
54 class BMP085 : private TWI::Driver {
55 public:
59  enum Mode {
61  STANDARD = 1,
64  } __attribute__((packed));
65 
70  BMP085() :
71  TWI::Driver(0x77),
73  m_cmd(0),
74  m_start(0),
75  B5(0),
76  m_pressure(0)
77  {}
78 
85  bool begin(Mode mode = ULTRA_LOW_POWER);
86 
93 
99  bool read_temperature();
100 
107  {
109  }
110 
117 
123  bool read_pressure();
124 
131  __attribute__((always_inline))
132  {
133  return (sample_pressure_request() && read_pressure());
134  }
135 
141  bool sample()
142  __attribute__((always_inline))
143  {
144  return (sample_temperature() && sample_pressure());
145  }
146 
151  int16_t temperature() const
152  __attribute__((always_inline))
153  {
154  return ((B5 + 8) >> 4);
155  }
156 
162  int32_t pressure() const
163  {
164  return (m_pressure);
165  }
166 
167 protected:
169  static const uint8_t TEMP_CONV_MS = 5;
170 
172  static const uint8_t PRESSURE_CONV_MS[] __PROGMEM;
173 
178  struct param_t {
179  int16_t ac1;
180  int16_t ac2;
181  int16_t ac3;
182  uint16_t ac4;
183  uint16_t ac5;
184  uint16_t ac6;
185  int16_t b1;
186  int16_t b2;
187  int16_t mb;
188  int16_t mc;
189  int16_t md;
190  };
191 
193  static const uint8_t COEFF_REG = 0xAA;
194 
196  static const uint8_t CMD_REG = 0xF4;
197 
199  static const uint8_t RES_REG = 0xF6;
200 
202  static const uint8_t TEMP_CONV_CMD = 0x2E;
203 
205  static const uint8_t PRESSURE_CONV_CMD = 0x34;
206 
209 
212 
214  uint8_t m_cmd;
215 
217  uint16_t m_start;
218 
220  int32_t B5;
221 
223  int32_t m_pressure;
224 };
225 
232 extern IOStream& operator<<(IOStream& outs, BMP085& bmp);
233 
234 #endif
Definition: TWI.hh:51
static const uint8_t RES_REG
Definition: BMP085.hh:199
uint16_t ac4
Definition: BMP085.hh:182
static const uint8_t PRESSURE_CONV_CMD
Definition: BMP085.hh:205
uint16_t m_start
Definition: BMP085.hh:217
int16_t ac3
Definition: BMP085.hh:181
uint8_t m_cmd
Definition: BMP085.hh:214
int32_t B5
Definition: BMP085.hh:220
bool sample_pressure_request()
Definition: BMP085.cpp:96
bool sample_temperature()
Definition: BMP085.hh:106
bool begin(Mode mode=ULTRA_LOW_POWER)
Definition: BMP085.cpp:34
bool read_pressure()
Definition: BMP085.cpp:113
int16_t mc
Definition: BMP085.hh:188
int32_t pressure() const
Definition: BMP085.hh:162
param_t m_param
Definition: BMP085.hh:208
int32_t m_pressure
Definition: BMP085.hh:223
IOStream & operator<<(IOStream &outs, BMP085 &bmp)
Definition: BMP085.cpp:158
int16_t md
Definition: BMP085.hh:189
Mode
Definition: BMP085.hh:59
int16_t ac2
Definition: BMP085.hh:180
static const uint8_t TEMP_CONV_CMD
Definition: BMP085.hh:202
int16_t ac1
Definition: BMP085.hh:179
bool sample_pressure()
Definition: BMP085.hh:130
static const uint8_t COEFF_REG
Definition: BMP085.hh:193
Driver(uint8_t addr)
Definition: TWI.hh:70
bool sample_temperature_request()
Definition: BMP085.cpp:51
Mode m_mode
Definition: BMP085.hh:211
static const uint8_t CMD_REG
Definition: BMP085.hh:196
bool sample()
Definition: BMP085.hh:141
static const uint8_t PRESSURE_CONV_MS[] __PROGMEM
Definition: BMP085.hh:172
uint16_t ac5
Definition: BMP085.hh:183
int16_t temperature() const
Definition: BMP085.hh:151
uint16_t ac6
Definition: BMP085.hh:184
static const uint8_t TEMP_CONV_MS
Definition: BMP085.hh:169
bool read_temperature()
Definition: BMP085.cpp:68
int16_t b2
Definition: BMP085.hh:186
Definition: BMP085.hh:54
int16_t b1
Definition: BMP085.hh:185
BMP085()
Definition: BMP085.hh:70
int16_t mb
Definition: BMP085.hh:187