This library enables users to communicate with the ADXL345 accelerometer through the I2C bus on the mbed. The API names are similar and work nearly the same way as those made in the SPI libraries for the ADXL345.

Dependents:   RoboticsCatAndMouse_HumanDriver

Fork of ADXL345_I2C by Peter Swanson

Committer:
peterswanson87
Date:
Thu May 12 01:19:36 2011 +0000
Revision:
1:d9412b56f98a
Parent:
0:d0adb548714f

        

Who changed what in which revision?

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