-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMS5607.h
108 lines (82 loc) · 2.22 KB
/
MS5607.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#pragma once
#include "Arduino.h"
class I2C {
public:
I2C();
byte write(byte address, const char *buffer, byte bufSize);
byte read(byte address, char *buffer, byte bufSize);
void setSlow();
void setNormal();
private:
int rxTimeout;
};
class MS5607Base {
public:
enum OversamplingRate {
kOSR256 = 0,
kOSR512 = 1,
kOSR1024 = 2,
kOSR2048 = 3,
kOSR4096 = 4,
kOSR8192 = 5
};
enum ConversionType {
kPressure = 0,
kTemperature = 1
};
};
class MS5607 : public MS5607Base {
public:
MS5607(I2C &bus, byte subAddress = 0);
bool reset();
bool readPROM(byte address, word &result);
bool startConversion(ConversionType type, OversamplingRate osr = kOSR256);
bool readResult24(long &result);
bool readResult16(word &result);
private:
I2C _bus;
uint8_t _address;
enum Commands {
kCmdReset = 0b00011110,
kCmdReadPROM = 0b10100000,
kCmdConvert = 0b01000000,
kCmdReadADC = 0b00000000,
};
};
class Barometer : public MS5607 {
public:
Barometer(I2C &bus, byte subaddress = 0);
bool initialize();
/**
* Measures and updates both temperature and pressure
*/
bool update();
/// Returns temperature in Celsium x100 (2000 = 20.00 C)
int16_t getTemperature();
/// Returns pressure in Pascals (100000 = 100000 Pa = 1000 mbar)
uint32_t getPressure();
private:
uint16_t PROM[8];
int16_t t; // temperature in Celsium x100 (2000 = 20.00 C)
uint32_t p; // pressure in Pascals (100000 = 100000 Pa = 1000 mbar)
};
class BarometerSimple : public MS5607 {
public:
BarometerSimple(I2C &bus, byte subaddress = 0);
bool initialize();
/**
* Measures and updates both temperature and pressure
*/
bool update();
/// Returns temperature in Celsium x100 (2000 = 20.00 C)
int16_t getTemperature();
/// Returns pressure in Pascals (100000 = 100000 Pa = 1000 mbar)
uint16_t getPressure();
/// Returns altitude in meters ASL
uint16_t getAltitude();
uint16_t getAltitude(uint16_t pressure);
private:
uint16_t PROM[8];
int16_t t; // temperature in Celsium x100 (2000 = 20.00 C)
uint16_t p; // pressure in Pascals /4 (25000 = 100000 Pa = 1000 mbar)
};