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