forked from jarzebski/Arduino-MS5611
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MS5611.h
76 lines (60 loc) · 1.95 KB
/
MS5611.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
MS5611.h - Header file for the MS5611 Barometric Pressure & Temperature Sensor Arduino Library.
Version: 1.0.0
(c) 2014 Korneliusz Jarzebski
www.jarzebski.pl
This program is free software: you can redistribute it and/or modify
it under the terms of the version 3 GNU General Public License as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef MS5611_h
#define MS5611_h
#if ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
#define MS5611_ADDRESS (0x77)
#define MS5611_CMD_ADC_READ (0x00)
#define MS5611_CMD_RESET (0x1E)
#define MS5611_CMD_CONV_D1 (0x40)
#define MS5611_CMD_CONV_D2 (0x50)
#define MS5611_CMD_READ_PROM (0xA2)
typedef enum
{
MS5611_ULTRA_HIGH_RES = 0x08,
MS5611_HIGH_RES = 0x06,
MS5611_STANDARD = 0x04,
MS5611_LOW_POWER = 0x02,
MS5611_ULTRA_LOW_POWER = 0x00
} ms5611_osr_t;
class MS5611
{
public:
bool begin(ms5611_osr_t osr = MS5611_HIGH_RES);
uint32_t readRawTemperature(void);
uint32_t readRawPressure(void);
double readTemperature(bool compensation = false);
int32_t readPressure(bool compensation = false);
double getAltitude(double pressure, double seaLevelPressure = 101325);
double getSeaLevel(double pressure, double altitude);
void setOversampling(ms5611_osr_t osr);
ms5611_osr_t getOversampling(void);
private:
uint16_t fc[6];
uint8_t ct;
uint8_t uosr;
int32_t TEMP2;
int64_t OFF2, SENS2;
void reset(void);
void readPROM(void);
uint16_t readRegister16(uint8_t reg);
uint32_t readRegister24(uint8_t reg);
};
#endif