ADXL345_I2C

Dependents:   jetfish robotic_fish_ver_4_9_pixy

Committer:
Reiko
Date:
Mon Jul 29 20:37:49 2013 +0000
Revision:
0:753991a08b2a
Added ADXL345_I2C code

Who changed what in which revision?

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