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