forked from jhschwartz/sm933X
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SM9333.h
62 lines (44 loc) · 1.48 KB
/
SM9333.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
// SM9333.h
#ifndef SM9333_H
#define SM9333_H
#define P_MIN -125
#define P_MAX 125
#define b0 -16881
#define b1 397.2
#define SM9333_UNPROTECTED 0x6C
#define SM9333_CRC_PROTECTED 0x6D
struct pressureTemperaturePair {
double pressure;
double temperature;
};
class SM9333
{
public:
// consructor
SM9333();
bool begin();
// checks if the chip is connected
bool isConnected();
// Returns a pressure reading
double readPressure();
// Returns a temperature reading
double readTemperature();
struct commandSequence {
int* sequence;
int length;
};
// Returns pressure and temperature readings (they're always sent by the chip at the same time)
pressureTemperaturePair readBoth();
private:
// using the low byte and high byte sent by the chip, calculates the Pressure using bitwise math and
// also the equation provided in the datasheet.
double calculatePressure(int pressureLowBit, int pressureHighBit);
// using the low Byte and high Byte sent by the chip, calculates the Temperature using bitwise math and
// also the equation provided in the datasheet.
double calculateTemperature(int temperatureLowByte, int temperatureHighByte);
// used to write a sequence of bits to the chip
void writer(commandSequence seq);
// requests a read from the chip of numBits number of bits, and with or without CRC protection
int* doRead(int numBits, bool crcProtected, int location);
};
#endif