ok

Committer:
stepJun
Date:
Thu Jun 05 12:03:11 2014 +0000
Revision:
0:cd9ad4e6166d
ok

Who changed what in which revision?

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