forked from EngineerTony/Sensirion_SDP6x_pressure_sens
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSDP6x.h
More file actions
80 lines (61 loc) · 2.49 KB
/
Copy pathSDP6x.h
File metadata and controls
80 lines (61 loc) · 2.49 KB
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
/*
SDP6x - A Low Pressor Sensor Library for Arduino.
Supported Sensor modules:
SDP600 series from Sensirion - http://www.futureelectronics.com/en/Technologies/Product.aspx?ProductID=SDP610125PASENSIRIONAG1050689&IM=0
SHT2x Created by Christopher Ladden at Modern Device on December 2009.
SDP6x Modified above by Antony Burness Jun 2016.
- adapted for the I2C Pressure sensor
- using example from sensirion https://www.sensirion.com/products/differential-pressure-sensors/all-documents-of-sensirions-differential-pressure-sensors-for-download/
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef SDP6X_H
#define SDP6X_H
#include <inttypes.h>
//Checksum CRC-8 polynomial generator (to check the recieved message is undamaged)
#define POLYNOMIAL 0x131 // P(x) = x^8 + x^5 + x^4 -1 = 100110001
typedef enum {
eSDP6xAddress = 0x40, //(64)
} PRES_SENSOR_P;
typedef enum {
NO_ERROR = 0,
CHECKSUM_ERROR = 0X04,
TIMEOUT_ERROR = 0X08
} PRES_SENSOR_ERROR;
typedef enum {
ePresHoldCmd = 0xF1, //command to trigger a pressure measurement
eSoftReset = 0xFE, //command: soft reset
eReadUserReg = 0xE5, //command: read advanced user register
eWriteUserReg = 0xE4 //command: write advanced user register
} PRES_MEASUREMENT_CMD_P;
typedef enum{
RESOLUTION_9BIT = 0x00,
RESOLUTION_10BIT = 0x01,
RESOLUTION_11BIT = 0x02,
RESOLUTION_12BIT = 0x03,
RESOLUTION_13BIT = 0x04,
RESOLUTION_14BIT = 0x05,
RESOLUTION_15BIT = 0x06,
RESOLUTION_16BIT = 0x07,
} etSensorResolutions;
class SDP6xClass
{
private:
bool readSensor(uint8_t command, uint16_t* res);
PRES_SENSOR_ERROR CheckCrc(uint8_t data[], uint8_t nbrOfBytes, uint8_t checksum);
void writeSensor(uint16_t data);
public:
float GetPressureDiff(void);
void SetSensorResolution(etSensorResolutions resolution);
};
extern SDP6xClass SDP6x;
#endif