BMP085を入れました

Dependencies:   BMP085_2 SDFileSystem mbed

Committer:
yattu0914
Date:
Mon May 19 09:33:42 2014 +0000
Revision:
7:ba3fa64f04e9
Parent:
6:3cc5c120fbe3
test

Who changed what in which revision?

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