2013

Dependencies:   BMP085_2 SDFileSystem mbed

Fork of cansat new by takaaki yatsuzuka

Committer:
kyattonippu
Date:
Thu Jul 17 09:21:55 2014 +0000
Revision:
8:8c60a5cd8396
Parent:
6:3cc5c120fbe3
2013

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
yattu0914 6:3cc5c120fbe3 51 #ifndef ADXL345_I2C_H
yattu0914 6:3cc5c120fbe3 52 #define ADXL345_I2C_H
yattu0914 6:3cc5c120fbe3 53
yattu0914 6:3cc5c120fbe3 54 /**
yattu0914 6:3cc5c120fbe3 55 * Includes
yattu0914 6:3cc5c120fbe3 56 */
yattu0914 6:3cc5c120fbe3 57 #include "mbed.h"
yattu0914 6:3cc5c120fbe3 58
yattu0914 6:3cc5c120fbe3 59 /**
yattu0914 6:3cc5c120fbe3 60 * Defines
yattu0914 6:3cc5c120fbe3 61 */
yattu0914 6:3cc5c120fbe3 62 //Registers.
yattu0914 6:3cc5c120fbe3 63 #define ADXL345_DEVID_REG 0x00
yattu0914 6:3cc5c120fbe3 64 #define ADXL345_THRESH_TAP_REG 0x1D
yattu0914 6:3cc5c120fbe3 65 #define ADXL345_OFSX_REG 0x1E
yattu0914 6:3cc5c120fbe3 66 #define ADXL345_OFSY_REG 0x1F
yattu0914 6:3cc5c120fbe3 67 #define ADXL345_OFSZ_REG 0x20
yattu0914 6:3cc5c120fbe3 68 #define ADXL345_DUR_REG 0x21
yattu0914 6:3cc5c120fbe3 69 #define ADXL345_LATENT_REG 0x22
yattu0914 6:3cc5c120fbe3 70 #define ADXL345_WINDOW_REG 0x23
yattu0914 6:3cc5c120fbe3 71 #define ADXL345_THRESH_ACT_REG 0x24
yattu0914 6:3cc5c120fbe3 72 #define ADXL345_THRESH_INACT_REG 0x25
yattu0914 6:3cc5c120fbe3 73 #define ADXL345_TIME_INACT_REG 0x26
yattu0914 6:3cc5c120fbe3 74 #define ADXL345_ACT_INACT_CTL_REG 0x27
yattu0914 6:3cc5c120fbe3 75 #define ADXL345_THRESH_FF_REG 0x28
yattu0914 6:3cc5c120fbe3 76 #define ADXL345_TIME_FF_REG 0x29
yattu0914 6:3cc5c120fbe3 77 #define ADXL345_TAP_AXES_REG 0x2A
yattu0914 6:3cc5c120fbe3 78 #define ADXL345_ACT_TAP_STATUS_REG 0x2B
yattu0914 6:3cc5c120fbe3 79 #define ADXL345_BW_RATE_REG 0x2C
yattu0914 6:3cc5c120fbe3 80 #define ADXL345_POWER_CTL_REG 0x2D
yattu0914 6:3cc5c120fbe3 81 #define ADXL345_INT_ENABLE_REG 0x2E
yattu0914 6:3cc5c120fbe3 82 #define ADXL345_INT_MAP_REG 0x2F
yattu0914 6:3cc5c120fbe3 83 #define ADXL345_INT_SOURCE_REG 0x30
yattu0914 6:3cc5c120fbe3 84 #define ADXL345_DATA_FORMAT_REG 0x31
yattu0914 6:3cc5c120fbe3 85 #define ADXL345_DATAX0_REG 0x32
yattu0914 6:3cc5c120fbe3 86 #define ADXL345_DATAX1_REG 0x33
yattu0914 6:3cc5c120fbe3 87 #define ADXL345_DATAY0_REG 0x34
yattu0914 6:3cc5c120fbe3 88 #define ADXL345_DATAY1_REG 0x35
yattu0914 6:3cc5c120fbe3 89 #define ADXL345_DATAZ0_REG 0x36
yattu0914 6:3cc5c120fbe3 90 #define ADXL345_DATAZ1_REG 0x37
yattu0914 6:3cc5c120fbe3 91 #define ADXL345_FIFO_CTL 0x38
yattu0914 6:3cc5c120fbe3 92 #define ADXL345_FIFO_STATUS 0x39
yattu0914 6:3cc5c120fbe3 93
yattu0914 6:3cc5c120fbe3 94 //Data rate codes.
yattu0914 6:3cc5c120fbe3 95 #define ADXL345_3200HZ 0x0F
yattu0914 6:3cc5c120fbe3 96 #define ADXL345_1600HZ 0x0E
yattu0914 6:3cc5c120fbe3 97 #define ADXL345_800HZ 0x0D
yattu0914 6:3cc5c120fbe3 98 #define ADXL345_400HZ 0x0C
yattu0914 6:3cc5c120fbe3 99 #define ADXL345_200HZ 0x0B
yattu0914 6:3cc5c120fbe3 100 #define ADXL345_100HZ 0x0A
yattu0914 6:3cc5c120fbe3 101 #define ADXL345_50HZ 0x09
yattu0914 6:3cc5c120fbe3 102 #define ADXL345_25HZ 0x08
yattu0914 6:3cc5c120fbe3 103 #define ADXL345_12HZ5 0x07
yattu0914 6:3cc5c120fbe3 104 #define ADXL345_6HZ25 0x06
yattu0914 6:3cc5c120fbe3 105
yattu0914 6:3cc5c120fbe3 106 // read or write bytes
yattu0914 6:3cc5c120fbe3 107 #define ADXL345_I2C_READ 0xA7
yattu0914 6:3cc5c120fbe3 108 #define ADXL345_I2C_WRITE 0xA6
yattu0914 6:3cc5c120fbe3 109 #define ADXL345_I2C_ADDRESS 0x53 //the ADXL345 7-bit address is 0x53 when ALT ADDRESS is low as it is on the sparkfun chip: when ALT ADDRESS is high the address is 0x1D
yattu0914 6:3cc5c120fbe3 110
yattu0914 6:3cc5c120fbe3 111 /////////////when ALT ADDRESS pin is high:
yattu0914 6:3cc5c120fbe3 112 //#define ADXL345_I2C_READ 0x3B
yattu0914 6:3cc5c120fbe3 113 //#define ADXL345_I2C_WRITE 0x3A
yattu0914 6:3cc5c120fbe3 114 //#define ADXL345_I2C_ADDRESS 0x1D
yattu0914 6:3cc5c120fbe3 115
yattu0914 6:3cc5c120fbe3 116 #define ADXL345_X 0x00
yattu0914 6:3cc5c120fbe3 117 #define ADXL345_Y 0x01
yattu0914 6:3cc5c120fbe3 118 #define ADXL345_Z 0x02
yattu0914 6:3cc5c120fbe3 119
yattu0914 6:3cc5c120fbe3 120
yattu0914 6:3cc5c120fbe3 121
yattu0914 6:3cc5c120fbe3 122 // modes
yattu0914 6:3cc5c120fbe3 123 #define MeasurementMode 0x08
yattu0914 6:3cc5c120fbe3 124
yattu0914 6:3cc5c120fbe3 125
yattu0914 6:3cc5c120fbe3 126
yattu0914 6:3cc5c120fbe3 127
yattu0914 6:3cc5c120fbe3 128
yattu0914 6:3cc5c120fbe3 129
yattu0914 6:3cc5c120fbe3 130
yattu0914 6:3cc5c120fbe3 131 class ADXL345_I2C {
yattu0914 6:3cc5c120fbe3 132
yattu0914 6:3cc5c120fbe3 133 public:
yattu0914 6:3cc5c120fbe3 134
yattu0914 6:3cc5c120fbe3 135 /**
yattu0914 6:3cc5c120fbe3 136 * Constructor.
yattu0914 6:3cc5c120fbe3 137 *
yattu0914 6:3cc5c120fbe3 138 * @param mosi mbed pin to use for SDA line of I2C interface.
yattu0914 6:3cc5c120fbe3 139 * @param sck mbed pin to use for SCL line of I2C interface.
yattu0914 6:3cc5c120fbe3 140 */
yattu0914 6:3cc5c120fbe3 141 ADXL345_I2C(PinName sda, PinName scl);
yattu0914 6:3cc5c120fbe3 142
yattu0914 6:3cc5c120fbe3 143 /**
yattu0914 6:3cc5c120fbe3 144 * Get the output of all three axes.
yattu0914 6:3cc5c120fbe3 145 *
yattu0914 6:3cc5c120fbe3 146 * @param Pointer to a buffer to hold the accelerometer value for the
yattu0914 6:3cc5c120fbe3 147 * x-axis, y-axis and z-axis [in that order].
yattu0914 6:3cc5c120fbe3 148 */
yattu0914 6:3cc5c120fbe3 149 void getOutput(int* readings);
yattu0914 6:3cc5c120fbe3 150
yattu0914 6:3cc5c120fbe3 151 /**
yattu0914 6:3cc5c120fbe3 152 * Read the device ID register on the device.
yattu0914 6:3cc5c120fbe3 153 *
yattu0914 6:3cc5c120fbe3 154 * @return The device ID code [0xE5]
yattu0914 6:3cc5c120fbe3 155 */
yattu0914 6:3cc5c120fbe3 156 char getDeviceID(void);
yattu0914 6:3cc5c120fbe3 157
yattu0914 6:3cc5c120fbe3 158
yattu0914 6:3cc5c120fbe3 159
yattu0914 6:3cc5c120fbe3 160 /**
yattu0914 6:3cc5c120fbe3 161 * Set the power mode.
yattu0914 6:3cc5c120fbe3 162 *
yattu0914 6:3cc5c120fbe3 163 * @param mode 0 -> Normal operation.
yattu0914 6:3cc5c120fbe3 164 * 1 -> Reduced power operation.
yattu0914 6:3cc5c120fbe3 165 */
yattu0914 6:3cc5c120fbe3 166 int setPowerMode(char mode);
yattu0914 6:3cc5c120fbe3 167
yattu0914 6:3cc5c120fbe3 168 /**
yattu0914 6:3cc5c120fbe3 169 * Set the power control settings.
yattu0914 6:3cc5c120fbe3 170 *
yattu0914 6:3cc5c120fbe3 171 * See datasheet for details.
yattu0914 6:3cc5c120fbe3 172 *
yattu0914 6:3cc5c120fbe3 173 * @param The control byte to write to the POWER_CTL register.
yattu0914 6:3cc5c120fbe3 174 */
yattu0914 6:3cc5c120fbe3 175 int setPowerControl(char settings);
yattu0914 6:3cc5c120fbe3 176 /**
yattu0914 6:3cc5c120fbe3 177 * Get the power control settings.
yattu0914 6:3cc5c120fbe3 178 *
yattu0914 6:3cc5c120fbe3 179 * See datasheet for details.
yattu0914 6:3cc5c120fbe3 180 *
yattu0914 6:3cc5c120fbe3 181 * @return The contents of the POWER_CTL register.
yattu0914 6:3cc5c120fbe3 182 */
yattu0914 6:3cc5c120fbe3 183 char getPowerControl(void);
yattu0914 6:3cc5c120fbe3 184
yattu0914 6:3cc5c120fbe3 185
yattu0914 6:3cc5c120fbe3 186 /**
yattu0914 6:3cc5c120fbe3 187 * Get the data format settings.
yattu0914 6:3cc5c120fbe3 188 *
yattu0914 6:3cc5c120fbe3 189 * @return The contents of the DATA_FORMAT register.
yattu0914 6:3cc5c120fbe3 190 */
yattu0914 6:3cc5c120fbe3 191
yattu0914 6:3cc5c120fbe3 192 char getDataFormatControl(void);
yattu0914 6:3cc5c120fbe3 193
yattu0914 6:3cc5c120fbe3 194 /**
yattu0914 6:3cc5c120fbe3 195 * Set the data format settings.
yattu0914 6:3cc5c120fbe3 196 *
yattu0914 6:3cc5c120fbe3 197 * @param settings The control byte to write to the DATA_FORMAT register.
yattu0914 6:3cc5c120fbe3 198 */
yattu0914 6:3cc5c120fbe3 199 int setDataFormatControl(char settings);
yattu0914 6:3cc5c120fbe3 200
yattu0914 6:3cc5c120fbe3 201 /**
yattu0914 6:3cc5c120fbe3 202 * Set the data rate.
yattu0914 6:3cc5c120fbe3 203 *
yattu0914 6:3cc5c120fbe3 204 * @param rate The rate code (see #defines or datasheet).
yattu0914 6:3cc5c120fbe3 205 */
yattu0914 6:3cc5c120fbe3 206 int setDataRate(char rate);
yattu0914 6:3cc5c120fbe3 207
yattu0914 6:3cc5c120fbe3 208
yattu0914 6:3cc5c120fbe3 209 /**
yattu0914 6:3cc5c120fbe3 210 * Get the current offset for a particular axis.
yattu0914 6:3cc5c120fbe3 211 *
yattu0914 6:3cc5c120fbe3 212 * @param axis 0x00 -> X-axis
yattu0914 6:3cc5c120fbe3 213 * 0x01 -> Y-axis
yattu0914 6:3cc5c120fbe3 214 * 0x02 -> Z-axis
yattu0914 6:3cc5c120fbe3 215 * @return The current offset as an 8-bit 2's complement number with scale
yattu0914 6:3cc5c120fbe3 216 * factor 15.6mg/LSB.
yattu0914 6:3cc5c120fbe3 217 */
yattu0914 6:3cc5c120fbe3 218
yattu0914 6:3cc5c120fbe3 219 char getOffset(char axis);
yattu0914 6:3cc5c120fbe3 220
yattu0914 6:3cc5c120fbe3 221 /**
yattu0914 6:3cc5c120fbe3 222 * Set the offset for a particular axis.
yattu0914 6:3cc5c120fbe3 223 *
yattu0914 6:3cc5c120fbe3 224 * @param axis 0x00 -> X-axis
yattu0914 6:3cc5c120fbe3 225 * 0x01 -> Y-axis
yattu0914 6:3cc5c120fbe3 226 * 0x02 -> Z-axis
yattu0914 6:3cc5c120fbe3 227 * @param offset The offset as an 8-bit 2's complement number with scale
yattu0914 6:3cc5c120fbe3 228 * factor 15.6mg/LSB.
yattu0914 6:3cc5c120fbe3 229 */
yattu0914 6:3cc5c120fbe3 230 int setOffset(char axis, char offset);
yattu0914 6:3cc5c120fbe3 231
yattu0914 6:3cc5c120fbe3 232
yattu0914 6:3cc5c120fbe3 233
yattu0914 6:3cc5c120fbe3 234 /**
yattu0914 6:3cc5c120fbe3 235 * Get the FIFO control settings.
yattu0914 6:3cc5c120fbe3 236 *
yattu0914 6:3cc5c120fbe3 237 * @return The contents of the FIFO_CTL register.
yattu0914 6:3cc5c120fbe3 238 */
yattu0914 6:3cc5c120fbe3 239 char getFifoControl(void);
yattu0914 6:3cc5c120fbe3 240
yattu0914 6:3cc5c120fbe3 241 /**
yattu0914 6:3cc5c120fbe3 242 * Set the FIFO control settings.
yattu0914 6:3cc5c120fbe3 243 *
yattu0914 6:3cc5c120fbe3 244 * @param The control byte to write to the FIFO_CTL register.
yattu0914 6:3cc5c120fbe3 245 */
yattu0914 6:3cc5c120fbe3 246 int setFifoControl(char settings);
yattu0914 6:3cc5c120fbe3 247
yattu0914 6:3cc5c120fbe3 248 /**
yattu0914 6:3cc5c120fbe3 249 * Get FIFO status.
yattu0914 6:3cc5c120fbe3 250 *
yattu0914 6:3cc5c120fbe3 251 * @return The contents of the FIFO_STATUS register.
yattu0914 6:3cc5c120fbe3 252 */
yattu0914 6:3cc5c120fbe3 253 char getFifoStatus(void);
yattu0914 6:3cc5c120fbe3 254
yattu0914 6:3cc5c120fbe3 255 /**
yattu0914 6:3cc5c120fbe3 256 * Read the tap threshold on the device.
yattu0914 6:3cc5c120fbe3 257 *
yattu0914 6:3cc5c120fbe3 258 * @return The tap threshold as an 8-bit number with a scale factor of
yattu0914 6:3cc5c120fbe3 259 * 62.5mg/LSB.
yattu0914 6:3cc5c120fbe3 260 */
yattu0914 6:3cc5c120fbe3 261 char getTapThreshold(void);
yattu0914 6:3cc5c120fbe3 262
yattu0914 6:3cc5c120fbe3 263 /**
yattu0914 6:3cc5c120fbe3 264 * Set the tap threshold.
yattu0914 6:3cc5c120fbe3 265 *
yattu0914 6:3cc5c120fbe3 266 * @param The tap threshold as an 8-bit number with a scale factor of
yattu0914 6:3cc5c120fbe3 267 * 62.5mg/LSB.
yattu0914 6:3cc5c120fbe3 268 */
yattu0914 6:3cc5c120fbe3 269 int setTapThreshold(char threshold);
yattu0914 6:3cc5c120fbe3 270
yattu0914 6:3cc5c120fbe3 271 /**
yattu0914 6:3cc5c120fbe3 272 * Get the tap duration required to trigger an event.
yattu0914 6:3cc5c120fbe3 273 *
yattu0914 6:3cc5c120fbe3 274 * @return The max time that an event must be above the tap threshold to
yattu0914 6:3cc5c120fbe3 275 * qualify as a tap event, in microseconds.
yattu0914 6:3cc5c120fbe3 276 */
yattu0914 6:3cc5c120fbe3 277 float getTapDuration(void);
yattu0914 6:3cc5c120fbe3 278
yattu0914 6:3cc5c120fbe3 279 /**
yattu0914 6:3cc5c120fbe3 280 * Set the tap duration required to trigger an event.
yattu0914 6:3cc5c120fbe3 281 *
yattu0914 6:3cc5c120fbe3 282 * @param duration_us The max time that an event must be above the tap
yattu0914 6:3cc5c120fbe3 283 * threshold to qualify as a tap event, in microseconds.
yattu0914 6:3cc5c120fbe3 284 * Time will be normalized by the scale factor which is
yattu0914 6:3cc5c120fbe3 285 * 625us/LSB. A value of 0 disables the single/double
yattu0914 6:3cc5c120fbe3 286 * tap functions.
yattu0914 6:3cc5c120fbe3 287 */
yattu0914 6:3cc5c120fbe3 288 int setTapDuration(short int duration_us);
yattu0914 6:3cc5c120fbe3 289
yattu0914 6:3cc5c120fbe3 290 /**
yattu0914 6:3cc5c120fbe3 291 * Get the tap latency between the detection of a tap and the time window.
yattu0914 6:3cc5c120fbe3 292 *
yattu0914 6:3cc5c120fbe3 293 * @return The wait time from the detection of a tap event to the start of
yattu0914 6:3cc5c120fbe3 294 * the time window during which a possible second tap event can be
yattu0914 6:3cc5c120fbe3 295 * detected in milliseconds.
yattu0914 6:3cc5c120fbe3 296 */
yattu0914 6:3cc5c120fbe3 297 float getTapLatency(void);
yattu0914 6:3cc5c120fbe3 298
yattu0914 6:3cc5c120fbe3 299 /**
yattu0914 6:3cc5c120fbe3 300 * Set the tap latency between the detection of a tap and the time window.
yattu0914 6:3cc5c120fbe3 301 *
yattu0914 6:3cc5c120fbe3 302 * @param latency_ms The wait time from the detection of a tap event to the
yattu0914 6:3cc5c120fbe3 303 * start of the time window during which a possible
yattu0914 6:3cc5c120fbe3 304 * second tap event can be detected in milliseconds.
yattu0914 6:3cc5c120fbe3 305 * A value of 0 disables the double tap function.
yattu0914 6:3cc5c120fbe3 306 */
yattu0914 6:3cc5c120fbe3 307 int setTapLatency(short int latency_ms);
yattu0914 6:3cc5c120fbe3 308
yattu0914 6:3cc5c120fbe3 309 /**
yattu0914 6:3cc5c120fbe3 310 * Get the time of window between tap latency and a double tap.
yattu0914 6:3cc5c120fbe3 311 *
yattu0914 6:3cc5c120fbe3 312 * @return The amount of time after the expiration of the latency time
yattu0914 6:3cc5c120fbe3 313 * during which a second valid tap can begin, in milliseconds.
yattu0914 6:3cc5c120fbe3 314 */
yattu0914 6:3cc5c120fbe3 315 float getWindowTime(void);
yattu0914 6:3cc5c120fbe3 316
yattu0914 6:3cc5c120fbe3 317 /**
yattu0914 6:3cc5c120fbe3 318 * Set the time of the window between tap latency and a double tap.
yattu0914 6:3cc5c120fbe3 319 *
yattu0914 6:3cc5c120fbe3 320 * @param window_ms The amount of time after the expiration of the latency
yattu0914 6:3cc5c120fbe3 321 * time during which a second valid tap can begin,
yattu0914 6:3cc5c120fbe3 322 * in milliseconds.
yattu0914 6:3cc5c120fbe3 323 */
yattu0914 6:3cc5c120fbe3 324 int setWindowTime(short int window_ms);
yattu0914 6:3cc5c120fbe3 325
yattu0914 6:3cc5c120fbe3 326 /**
yattu0914 6:3cc5c120fbe3 327 * Get the threshold value for detecting activity.
yattu0914 6:3cc5c120fbe3 328 *
yattu0914 6:3cc5c120fbe3 329 * @return The threshold value for detecting activity as an 8-bit number.
yattu0914 6:3cc5c120fbe3 330 * Scale factor is 62.5mg/LSB.
yattu0914 6:3cc5c120fbe3 331 */
yattu0914 6:3cc5c120fbe3 332 char getActivityThreshold(void);
yattu0914 6:3cc5c120fbe3 333
yattu0914 6:3cc5c120fbe3 334 /**
yattu0914 6:3cc5c120fbe3 335 * Set the threshold value for detecting activity.
yattu0914 6:3cc5c120fbe3 336 *
yattu0914 6:3cc5c120fbe3 337 * @param threshold The threshold value for detecting activity as an 8-bit
yattu0914 6:3cc5c120fbe3 338 * number. Scale factor is 62.5mg/LSB. A value of 0 may
yattu0914 6:3cc5c120fbe3 339 * result in undesirable behavior if the activity
yattu0914 6:3cc5c120fbe3 340 * interrupt is enabled.
yattu0914 6:3cc5c120fbe3 341 */
yattu0914 6:3cc5c120fbe3 342 int setActivityThreshold(char threshold);
yattu0914 6:3cc5c120fbe3 343
yattu0914 6:3cc5c120fbe3 344 /**
yattu0914 6:3cc5c120fbe3 345 * Get the threshold value for detecting inactivity.
yattu0914 6:3cc5c120fbe3 346 *
yattu0914 6:3cc5c120fbe3 347 * @return The threshold value for detecting inactivity as an 8-bit number.
yattu0914 6:3cc5c120fbe3 348 * Scale factor is 62.5mg/LSB.
yattu0914 6:3cc5c120fbe3 349 */
yattu0914 6:3cc5c120fbe3 350 char getInactivityThreshold(void);
yattu0914 6:3cc5c120fbe3 351
yattu0914 6:3cc5c120fbe3 352 /**
yattu0914 6:3cc5c120fbe3 353 * Set the threshold value for detecting inactivity.
yattu0914 6:3cc5c120fbe3 354 *
yattu0914 6:3cc5c120fbe3 355 * @param threshold The threshold value for detecting inactivity as an
yattu0914 6:3cc5c120fbe3 356 * 8-bit number. Scale factor is 62.5mg/LSB.
yattu0914 6:3cc5c120fbe3 357 */
yattu0914 6:3cc5c120fbe3 358 int setInactivityThreshold(char threshold);
yattu0914 6:3cc5c120fbe3 359
yattu0914 6:3cc5c120fbe3 360 /**
yattu0914 6:3cc5c120fbe3 361 * Get the time required for inactivity to be declared.
yattu0914 6:3cc5c120fbe3 362 *
yattu0914 6:3cc5c120fbe3 363 * @return The amount of time that acceleration must be less than the
yattu0914 6:3cc5c120fbe3 364 * inactivity threshold for inactivity to be declared, in
yattu0914 6:3cc5c120fbe3 365 * seconds.
yattu0914 6:3cc5c120fbe3 366 */
yattu0914 6:3cc5c120fbe3 367 char getTimeInactivity(void);
yattu0914 6:3cc5c120fbe3 368
yattu0914 6:3cc5c120fbe3 369 /**
yattu0914 6:3cc5c120fbe3 370 * Set the time required for inactivity to be declared.
yattu0914 6:3cc5c120fbe3 371 *
yattu0914 6:3cc5c120fbe3 372 * @param inactivity The amount of time that acceleration must be less than
yattu0914 6:3cc5c120fbe3 373 * the inactivity threshold for inactivity to be
yattu0914 6:3cc5c120fbe3 374 * declared, in seconds. A value of 0 results in an
yattu0914 6:3cc5c120fbe3 375 * interrupt when the output data is less than the
yattu0914 6:3cc5c120fbe3 376 * threshold inactivity.
yattu0914 6:3cc5c120fbe3 377 */
yattu0914 6:3cc5c120fbe3 378 int setTimeInactivity(char timeInactivity);
yattu0914 6:3cc5c120fbe3 379
yattu0914 6:3cc5c120fbe3 380 /**
yattu0914 6:3cc5c120fbe3 381 * Get the activity/inactivity control settings.
yattu0914 6:3cc5c120fbe3 382 *
yattu0914 6:3cc5c120fbe3 383 * D7 D6 D5 D4
yattu0914 6:3cc5c120fbe3 384 * +-----------+--------------+--------------+--------------+
yattu0914 6:3cc5c120fbe3 385 * | ACT ac/dc | ACT_X enable | ACT_Y enable | ACT_Z enable |
yattu0914 6:3cc5c120fbe3 386 * +-----------+--------------+--------------+--------------+
yattu0914 6:3cc5c120fbe3 387 *
yattu0914 6:3cc5c120fbe3 388 * D3 D2 D1 D0
yattu0914 6:3cc5c120fbe3 389 * +-------------+----------------+----------------+----------------+
yattu0914 6:3cc5c120fbe3 390 * | INACT ac/dc | INACT_X enable | INACT_Y enable | INACT_Z enable |
yattu0914 6:3cc5c120fbe3 391 * +-------------+----------------+----------------+----------------+
yattu0914 6:3cc5c120fbe3 392 *
yattu0914 6:3cc5c120fbe3 393 * See datasheet for details.
yattu0914 6:3cc5c120fbe3 394 *
yattu0914 6:3cc5c120fbe3 395 * @return The contents of the ACT_INACT_CTL register.
yattu0914 6:3cc5c120fbe3 396 */
yattu0914 6:3cc5c120fbe3 397 char getActivityInactivityControl(void);
yattu0914 6:3cc5c120fbe3 398
yattu0914 6:3cc5c120fbe3 399 /**
yattu0914 6:3cc5c120fbe3 400 * Set the activity/inactivity control settings.
yattu0914 6:3cc5c120fbe3 401 *
yattu0914 6:3cc5c120fbe3 402 * D7 D6 D5 D4
yattu0914 6:3cc5c120fbe3 403 * +-----------+--------------+--------------+--------------+
yattu0914 6:3cc5c120fbe3 404 * | ACT ac/dc | ACT_X enable | ACT_Y enable | ACT_Z enable |
yattu0914 6:3cc5c120fbe3 405 * +-----------+--------------+--------------+--------------+
yattu0914 6:3cc5c120fbe3 406 *
yattu0914 6:3cc5c120fbe3 407 * D3 D2 D1 D0
yattu0914 6:3cc5c120fbe3 408 * +-------------+----------------+----------------+----------------+
yattu0914 6:3cc5c120fbe3 409 * | INACT ac/dc | INACT_X enable | INACT_Y enable | INACT_Z enable |
yattu0914 6:3cc5c120fbe3 410 * +-------------+----------------+----------------+----------------+
yattu0914 6:3cc5c120fbe3 411 *
yattu0914 6:3cc5c120fbe3 412 * See datasheet for details.
yattu0914 6:3cc5c120fbe3 413 *
yattu0914 6:3cc5c120fbe3 414 * @param settings The control byte to write to the ACT_INACT_CTL register.
yattu0914 6:3cc5c120fbe3 415 */
yattu0914 6:3cc5c120fbe3 416 int setActivityInactivityControl(char settings);
yattu0914 6:3cc5c120fbe3 417
yattu0914 6:3cc5c120fbe3 418 /**
yattu0914 6:3cc5c120fbe3 419 * Get the threshold for free fall detection.
yattu0914 6:3cc5c120fbe3 420 *
yattu0914 6:3cc5c120fbe3 421 * @return The threshold value for free-fall detection, as an 8-bit number,
yattu0914 6:3cc5c120fbe3 422 * with scale factor 62.5mg/LSB.
yattu0914 6:3cc5c120fbe3 423 */
yattu0914 6:3cc5c120fbe3 424 char getFreefallThreshold(void);
yattu0914 6:3cc5c120fbe3 425
yattu0914 6:3cc5c120fbe3 426 /**
yattu0914 6:3cc5c120fbe3 427 * Set the threshold for free fall detection.
yattu0914 6:3cc5c120fbe3 428 *
yattu0914 6:3cc5c120fbe3 429 * @return The threshold value for free-fall detection, as an 8-bit number,
yattu0914 6:3cc5c120fbe3 430 * with scale factor 62.5mg/LSB. A value of 0 may result in
yattu0914 6:3cc5c120fbe3 431 * undesirable behavior if the free-fall interrupt is enabled.
yattu0914 6:3cc5c120fbe3 432 * Values between 300 mg and 600 mg (0x05 to 0x09) are recommended.
yattu0914 6:3cc5c120fbe3 433 */
yattu0914 6:3cc5c120fbe3 434 int setFreefallThreshold(char threshold);
yattu0914 6:3cc5c120fbe3 435
yattu0914 6:3cc5c120fbe3 436 /**
yattu0914 6:3cc5c120fbe3 437 * Get the time required to generate a free fall interrupt.
yattu0914 6:3cc5c120fbe3 438 *
yattu0914 6:3cc5c120fbe3 439 * @return The minimum time that the value of all axes must be less than
yattu0914 6:3cc5c120fbe3 440 * the freefall threshold to generate a free-fall interrupt, in
yattu0914 6:3cc5c120fbe3 441 * milliseconds.
yattu0914 6:3cc5c120fbe3 442 */
yattu0914 6:3cc5c120fbe3 443 char getFreefallTime(void);
yattu0914 6:3cc5c120fbe3 444
yattu0914 6:3cc5c120fbe3 445 /**
yattu0914 6:3cc5c120fbe3 446 * Set the time required to generate a free fall interrupt.
yattu0914 6:3cc5c120fbe3 447 *
yattu0914 6:3cc5c120fbe3 448 * @return The minimum time that the value of all axes must be less than
yattu0914 6:3cc5c120fbe3 449 * the freefall threshold to generate a free-fall interrupt, in
yattu0914 6:3cc5c120fbe3 450 * milliseconds. A value of 0 may result in undesirable behavior
yattu0914 6:3cc5c120fbe3 451 * if the free-fall interrupt is enabled. Values between 100 ms
yattu0914 6:3cc5c120fbe3 452 * and 350 ms (0x14 to 0x46) are recommended.
yattu0914 6:3cc5c120fbe3 453 */
yattu0914 6:3cc5c120fbe3 454 int setFreefallTime(short int freefallTime_ms);
yattu0914 6:3cc5c120fbe3 455
yattu0914 6:3cc5c120fbe3 456 /**
yattu0914 6:3cc5c120fbe3 457 * Get the axis tap settings.
yattu0914 6:3cc5c120fbe3 458 *
yattu0914 6:3cc5c120fbe3 459 * D3 D2 D1 D0
yattu0914 6:3cc5c120fbe3 460 * +----------+--------------+--------------+--------------+
yattu0914 6:3cc5c120fbe3 461 * | Suppress | TAP_X enable | TAP_Y enable | TAP_Z enable |
yattu0914 6:3cc5c120fbe3 462 * +----------+--------------+--------------+--------------+
yattu0914 6:3cc5c120fbe3 463 *
yattu0914 6:3cc5c120fbe3 464 * (D7-D4 are 0s).
yattu0914 6:3cc5c120fbe3 465 *
yattu0914 6:3cc5c120fbe3 466 * See datasheet for more details.
yattu0914 6:3cc5c120fbe3 467 *
yattu0914 6:3cc5c120fbe3 468 * @return The contents of the TAP_AXES register.
yattu0914 6:3cc5c120fbe3 469 */
yattu0914 6:3cc5c120fbe3 470 char getTapAxisControl(void);
yattu0914 6:3cc5c120fbe3 471
yattu0914 6:3cc5c120fbe3 472 /**
yattu0914 6:3cc5c120fbe3 473 * Set the axis tap settings.
yattu0914 6:3cc5c120fbe3 474 *
yattu0914 6:3cc5c120fbe3 475 * D3 D2 D1 D0
yattu0914 6:3cc5c120fbe3 476 * +----------+--------------+--------------+--------------+
yattu0914 6:3cc5c120fbe3 477 * | Suppress | TAP_X enable | TAP_Y enable | TAP_Z enable |
yattu0914 6:3cc5c120fbe3 478 * +----------+--------------+--------------+--------------+
yattu0914 6:3cc5c120fbe3 479 *
yattu0914 6:3cc5c120fbe3 480 * (D7-D4 are 0s).
yattu0914 6:3cc5c120fbe3 481 *
yattu0914 6:3cc5c120fbe3 482 * See datasheet for more details.
yattu0914 6:3cc5c120fbe3 483 *
yattu0914 6:3cc5c120fbe3 484 * @param The control byte to write to the TAP_AXES register.
yattu0914 6:3cc5c120fbe3 485 */
yattu0914 6:3cc5c120fbe3 486 int setTapAxisControl(char settings);
yattu0914 6:3cc5c120fbe3 487
yattu0914 6:3cc5c120fbe3 488 /**
yattu0914 6:3cc5c120fbe3 489 * Get the source of a tap.
yattu0914 6:3cc5c120fbe3 490 *
yattu0914 6:3cc5c120fbe3 491 * @return The contents of the ACT_TAP_STATUS register.
yattu0914 6:3cc5c120fbe3 492 */
yattu0914 6:3cc5c120fbe3 493 char getTapSource(void);
yattu0914 6:3cc5c120fbe3 494
yattu0914 6:3cc5c120fbe3 495 /**
yattu0914 6:3cc5c120fbe3 496 * Get the interrupt enable settings.
yattu0914 6:3cc5c120fbe3 497 *
yattu0914 6:3cc5c120fbe3 498 * @return The contents of the INT_ENABLE register.
yattu0914 6:3cc5c120fbe3 499 */
yattu0914 6:3cc5c120fbe3 500
yattu0914 6:3cc5c120fbe3 501 char getInterruptEnableControl(void);
yattu0914 6:3cc5c120fbe3 502
yattu0914 6:3cc5c120fbe3 503 /**
yattu0914 6:3cc5c120fbe3 504 * Set the interrupt enable settings.
yattu0914 6:3cc5c120fbe3 505 *
yattu0914 6:3cc5c120fbe3 506 * @param settings The control byte to write to the INT_ENABLE register.
yattu0914 6:3cc5c120fbe3 507 */
yattu0914 6:3cc5c120fbe3 508 int setInterruptEnableControl(char settings);
yattu0914 6:3cc5c120fbe3 509
yattu0914 6:3cc5c120fbe3 510 /**
yattu0914 6:3cc5c120fbe3 511 * Get the interrupt mapping settings.
yattu0914 6:3cc5c120fbe3 512 *
yattu0914 6:3cc5c120fbe3 513 * @return The contents of the INT_MAP register.
yattu0914 6:3cc5c120fbe3 514 */
yattu0914 6:3cc5c120fbe3 515 char getInterruptMappingControl(void);
yattu0914 6:3cc5c120fbe3 516
yattu0914 6:3cc5c120fbe3 517 /**
yattu0914 6:3cc5c120fbe3 518 * Set the interrupt mapping settings.
yattu0914 6:3cc5c120fbe3 519 *
yattu0914 6:3cc5c120fbe3 520 * @param settings The control byte to write to the INT_MAP register.
yattu0914 6:3cc5c120fbe3 521 */
yattu0914 6:3cc5c120fbe3 522 int setInterruptMappingControl(char settings);
yattu0914 6:3cc5c120fbe3 523
yattu0914 6:3cc5c120fbe3 524 /**
yattu0914 6:3cc5c120fbe3 525 * Get the interrupt source.
yattu0914 6:3cc5c120fbe3 526 *
yattu0914 6:3cc5c120fbe3 527 * @return The contents of the INT_SOURCE register.
yattu0914 6:3cc5c120fbe3 528 */
yattu0914 6:3cc5c120fbe3 529 char getInterruptSource(void);
yattu0914 6:3cc5c120fbe3 530
yattu0914 6:3cc5c120fbe3 531
yattu0914 6:3cc5c120fbe3 532 private:
yattu0914 6:3cc5c120fbe3 533
yattu0914 6:3cc5c120fbe3 534 I2C i2c_;
yattu0914 6:3cc5c120fbe3 535
yattu0914 6:3cc5c120fbe3 536
yattu0914 6:3cc5c120fbe3 537 /**
yattu0914 6:3cc5c120fbe3 538 * Read one byte from a register on the device.
yattu0914 6:3cc5c120fbe3 539 *
yattu0914 6:3cc5c120fbe3 540 * @param: - the address to be read from
yattu0914 6:3cc5c120fbe3 541 *
yattu0914 6:3cc5c120fbe3 542 * @return: the value of the data read
yattu0914 6:3cc5c120fbe3 543 */
yattu0914 6:3cc5c120fbe3 544 char SingleByteRead(char address);
yattu0914 6:3cc5c120fbe3 545
yattu0914 6:3cc5c120fbe3 546 /**
yattu0914 6:3cc5c120fbe3 547 * Write one byte to a register on the device.
yattu0914 6:3cc5c120fbe3 548 *
yattu0914 6:3cc5c120fbe3 549 * @param:
yattu0914 6:3cc5c120fbe3 550 - address of the register to write to.
yattu0914 6:3cc5c120fbe3 551 - the value of the data to store
yattu0914 6:3cc5c120fbe3 552 */
yattu0914 6:3cc5c120fbe3 553
yattu0914 6:3cc5c120fbe3 554
yattu0914 6:3cc5c120fbe3 555 int SingleByteWrite(char address, char data);
yattu0914 6:3cc5c120fbe3 556
yattu0914 6:3cc5c120fbe3 557 /**
yattu0914 6:3cc5c120fbe3 558 * Read several consecutive bytes on the device and store them in a given location.
yattu0914 6:3cc5c120fbe3 559 *
yattu0914 6:3cc5c120fbe3 560 * @param startAddress: The address of the first register to read from.
yattu0914 6:3cc5c120fbe3 561 * @param ptr_output: a pointer to the location to store the data being read
yattu0914 6:3cc5c120fbe3 562 * @param size: The number of bytes to read.
yattu0914 6:3cc5c120fbe3 563 */
yattu0914 6:3cc5c120fbe3 564 void multiByteRead(char startAddress, char* ptr_output, int size);
yattu0914 6:3cc5c120fbe3 565
yattu0914 6:3cc5c120fbe3 566 /**
yattu0914 6:3cc5c120fbe3 567 * Write several consecutive bytes on the device.
yattu0914 6:3cc5c120fbe3 568 *
yattu0914 6:3cc5c120fbe3 569 * @param startAddress: The address of the first register to write to.
yattu0914 6:3cc5c120fbe3 570 * @param ptr_data: Pointer to a location which contains the data to write.
yattu0914 6:3cc5c120fbe3 571 * @param size: The number of bytes to write.
yattu0914 6:3cc5c120fbe3 572 */
yattu0914 6:3cc5c120fbe3 573 int multiByteWrite(char startAddress, char* ptr_data, int size);
yattu0914 6:3cc5c120fbe3 574
yattu0914 6:3cc5c120fbe3 575 };
yattu0914 6:3cc5c120fbe3 576
yattu0914 6:3cc5c120fbe3 577 #endif /* ADXL345_I2C_H */