User | Revision | Line number | New contents of line |
gbeardall |
0:dbea5fa1cd2c
|
1
|
/**
|
gbeardall |
0:dbea5fa1cd2c
|
2
|
* @author Peter Swanson
|
gbeardall |
0:dbea5fa1cd2c
|
3
|
* A personal note from me: Jesus Christ has changed my life so much it blows my mind. I say this because
|
gbeardall |
0:dbea5fa1cd2c
|
4
|
* today, religion is thought of as something that you do or believe and has about as
|
gbeardall |
0:dbea5fa1cd2c
|
5
|
* little impact on a person as their political stance. But for me, God gives me daily
|
gbeardall |
0:dbea5fa1cd2c
|
6
|
* strength and has filled my life with the satisfaction that I could never find in any
|
gbeardall |
0:dbea5fa1cd2c
|
7
|
* of the other things that I once looked for it in.
|
gbeardall |
0:dbea5fa1cd2c
|
8
|
* If your interested, heres verse that changed my life:
|
gbeardall |
0:dbea5fa1cd2c
|
9
|
* Rom 8:1-3: "Therefore, there is now no condemnation for those who are in Christ Jesus,
|
gbeardall |
0:dbea5fa1cd2c
|
10
|
* because through Christ Jesus, the law of the Spirit who gives life has set
|
gbeardall |
0:dbea5fa1cd2c
|
11
|
* me free from the law of sin (which brings...) and death. For what the law
|
gbeardall |
0:dbea5fa1cd2c
|
12
|
* was powerless to do in that it was weakened by the flesh, God did by sending
|
gbeardall |
0:dbea5fa1cd2c
|
13
|
* His own Son in the likeness of sinful flesh to be a sin offering. And so He
|
gbeardall |
0:dbea5fa1cd2c
|
14
|
* condemned sin in the flesh in order that the righteous requirements of the
|
gbeardall |
0:dbea5fa1cd2c
|
15
|
* (God's) law might be fully met in us, who live not according to the flesh
|
gbeardall |
0:dbea5fa1cd2c
|
16
|
* but according to the Spirit."
|
gbeardall |
0:dbea5fa1cd2c
|
17
|
*
|
gbeardall |
0:dbea5fa1cd2c
|
18
|
* @section LICENSE
|
gbeardall |
0:dbea5fa1cd2c
|
19
|
*
|
gbeardall |
0:dbea5fa1cd2c
|
20
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
gbeardall |
0:dbea5fa1cd2c
|
21
|
* of this software and associated documentation files (the "Software"), to deal
|
gbeardall |
0:dbea5fa1cd2c
|
22
|
* in the Software without restriction, including without limitation the rights
|
gbeardall |
0:dbea5fa1cd2c
|
23
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
gbeardall |
0:dbea5fa1cd2c
|
24
|
* copies of the Software, and to permit persons to whom the Software is
|
gbeardall |
0:dbea5fa1cd2c
|
25
|
* furnished to do so, subject to the following conditions:
|
gbeardall |
0:dbea5fa1cd2c
|
26
|
*
|
gbeardall |
0:dbea5fa1cd2c
|
27
|
* The above copyright notice and this permission notice shall be included in
|
gbeardall |
0:dbea5fa1cd2c
|
28
|
* all copies or substantial portions of the Software.
|
gbeardall |
0:dbea5fa1cd2c
|
29
|
*
|
gbeardall |
0:dbea5fa1cd2c
|
30
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
gbeardall |
0:dbea5fa1cd2c
|
31
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
gbeardall |
0:dbea5fa1cd2c
|
32
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
gbeardall |
0:dbea5fa1cd2c
|
33
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
gbeardall |
0:dbea5fa1cd2c
|
34
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
gbeardall |
0:dbea5fa1cd2c
|
35
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
gbeardall |
0:dbea5fa1cd2c
|
36
|
* THE SOFTWARE.
|
gbeardall |
0:dbea5fa1cd2c
|
37
|
*
|
gbeardall |
0:dbea5fa1cd2c
|
38
|
* @section DESCRIPTION
|
gbeardall |
0:dbea5fa1cd2c
|
39
|
*
|
gbeardall |
0:dbea5fa1cd2c
|
40
|
* ADXL345, triple axis, I2C interface, accelerometer.
|
gbeardall |
0:dbea5fa1cd2c
|
41
|
*
|
gbeardall |
0:dbea5fa1cd2c
|
42
|
* Datasheet:
|
gbeardall |
0:dbea5fa1cd2c
|
43
|
*
|
gbeardall |
0:dbea5fa1cd2c
|
44
|
* http://www.analog.com/static/imported-files/data_sheets/ADXL345.pdf
|
gbeardall |
0:dbea5fa1cd2c
|
45
|
*/
|
gbeardall |
0:dbea5fa1cd2c
|
46
|
|
gbeardall |
0:dbea5fa1cd2c
|
47
|
/**
|
gbeardall |
0:dbea5fa1cd2c
|
48
|
* Includes
|
gbeardall |
0:dbea5fa1cd2c
|
49
|
*/
|
gbeardall |
0:dbea5fa1cd2c
|
50
|
#include "ADXL345_I2C.h"
|
gbeardall |
0:dbea5fa1cd2c
|
51
|
|
gbeardall |
0:dbea5fa1cd2c
|
52
|
//#include "mbed.h"
|
gbeardall |
0:dbea5fa1cd2c
|
53
|
|
gbeardall |
0:dbea5fa1cd2c
|
54
|
ADXL345_I2C::ADXL345_I2C(PinName sda, PinName scl) : i2c_(sda, scl) {
|
gbeardall |
0:dbea5fa1cd2c
|
55
|
|
gbeardall |
0:dbea5fa1cd2c
|
56
|
//400kHz, allowing us to use the fastest data rates.
|
gbeardall |
0:dbea5fa1cd2c
|
57
|
i2c_.frequency(400000);
|
gbeardall |
0:dbea5fa1cd2c
|
58
|
// initialize the BW data rate
|
gbeardall |
0:dbea5fa1cd2c
|
59
|
char tx[2];
|
gbeardall |
0:dbea5fa1cd2c
|
60
|
tx[0] = ADXL345_BW_RATE_REG;
|
gbeardall |
0:dbea5fa1cd2c
|
61
|
tx[1] = ADXL345_1600HZ; //value greater than or equal to 0x0A is written into the rate bits (Bit D3 through Bit D0) in the BW_RATE register
|
gbeardall |
0:dbea5fa1cd2c
|
62
|
i2c_.write( ADXL345_I2C_WRITE , tx, 2);
|
gbeardall |
0:dbea5fa1cd2c
|
63
|
|
gbeardall |
0:dbea5fa1cd2c
|
64
|
//Data format (for +-16g) - This is done by setting Bit D3 of the DATA_FORMAT register (Address 0x31) and writing a value of 0x03 to the range bits (Bit D1 and Bit D0) of the DATA_FORMAT register (Address 0x31).
|
gbeardall |
0:dbea5fa1cd2c
|
65
|
|
gbeardall |
0:dbea5fa1cd2c
|
66
|
char rx[2];
|
gbeardall |
0:dbea5fa1cd2c
|
67
|
rx[0] = ADXL345_DATA_FORMAT_REG;
|
gbeardall |
0:dbea5fa1cd2c
|
68
|
rx[1] = 0x0B;
|
gbeardall |
0:dbea5fa1cd2c
|
69
|
// full res and +_16g
|
gbeardall |
0:dbea5fa1cd2c
|
70
|
i2c_.write( ADXL345_I2C_WRITE , rx, 2);
|
gbeardall |
0:dbea5fa1cd2c
|
71
|
|
gbeardall |
0:dbea5fa1cd2c
|
72
|
// Set Offset - programmed into the OFSX, OFSY, and OFXZ registers, respectively, as 0xFD, 0x03 and 0xFE.
|
gbeardall |
0:dbea5fa1cd2c
|
73
|
char x[2];
|
gbeardall |
0:dbea5fa1cd2c
|
74
|
x[0] = ADXL345_OFSX_REG ;
|
gbeardall |
0:dbea5fa1cd2c
|
75
|
x[1] = 0xFD;
|
gbeardall |
0:dbea5fa1cd2c
|
76
|
i2c_.write( ADXL345_I2C_WRITE , x, 2);
|
gbeardall |
0:dbea5fa1cd2c
|
77
|
char y[2];
|
gbeardall |
0:dbea5fa1cd2c
|
78
|
y[0] = ADXL345_OFSY_REG ;
|
gbeardall |
0:dbea5fa1cd2c
|
79
|
y[1] = 0x03;
|
gbeardall |
0:dbea5fa1cd2c
|
80
|
i2c_.write( ADXL345_I2C_WRITE , y, 2);
|
gbeardall |
0:dbea5fa1cd2c
|
81
|
char z[2];
|
gbeardall |
0:dbea5fa1cd2c
|
82
|
z[0] = ADXL345_OFSZ_REG ;
|
gbeardall |
0:dbea5fa1cd2c
|
83
|
z[1] = 0xFE;
|
gbeardall |
0:dbea5fa1cd2c
|
84
|
i2c_.write( ADXL345_I2C_WRITE , z, 2);
|
gbeardall |
0:dbea5fa1cd2c
|
85
|
}
|
gbeardall |
0:dbea5fa1cd2c
|
86
|
|
gbeardall |
0:dbea5fa1cd2c
|
87
|
|
gbeardall |
0:dbea5fa1cd2c
|
88
|
char ADXL345_I2C::SingleByteRead(char address){
|
gbeardall |
0:dbea5fa1cd2c
|
89
|
char tx = address;
|
gbeardall |
0:dbea5fa1cd2c
|
90
|
char output;
|
gbeardall |
0:dbea5fa1cd2c
|
91
|
i2c_.write( ADXL345_I2C_WRITE , &tx, 1); //tell it what you want to read
|
gbeardall |
0:dbea5fa1cd2c
|
92
|
i2c_.read( ADXL345_I2C_READ , &output, 1); //tell it where to store the data
|
gbeardall |
0:dbea5fa1cd2c
|
93
|
return output;
|
gbeardall |
0:dbea5fa1cd2c
|
94
|
|
gbeardall |
0:dbea5fa1cd2c
|
95
|
}
|
gbeardall |
0:dbea5fa1cd2c
|
96
|
|
gbeardall |
0:dbea5fa1cd2c
|
97
|
|
gbeardall |
0:dbea5fa1cd2c
|
98
|
/*
|
gbeardall |
0:dbea5fa1cd2c
|
99
|
***info on the i2c_.write***
|
gbeardall |
0:dbea5fa1cd2c
|
100
|
address 8-bit I2C slave address [ addr | 0 ]
|
gbeardall |
0:dbea5fa1cd2c
|
101
|
data Pointer to the byte-array data to send
|
gbeardall |
0:dbea5fa1cd2c
|
102
|
length Number of bytes to send
|
gbeardall |
0:dbea5fa1cd2c
|
103
|
repeated Repeated start, true - do not send stop at end
|
gbeardall |
0:dbea5fa1cd2c
|
104
|
returns 0 on success (ack), or non-0 on failure (nack)
|
gbeardall |
0:dbea5fa1cd2c
|
105
|
*/
|
gbeardall |
0:dbea5fa1cd2c
|
106
|
|
gbeardall |
0:dbea5fa1cd2c
|
107
|
int ADXL345_I2C::SingleByteWrite(char address, char data){
|
gbeardall |
0:dbea5fa1cd2c
|
108
|
int ack = 0;
|
gbeardall |
0:dbea5fa1cd2c
|
109
|
char tx[2];
|
gbeardall |
0:dbea5fa1cd2c
|
110
|
tx[0] = address;
|
gbeardall |
0:dbea5fa1cd2c
|
111
|
tx[1] = data;
|
gbeardall |
0:dbea5fa1cd2c
|
112
|
return ack | i2c_.write( ADXL345_I2C_WRITE , tx, 2);
|
gbeardall |
0:dbea5fa1cd2c
|
113
|
}
|
gbeardall |
0:dbea5fa1cd2c
|
114
|
|
gbeardall |
0:dbea5fa1cd2c
|
115
|
|
gbeardall |
0:dbea5fa1cd2c
|
116
|
|
gbeardall |
0:dbea5fa1cd2c
|
117
|
void ADXL345_I2C::multiByteRead(char address, char* output, int size) {
|
gbeardall |
0:dbea5fa1cd2c
|
118
|
i2c_.write( ADXL345_I2C_WRITE, &address, 1); //tell it where to read from
|
gbeardall |
0:dbea5fa1cd2c
|
119
|
i2c_.read( ADXL345_I2C_READ , output, size); //tell it where to store the data read
|
gbeardall |
0:dbea5fa1cd2c
|
120
|
}
|
gbeardall |
0:dbea5fa1cd2c
|
121
|
|
gbeardall |
0:dbea5fa1cd2c
|
122
|
|
gbeardall |
0:dbea5fa1cd2c
|
123
|
int ADXL345_I2C::multiByteWrite(char address, char* ptr_data, int size) {
|
gbeardall |
0:dbea5fa1cd2c
|
124
|
int ack;
|
gbeardall |
0:dbea5fa1cd2c
|
125
|
|
gbeardall |
0:dbea5fa1cd2c
|
126
|
ack = i2c_.write( ADXL345_I2C_WRITE, &address, 1); //tell it where to write to
|
gbeardall |
0:dbea5fa1cd2c
|
127
|
return ack | i2c_.write( ADXL345_I2C_READ, ptr_data, size); //tell it what data to write
|
gbeardall |
0:dbea5fa1cd2c
|
128
|
|
gbeardall |
0:dbea5fa1cd2c
|
129
|
}
|
gbeardall |
0:dbea5fa1cd2c
|
130
|
|
gbeardall |
0:dbea5fa1cd2c
|
131
|
|
gbeardall |
0:dbea5fa1cd2c
|
132
|
void ADXL345_I2C::getOutput(int* readings){
|
gbeardall |
0:dbea5fa1cd2c
|
133
|
char buffer[6];
|
gbeardall |
0:dbea5fa1cd2c
|
134
|
multiByteRead(ADXL345_DATAX0_REG, buffer, 6);
|
gbeardall |
0:dbea5fa1cd2c
|
135
|
|
gbeardall |
0:dbea5fa1cd2c
|
136
|
readings[0] = (int)buffer[1] << 8 | (int)buffer[0];
|
gbeardall |
0:dbea5fa1cd2c
|
137
|
readings[1] = (int)buffer[3] << 8 | (int)buffer[2];
|
gbeardall |
0:dbea5fa1cd2c
|
138
|
readings[2] = (int)buffer[5] << 8 | (int)buffer[4];
|
gbeardall |
0:dbea5fa1cd2c
|
139
|
|
gbeardall |
0:dbea5fa1cd2c
|
140
|
}
|
gbeardall |
0:dbea5fa1cd2c
|
141
|
|
gbeardall |
0:dbea5fa1cd2c
|
142
|
|
gbeardall |
0:dbea5fa1cd2c
|
143
|
|
gbeardall |
0:dbea5fa1cd2c
|
144
|
char ADXL345_I2C::getDeviceID() {
|
gbeardall |
0:dbea5fa1cd2c
|
145
|
return SingleByteRead(ADXL345_DEVID_REG);
|
gbeardall |
0:dbea5fa1cd2c
|
146
|
}
|
gbeardall |
0:dbea5fa1cd2c
|
147
|
//
|
gbeardall |
0:dbea5fa1cd2c
|
148
|
int ADXL345_I2C::setPowerMode(char mode) {
|
gbeardall |
0:dbea5fa1cd2c
|
149
|
|
gbeardall |
0:dbea5fa1cd2c
|
150
|
//Get the current register contents, so we don't clobber the rate value.
|
gbeardall |
0:dbea5fa1cd2c
|
151
|
char registerContents = (mode << 4) | SingleByteRead(ADXL345_BW_RATE_REG);
|
gbeardall |
0:dbea5fa1cd2c
|
152
|
|
gbeardall |
0:dbea5fa1cd2c
|
153
|
return SingleByteWrite(ADXL345_BW_RATE_REG, registerContents);
|
gbeardall |
0:dbea5fa1cd2c
|
154
|
|
gbeardall |
0:dbea5fa1cd2c
|
155
|
}
|
gbeardall |
0:dbea5fa1cd2c
|
156
|
|
gbeardall |
0:dbea5fa1cd2c
|
157
|
char ADXL345_I2C::getPowerControl() {
|
gbeardall |
0:dbea5fa1cd2c
|
158
|
return SingleByteRead(ADXL345_POWER_CTL_REG);
|
gbeardall |
0:dbea5fa1cd2c
|
159
|
}
|
gbeardall |
0:dbea5fa1cd2c
|
160
|
|
gbeardall |
0:dbea5fa1cd2c
|
161
|
int ADXL345_I2C::setPowerControl(char settings) {
|
gbeardall |
0:dbea5fa1cd2c
|
162
|
return SingleByteWrite(ADXL345_POWER_CTL_REG, settings);
|
gbeardall |
0:dbea5fa1cd2c
|
163
|
|
gbeardall |
0:dbea5fa1cd2c
|
164
|
}
|
gbeardall |
0:dbea5fa1cd2c
|
165
|
|
gbeardall |
0:dbea5fa1cd2c
|
166
|
|
gbeardall |
0:dbea5fa1cd2c
|
167
|
|
gbeardall |
0:dbea5fa1cd2c
|
168
|
char ADXL345_I2C::getDataFormatControl(void){
|
gbeardall |
0:dbea5fa1cd2c
|
169
|
|
gbeardall |
0:dbea5fa1cd2c
|
170
|
return SingleByteRead(ADXL345_DATA_FORMAT_REG);
|
gbeardall |
0:dbea5fa1cd2c
|
171
|
}
|
gbeardall |
0:dbea5fa1cd2c
|
172
|
|
gbeardall |
0:dbea5fa1cd2c
|
173
|
int ADXL345_I2C::setDataFormatControl(char settings){
|
gbeardall |
0:dbea5fa1cd2c
|
174
|
|
gbeardall |
0:dbea5fa1cd2c
|
175
|
return SingleByteWrite(ADXL345_DATA_FORMAT_REG, settings);
|
gbeardall |
0:dbea5fa1cd2c
|
176
|
|
gbeardall |
0:dbea5fa1cd2c
|
177
|
}
|
gbeardall |
0:dbea5fa1cd2c
|
178
|
|
gbeardall |
0:dbea5fa1cd2c
|
179
|
int ADXL345_I2C::setDataRate(char rate) {
|
gbeardall |
0:dbea5fa1cd2c
|
180
|
|
gbeardall |
0:dbea5fa1cd2c
|
181
|
//Get the current register contents, so we don't clobber the power bit.
|
gbeardall |
0:dbea5fa1cd2c
|
182
|
char registerContents = SingleByteRead(ADXL345_BW_RATE_REG);
|
gbeardall |
0:dbea5fa1cd2c
|
183
|
|
gbeardall |
0:dbea5fa1cd2c
|
184
|
registerContents &= 0x10;
|
gbeardall |
0:dbea5fa1cd2c
|
185
|
registerContents |= rate;
|
gbeardall |
0:dbea5fa1cd2c
|
186
|
|
gbeardall |
0:dbea5fa1cd2c
|
187
|
return SingleByteWrite(ADXL345_BW_RATE_REG, registerContents);
|
gbeardall |
0:dbea5fa1cd2c
|
188
|
|
gbeardall |
0:dbea5fa1cd2c
|
189
|
}
|
gbeardall |
0:dbea5fa1cd2c
|
190
|
|
gbeardall |
0:dbea5fa1cd2c
|
191
|
|
gbeardall |
0:dbea5fa1cd2c
|
192
|
char ADXL345_I2C::getOffset(char axis) {
|
gbeardall |
0:dbea5fa1cd2c
|
193
|
|
gbeardall |
0:dbea5fa1cd2c
|
194
|
char address = 0;
|
gbeardall |
0:dbea5fa1cd2c
|
195
|
|
gbeardall |
0:dbea5fa1cd2c
|
196
|
if (axis == ADXL345_X) {
|
gbeardall |
0:dbea5fa1cd2c
|
197
|
address = ADXL345_OFSX_REG;
|
gbeardall |
0:dbea5fa1cd2c
|
198
|
} else if (axis == ADXL345_Y) {
|
gbeardall |
0:dbea5fa1cd2c
|
199
|
address = ADXL345_OFSY_REG;
|
gbeardall |
0:dbea5fa1cd2c
|
200
|
} else if (axis == ADXL345_Z) {
|
gbeardall |
0:dbea5fa1cd2c
|
201
|
address = ADXL345_OFSZ_REG;
|
gbeardall |
0:dbea5fa1cd2c
|
202
|
}
|
gbeardall |
0:dbea5fa1cd2c
|
203
|
|
gbeardall |
0:dbea5fa1cd2c
|
204
|
return SingleByteRead(address);
|
gbeardall |
0:dbea5fa1cd2c
|
205
|
}
|
gbeardall |
0:dbea5fa1cd2c
|
206
|
|
gbeardall |
0:dbea5fa1cd2c
|
207
|
int ADXL345_I2C::setOffset(char axis, char offset) {
|
gbeardall |
0:dbea5fa1cd2c
|
208
|
|
gbeardall |
0:dbea5fa1cd2c
|
209
|
char address = 0;
|
gbeardall |
0:dbea5fa1cd2c
|
210
|
|
gbeardall |
0:dbea5fa1cd2c
|
211
|
if (axis == ADXL345_X) {
|
gbeardall |
0:dbea5fa1cd2c
|
212
|
address = ADXL345_OFSX_REG;
|
gbeardall |
0:dbea5fa1cd2c
|
213
|
} else if (axis == ADXL345_Y) {
|
gbeardall |
0:dbea5fa1cd2c
|
214
|
address = ADXL345_OFSY_REG;
|
gbeardall |
0:dbea5fa1cd2c
|
215
|
} else if (axis == ADXL345_Z) {
|
gbeardall |
0:dbea5fa1cd2c
|
216
|
address = ADXL345_OFSZ_REG;
|
gbeardall |
0:dbea5fa1cd2c
|
217
|
}
|
gbeardall |
0:dbea5fa1cd2c
|
218
|
|
gbeardall |
0:dbea5fa1cd2c
|
219
|
return SingleByteWrite(address, offset);
|
gbeardall |
0:dbea5fa1cd2c
|
220
|
|
gbeardall |
0:dbea5fa1cd2c
|
221
|
}
|
gbeardall |
0:dbea5fa1cd2c
|
222
|
|
gbeardall |
0:dbea5fa1cd2c
|
223
|
|
gbeardall |
0:dbea5fa1cd2c
|
224
|
char ADXL345_I2C::getFifoControl(void){
|
gbeardall |
0:dbea5fa1cd2c
|
225
|
|
gbeardall |
0:dbea5fa1cd2c
|
226
|
return SingleByteRead(ADXL345_FIFO_CTL);
|
gbeardall |
0:dbea5fa1cd2c
|
227
|
|
gbeardall |
0:dbea5fa1cd2c
|
228
|
}
|
gbeardall |
0:dbea5fa1cd2c
|
229
|
|
gbeardall |
0:dbea5fa1cd2c
|
230
|
int ADXL345_I2C::setFifoControl(char settings){
|
gbeardall |
0:dbea5fa1cd2c
|
231
|
return SingleByteWrite(ADXL345_FIFO_STATUS, settings);
|
gbeardall |
0:dbea5fa1cd2c
|
232
|
|
gbeardall |
0:dbea5fa1cd2c
|
233
|
}
|
gbeardall |
0:dbea5fa1cd2c
|
234
|
|
gbeardall |
0:dbea5fa1cd2c
|
235
|
char ADXL345_I2C::getFifoStatus(void){
|
gbeardall |
0:dbea5fa1cd2c
|
236
|
|
gbeardall |
0:dbea5fa1cd2c
|
237
|
return SingleByteRead(ADXL345_FIFO_STATUS);
|
gbeardall |
0:dbea5fa1cd2c
|
238
|
|
gbeardall |
0:dbea5fa1cd2c
|
239
|
}
|
gbeardall |
0:dbea5fa1cd2c
|
240
|
|
gbeardall |
0:dbea5fa1cd2c
|
241
|
|
gbeardall |
0:dbea5fa1cd2c
|
242
|
|
gbeardall |
0:dbea5fa1cd2c
|
243
|
char ADXL345_I2C::getTapThreshold(void) {
|
gbeardall |
0:dbea5fa1cd2c
|
244
|
|
gbeardall |
0:dbea5fa1cd2c
|
245
|
return SingleByteRead(ADXL345_THRESH_TAP_REG);
|
gbeardall |
0:dbea5fa1cd2c
|
246
|
}
|
gbeardall |
0:dbea5fa1cd2c
|
247
|
|
gbeardall |
0:dbea5fa1cd2c
|
248
|
int ADXL345_I2C::setTapThreshold(char threshold) {
|
gbeardall |
0:dbea5fa1cd2c
|
249
|
|
gbeardall |
0:dbea5fa1cd2c
|
250
|
return SingleByteWrite(ADXL345_THRESH_TAP_REG, threshold);
|
gbeardall |
0:dbea5fa1cd2c
|
251
|
|
gbeardall |
0:dbea5fa1cd2c
|
252
|
}
|
gbeardall |
0:dbea5fa1cd2c
|
253
|
|
gbeardall |
0:dbea5fa1cd2c
|
254
|
|
gbeardall |
0:dbea5fa1cd2c
|
255
|
float ADXL345_I2C::getTapDuration(void) {
|
gbeardall |
0:dbea5fa1cd2c
|
256
|
|
gbeardall |
0:dbea5fa1cd2c
|
257
|
return (float)SingleByteRead(ADXL345_DUR_REG)*625;
|
gbeardall |
0:dbea5fa1cd2c
|
258
|
}
|
gbeardall |
0:dbea5fa1cd2c
|
259
|
|
gbeardall |
0:dbea5fa1cd2c
|
260
|
int ADXL345_I2C::setTapDuration(short int duration_us) {
|
gbeardall |
0:dbea5fa1cd2c
|
261
|
|
gbeardall |
0:dbea5fa1cd2c
|
262
|
short int tapDuration = duration_us / 625;
|
gbeardall |
0:dbea5fa1cd2c
|
263
|
char tapChar[2];
|
gbeardall |
0:dbea5fa1cd2c
|
264
|
tapChar[0] = (tapDuration & 0x00FF);
|
gbeardall |
0:dbea5fa1cd2c
|
265
|
tapChar[1] = (tapDuration >> 8) & 0x00FF;
|
gbeardall |
0:dbea5fa1cd2c
|
266
|
return multiByteWrite(ADXL345_DUR_REG, tapChar, 2);
|
gbeardall |
0:dbea5fa1cd2c
|
267
|
|
gbeardall |
0:dbea5fa1cd2c
|
268
|
}
|
gbeardall |
0:dbea5fa1cd2c
|
269
|
|
gbeardall |
0:dbea5fa1cd2c
|
270
|
float ADXL345_I2C::getTapLatency(void) {
|
gbeardall |
0:dbea5fa1cd2c
|
271
|
|
gbeardall |
0:dbea5fa1cd2c
|
272
|
return (float)SingleByteRead(ADXL345_LATENT_REG)*1.25;
|
gbeardall |
0:dbea5fa1cd2c
|
273
|
}
|
gbeardall |
0:dbea5fa1cd2c
|
274
|
|
gbeardall |
0:dbea5fa1cd2c
|
275
|
int ADXL345_I2C::setTapLatency(short int latency_ms) {
|
gbeardall |
0:dbea5fa1cd2c
|
276
|
|
gbeardall |
0:dbea5fa1cd2c
|
277
|
latency_ms = latency_ms / 1.25;
|
gbeardall |
0:dbea5fa1cd2c
|
278
|
char latChar[2];
|
gbeardall |
0:dbea5fa1cd2c
|
279
|
latChar[0] = (latency_ms & 0x00FF);
|
gbeardall |
0:dbea5fa1cd2c
|
280
|
latChar[1] = (latency_ms << 8) & 0xFF00;
|
gbeardall |
0:dbea5fa1cd2c
|
281
|
return multiByteWrite(ADXL345_LATENT_REG, latChar, 2);
|
gbeardall |
0:dbea5fa1cd2c
|
282
|
|
gbeardall |
0:dbea5fa1cd2c
|
283
|
}
|
gbeardall |
0:dbea5fa1cd2c
|
284
|
|
gbeardall |
0:dbea5fa1cd2c
|
285
|
float ADXL345_I2C::getWindowTime(void) {
|
gbeardall |
0:dbea5fa1cd2c
|
286
|
|
gbeardall |
0:dbea5fa1cd2c
|
287
|
return (float)SingleByteRead(ADXL345_WINDOW_REG)*1.25;
|
gbeardall |
0:dbea5fa1cd2c
|
288
|
}
|
gbeardall |
0:dbea5fa1cd2c
|
289
|
|
gbeardall |
0:dbea5fa1cd2c
|
290
|
int ADXL345_I2C::setWindowTime(short int window_ms) {
|
gbeardall |
0:dbea5fa1cd2c
|
291
|
|
gbeardall |
0:dbea5fa1cd2c
|
292
|
window_ms = window_ms / 1.25;
|
gbeardall |
0:dbea5fa1cd2c
|
293
|
char windowChar[2];
|
gbeardall |
0:dbea5fa1cd2c
|
294
|
windowChar[0] = (window_ms & 0x00FF);
|
gbeardall |
0:dbea5fa1cd2c
|
295
|
windowChar[1] = ((window_ms << 8) & 0xFF00);
|
gbeardall |
0:dbea5fa1cd2c
|
296
|
return multiByteWrite(ADXL345_WINDOW_REG, windowChar, 2);
|
gbeardall |
0:dbea5fa1cd2c
|
297
|
|
gbeardall |
0:dbea5fa1cd2c
|
298
|
}
|
gbeardall |
0:dbea5fa1cd2c
|
299
|
|
gbeardall |
0:dbea5fa1cd2c
|
300
|
char ADXL345_I2C::getActivityThreshold(void) {
|
gbeardall |
0:dbea5fa1cd2c
|
301
|
|
gbeardall |
0:dbea5fa1cd2c
|
302
|
return SingleByteRead(ADXL345_THRESH_ACT_REG);
|
gbeardall |
0:dbea5fa1cd2c
|
303
|
}
|
gbeardall |
0:dbea5fa1cd2c
|
304
|
|
gbeardall |
0:dbea5fa1cd2c
|
305
|
int ADXL345_I2C::setActivityThreshold(char threshold) {
|
gbeardall |
0:dbea5fa1cd2c
|
306
|
return SingleByteWrite(ADXL345_THRESH_ACT_REG, threshold);
|
gbeardall |
0:dbea5fa1cd2c
|
307
|
|
gbeardall |
0:dbea5fa1cd2c
|
308
|
}
|
gbeardall |
0:dbea5fa1cd2c
|
309
|
|
gbeardall |
0:dbea5fa1cd2c
|
310
|
char ADXL345_I2C::getInactivityThreshold(void) {
|
gbeardall |
0:dbea5fa1cd2c
|
311
|
return SingleByteRead(ADXL345_THRESH_INACT_REG);
|
gbeardall |
0:dbea5fa1cd2c
|
312
|
|
gbeardall |
0:dbea5fa1cd2c
|
313
|
}
|
gbeardall |
0:dbea5fa1cd2c
|
314
|
|
gbeardall |
0:dbea5fa1cd2c
|
315
|
//int FUNCTION(short int * ptr_Output)
|
gbeardall |
0:dbea5fa1cd2c
|
316
|
//short int FUNCTION ()
|
gbeardall |
0:dbea5fa1cd2c
|
317
|
|
gbeardall |
0:dbea5fa1cd2c
|
318
|
int ADXL345_I2C::setInactivityThreshold(char threshold) {
|
gbeardall |
0:dbea5fa1cd2c
|
319
|
return SingleByteWrite(ADXL345_THRESH_INACT_REG, threshold);
|
gbeardall |
0:dbea5fa1cd2c
|
320
|
|
gbeardall |
0:dbea5fa1cd2c
|
321
|
}
|
gbeardall |
0:dbea5fa1cd2c
|
322
|
|
gbeardall |
0:dbea5fa1cd2c
|
323
|
char ADXL345_I2C::getTimeInactivity(void) {
|
gbeardall |
0:dbea5fa1cd2c
|
324
|
|
gbeardall |
0:dbea5fa1cd2c
|
325
|
return SingleByteRead(ADXL345_TIME_INACT_REG);
|
gbeardall |
0:dbea5fa1cd2c
|
326
|
|
gbeardall |
0:dbea5fa1cd2c
|
327
|
}
|
gbeardall |
0:dbea5fa1cd2c
|
328
|
|
gbeardall |
0:dbea5fa1cd2c
|
329
|
int ADXL345_I2C::setTimeInactivity(char timeInactivity) {
|
gbeardall |
0:dbea5fa1cd2c
|
330
|
return SingleByteWrite(ADXL345_TIME_INACT_REG, timeInactivity);
|
gbeardall |
0:dbea5fa1cd2c
|
331
|
|
gbeardall |
0:dbea5fa1cd2c
|
332
|
}
|
gbeardall |
0:dbea5fa1cd2c
|
333
|
|
gbeardall |
0:dbea5fa1cd2c
|
334
|
char ADXL345_I2C::getActivityInactivityControl(void) {
|
gbeardall |
0:dbea5fa1cd2c
|
335
|
|
gbeardall |
0:dbea5fa1cd2c
|
336
|
return SingleByteRead(ADXL345_ACT_INACT_CTL_REG);
|
gbeardall |
0:dbea5fa1cd2c
|
337
|
|
gbeardall |
0:dbea5fa1cd2c
|
338
|
}
|
gbeardall |
0:dbea5fa1cd2c
|
339
|
|
gbeardall |
0:dbea5fa1cd2c
|
340
|
int ADXL345_I2C::setActivityInactivityControl(char settings) {
|
gbeardall |
0:dbea5fa1cd2c
|
341
|
return SingleByteWrite(ADXL345_ACT_INACT_CTL_REG, settings);
|
gbeardall |
0:dbea5fa1cd2c
|
342
|
|
gbeardall |
0:dbea5fa1cd2c
|
343
|
}
|
gbeardall |
0:dbea5fa1cd2c
|
344
|
|
gbeardall |
0:dbea5fa1cd2c
|
345
|
char ADXL345_I2C::getFreefallThreshold(void) {
|
gbeardall |
0:dbea5fa1cd2c
|
346
|
|
gbeardall |
0:dbea5fa1cd2c
|
347
|
return SingleByteRead(ADXL345_THRESH_FF_REG);
|
gbeardall |
0:dbea5fa1cd2c
|
348
|
|
gbeardall |
0:dbea5fa1cd2c
|
349
|
}
|
gbeardall |
0:dbea5fa1cd2c
|
350
|
|
gbeardall |
0:dbea5fa1cd2c
|
351
|
int ADXL345_I2C::setFreefallThreshold(char threshold) {
|
gbeardall |
0:dbea5fa1cd2c
|
352
|
return SingleByteWrite(ADXL345_THRESH_FF_REG, threshold);
|
gbeardall |
0:dbea5fa1cd2c
|
353
|
|
gbeardall |
0:dbea5fa1cd2c
|
354
|
}
|
gbeardall |
0:dbea5fa1cd2c
|
355
|
|
gbeardall |
0:dbea5fa1cd2c
|
356
|
char ADXL345_I2C::getFreefallTime(void) {
|
gbeardall |
0:dbea5fa1cd2c
|
357
|
|
gbeardall |
0:dbea5fa1cd2c
|
358
|
return SingleByteRead(ADXL345_TIME_FF_REG)*5;
|
gbeardall |
0:dbea5fa1cd2c
|
359
|
|
gbeardall |
0:dbea5fa1cd2c
|
360
|
}
|
gbeardall |
0:dbea5fa1cd2c
|
361
|
|
gbeardall |
0:dbea5fa1cd2c
|
362
|
int ADXL345_I2C::setFreefallTime(short int freefallTime_ms) {
|
gbeardall |
0:dbea5fa1cd2c
|
363
|
freefallTime_ms = freefallTime_ms / 5;
|
gbeardall |
0:dbea5fa1cd2c
|
364
|
char fallChar[2];
|
gbeardall |
0:dbea5fa1cd2c
|
365
|
fallChar[0] = (freefallTime_ms & 0x00FF);
|
gbeardall |
0:dbea5fa1cd2c
|
366
|
fallChar[1] = (freefallTime_ms << 8) & 0xFF00;
|
gbeardall |
0:dbea5fa1cd2c
|
367
|
|
gbeardall |
0:dbea5fa1cd2c
|
368
|
return multiByteWrite(ADXL345_TIME_FF_REG, fallChar, 2);
|
gbeardall |
0:dbea5fa1cd2c
|
369
|
|
gbeardall |
0:dbea5fa1cd2c
|
370
|
}
|
gbeardall |
0:dbea5fa1cd2c
|
371
|
|
gbeardall |
0:dbea5fa1cd2c
|
372
|
char ADXL345_I2C::getTapAxisControl(void) {
|
gbeardall |
0:dbea5fa1cd2c
|
373
|
|
gbeardall |
0:dbea5fa1cd2c
|
374
|
return SingleByteRead(ADXL345_TAP_AXES_REG);
|
gbeardall |
0:dbea5fa1cd2c
|
375
|
|
gbeardall |
0:dbea5fa1cd2c
|
376
|
}
|
gbeardall |
0:dbea5fa1cd2c
|
377
|
|
gbeardall |
0:dbea5fa1cd2c
|
378
|
int ADXL345_I2C::setTapAxisControl(char settings) {
|
gbeardall |
0:dbea5fa1cd2c
|
379
|
return SingleByteWrite(ADXL345_TAP_AXES_REG, settings);
|
gbeardall |
0:dbea5fa1cd2c
|
380
|
|
gbeardall |
0:dbea5fa1cd2c
|
381
|
}
|
gbeardall |
0:dbea5fa1cd2c
|
382
|
|
gbeardall |
0:dbea5fa1cd2c
|
383
|
char ADXL345_I2C::getTapSource(void) {
|
gbeardall |
0:dbea5fa1cd2c
|
384
|
|
gbeardall |
0:dbea5fa1cd2c
|
385
|
return SingleByteRead(ADXL345_ACT_TAP_STATUS_REG);
|
gbeardall |
0:dbea5fa1cd2c
|
386
|
|
gbeardall |
0:dbea5fa1cd2c
|
387
|
}
|
gbeardall |
0:dbea5fa1cd2c
|
388
|
|
gbeardall |
0:dbea5fa1cd2c
|
389
|
|
gbeardall |
0:dbea5fa1cd2c
|
390
|
|
gbeardall |
0:dbea5fa1cd2c
|
391
|
char ADXL345_I2C::getInterruptEnableControl(void) {
|
gbeardall |
0:dbea5fa1cd2c
|
392
|
|
gbeardall |
0:dbea5fa1cd2c
|
393
|
return SingleByteRead(ADXL345_INT_ENABLE_REG);
|
gbeardall |
0:dbea5fa1cd2c
|
394
|
|
gbeardall |
0:dbea5fa1cd2c
|
395
|
}
|
gbeardall |
0:dbea5fa1cd2c
|
396
|
|
gbeardall |
0:dbea5fa1cd2c
|
397
|
int ADXL345_I2C::setInterruptEnableControl(char settings) {
|
gbeardall |
0:dbea5fa1cd2c
|
398
|
return SingleByteWrite(ADXL345_INT_ENABLE_REG, settings);
|
gbeardall |
0:dbea5fa1cd2c
|
399
|
|
gbeardall |
0:dbea5fa1cd2c
|
400
|
}
|
gbeardall |
0:dbea5fa1cd2c
|
401
|
|
gbeardall |
0:dbea5fa1cd2c
|
402
|
char ADXL345_I2C::getInterruptMappingControl(void) {
|
gbeardall |
0:dbea5fa1cd2c
|
403
|
|
gbeardall |
0:dbea5fa1cd2c
|
404
|
return SingleByteRead(ADXL345_INT_MAP_REG);
|
gbeardall |
0:dbea5fa1cd2c
|
405
|
|
gbeardall |
0:dbea5fa1cd2c
|
406
|
}
|
gbeardall |
0:dbea5fa1cd2c
|
407
|
|
gbeardall |
0:dbea5fa1cd2c
|
408
|
int ADXL345_I2C::setInterruptMappingControl(char settings) {
|
gbeardall |
0:dbea5fa1cd2c
|
409
|
return SingleByteWrite(ADXL345_INT_MAP_REG, settings);
|
gbeardall |
0:dbea5fa1cd2c
|
410
|
|
gbeardall |
0:dbea5fa1cd2c
|
411
|
}
|
gbeardall |
0:dbea5fa1cd2c
|
412
|
|
gbeardall |
0:dbea5fa1cd2c
|
413
|
char ADXL345_I2C::getInterruptSource(void){
|
gbeardall |
0:dbea5fa1cd2c
|
414
|
|
gbeardall |
0:dbea5fa1cd2c
|
415
|
return SingleByteRead(ADXL345_INT_SOURCE_REG);
|
gbeardall |
0:dbea5fa1cd2c
|
416
|
|
gbeardall |
0:dbea5fa1cd2c
|
417
|
}
|
gbeardall |
0:dbea5fa1cd2c
|
418
|
|
gbeardall |
0:dbea5fa1cd2c
|
419
|
|
gbeardall |
0:dbea5fa1cd2c
|
420
|
|
gbeardall |
0:dbea5fa1cd2c
|
421
|
|