Dependencies:   mbed

Committer:
higedura
Date:
Mon Jan 30 08:02:30 2012 +0000
Revision:
0:b61f317f452e

        

Who changed what in which revision?

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