upm  0.8.0
Sensor/Actuator repository for libmraa (v1.1.1)
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
ms5611.hpp
1 /*
2  * Author: Henry Bruce <henry.bruce@intel.com>
3  * Copyright (c) 2016 Intel Corporation.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining
6  * a copy of this software and associated documentation files (the
7  * "Software"), to deal in the Software without restriction, including
8  * without limitation the rights to use, copy, modify, merge, publish,
9  * distribute, sublicense, and/or sell copies of the Software, and to
10  * permit persons to whom the Software is furnished to do so, subject to
11  * the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 
25 #include "upm/iPressureSensor.hpp"
26 #include "upm/iTemperatureSensor.hpp"
27 #include "mraa/i2c.hpp"
28 
29 namespace upm
30 {
31 
32 #define MS5611_ADDRESS 0x76
33 
61 {
62 public:
63  enum OsrMode
64  {
65  ULTRA_LOW_POWER, LOW_POWER, STANDARD, ULTRA_HIGH_RES, HIGH_RES
66  };
67 
68  MS5611(int i2cBus = 0, int address = MS5611_ADDRESS);
69  ~MS5611();
70  const char* getModuleName() { return "ms5611"; }
71  void setOverSampling(OsrMode osrMode);
72  int getTemperatureCelsius();
73  int getPressurePa();
74 
75 private:
76  int promCrc4();
77  uint32_t readADC(int adcReg);
78  void delayms(int millisecs);
79  uint32_t readRawPressure();
80  uint32_t readRawTemperature();
81 
82  mraa::Result status;
83  mraa::I2c* i2c;
84  int address;
85  uint16_t *prom;
86  int osr;
87  int samplePeriod;
88 };
89 
90 
91 }
92 
Interface for Temperature Sensors.
Definition: iTemperatureSensor.hpp:34
Definition: ms5611.hpp:60
const char * getModuleName()
Definition: ms5611.hpp:70
Interface for Pressue Sensors.
Definition: iPressureSensor.hpp:38