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