This repository has been archived by the owner on May 24, 2020. It is now read-only.
forked from pololu/lps-arduino
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLPS.h
110 lines (80 loc) · 3.35 KB
/
LPS.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
109
110
#ifndef LPS_h
#define LPS_h
#include <Arduino.h> // for byte data type
class LPS
{
public:
enum deviceType { device_331AP, device_25H, device_auto };
enum sa0State { sa0_low, sa0_high, sa0_auto };
// register addresses
// Note: where register names differ between the register mapping table and
// the register descriptions in the datasheets, the names from the register
// descriptions are used here.
enum regAddr
{
REF_P_XL = 0x08,
REF_P_L = 0x09,
REF_P_H = 0x0A,
WHO_AM_I = 0x0F,
RES_CONF = 0x10,
CTRL_REG1 = 0x20,
CTRL_REG2 = 0x21,
CTRL_REG3 = 0x22,
CTRL_REG4 = 0x23, // 25H
STATUS_REG = 0x27,
PRESS_OUT_XL = 0x28,
PRESS_OUT_L = 0x29,
PRESS_OUT_H = 0x2A,
TEMP_OUT_L = 0x2B,
TEMP_OUT_H = 0x2C,
FIFO_CTRL = 0x2E, // 25H
FIFO_STATUS = 0x2F, // 25H
AMP_CTRL = 0x30, // 331AP
RPDS_L = 0x39, // 25H
RPDS_H = 0x3A, // 25H
DELTA_PRESS_XL = 0x3C, // 331AP
DELTA_PRESS_L = 0x3D, // 331AP
DELTA_PRESS_H = 0x3E, // 331AP
// dummy addresses for registers in different locations on different devices;
// the library translates these based on device type
// value with sign flipped is used as index into translated_regs array
INTERRUPT_CFG = -1,
INT_SOURCE = -2,
THS_P_L = -3,
THS_P_H = -4,
// update dummy_reg_count if registers are added here!
// device-specific register addresses
LPS331AP_INTERRUPT_CFG = 0x23,
LPS331AP_INT_SOURCE = 0x24,
LPS331AP_THS_P_L = 0x25,
LPS331AP_THS_P_H = 0x26,
LPS25H_INTERRUPT_CFG = 0x24,
LPS25H_INT_SOURCE = 0x25,
LPS25H_THS_P_L = 0x30,
LPS25H_THS_P_H = 0x31,
};
LPS(void);
bool init(deviceType device = device_auto, byte sa0 = sa0_auto);
deviceType getDeviceType(void) { return _device; }
byte getAddress(void) { return address; }
void enableDefault(void);
void writeReg(int reg, byte value);
byte readReg(int reg);
float readPressureMillibars(void);
float readPressureInchesHg(void);
int32_t readPressureRaw(void);
float readTemperatureC(void);
float readTemperatureF(void);
int16_t readTemperatureRaw(void);
static float pressureToAltitudeMeters(float pressure_mbar, float altimeter_setting_mbar = 1013.25);
static float pressureToAltitudeFeet(float pressure_inHg, float altimeter_setting_inHg = 29.9213);
private:
deviceType _device; // chip type (331AP or 25H)
byte address;
static const int dummy_reg_count = 4;
regAddr translated_regs[dummy_reg_count + 1]; // index 0 not used
bool detectDeviceAndAddress(deviceType device, sa0State sa0);
bool detectDevice(deviceType device);
int testWhoAmI(byte address);
};
#endif