Seeed Studio Grove Sensors Example

Dependencies:   mbed DHT DigitDisplay

Fork of STM32_Read_Sensors_Example by AT&T Developer Summit Hackathon 2016

Committer:
dangriffin
Date:
Thu Dec 18 18:00:17 2014 +0000
Revision:
7:d52c3793a04a
Parent:
3:6d8574d8c9c1
Minor correction to message scrolling loop.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
joe_tijerina 3:6d8574d8c9c1 1 /**
joe_tijerina 3:6d8574d8c9c1 2 * @author Peter Swanson
joe_tijerina 3:6d8574d8c9c1 3 * A personal note from me: Jesus Christ has changed my life so much it blows my mind. I say this because
joe_tijerina 3:6d8574d8c9c1 4 * today, religion is thought of as something that you do or believe and has about as
joe_tijerina 3:6d8574d8c9c1 5 * little impact on a person as their political stance. But for me, God gives me daily
joe_tijerina 3:6d8574d8c9c1 6 * strength and has filled my life with the satisfaction that I could never find in any
joe_tijerina 3:6d8574d8c9c1 7 * of the other things that I once looked for it in.
joe_tijerina 3:6d8574d8c9c1 8 * If your interested, heres verse that changed my life:
joe_tijerina 3:6d8574d8c9c1 9 * Rom 8:1-3: "Therefore, there is now no condemnation for those who are in Christ Jesus,
joe_tijerina 3:6d8574d8c9c1 10 * because through Christ Jesus, the law of the Spirit who gives life has set
joe_tijerina 3:6d8574d8c9c1 11 * me free from the law of sin (which brings...) and death. For what the law
joe_tijerina 3:6d8574d8c9c1 12 * was powerless to do in that it was weakened by the flesh, God did by sending
joe_tijerina 3:6d8574d8c9c1 13 * His own Son in the likeness of sinful flesh to be a sin offering. And so He
joe_tijerina 3:6d8574d8c9c1 14 * condemned sin in the flesh in order that the righteous requirements of the
joe_tijerina 3:6d8574d8c9c1 15 * (God's) law might be fully met in us, who live not according to the flesh
joe_tijerina 3:6d8574d8c9c1 16 * but according to the Spirit."
joe_tijerina 3:6d8574d8c9c1 17 *
joe_tijerina 3:6d8574d8c9c1 18 * A special thanks to Ewout van Bekkum for all his patient help in developing this library!
joe_tijerina 3:6d8574d8c9c1 19 *
joe_tijerina 3:6d8574d8c9c1 20 * @section LICENSE
joe_tijerina 3:6d8574d8c9c1 21 *
joe_tijerina 3:6d8574d8c9c1 22 * Permission is hereby granted, free of charge, to any person obtaining a copy
joe_tijerina 3:6d8574d8c9c1 23 * of this software and associated documentation files (the "Software"), to deal
joe_tijerina 3:6d8574d8c9c1 24 * in the Software without restriction, including without limitation the rights
joe_tijerina 3:6d8574d8c9c1 25 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
joe_tijerina 3:6d8574d8c9c1 26 * copies of the Software, and to permit persons to whom the Software is
joe_tijerina 3:6d8574d8c9c1 27 * furnished to do so, subject to the following conditions:
joe_tijerina 3:6d8574d8c9c1 28 *
joe_tijerina 3:6d8574d8c9c1 29 * The above copyright notice and this permission notice shall be included in
joe_tijerina 3:6d8574d8c9c1 30 * all copies or substantial portions of the Software.
joe_tijerina 3:6d8574d8c9c1 31 *
joe_tijerina 3:6d8574d8c9c1 32 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
joe_tijerina 3:6d8574d8c9c1 33 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
joe_tijerina 3:6d8574d8c9c1 34 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
joe_tijerina 3:6d8574d8c9c1 35 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
joe_tijerina 3:6d8574d8c9c1 36 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
joe_tijerina 3:6d8574d8c9c1 37 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
joe_tijerina 3:6d8574d8c9c1 38 * THE SOFTWARE.
joe_tijerina 3:6d8574d8c9c1 39 *
joe_tijerina 3:6d8574d8c9c1 40 * @section DESCRIPTION
joe_tijerina 3:6d8574d8c9c1 41 *
joe_tijerina 3:6d8574d8c9c1 42 * ADXL345, triple axis, I2C interface, accelerometer.
joe_tijerina 3:6d8574d8c9c1 43 *
joe_tijerina 3:6d8574d8c9c1 44 * Datasheet:
joe_tijerina 3:6d8574d8c9c1 45 *
joe_tijerina 3:6d8574d8c9c1 46 * http://www.analog.com/static/imported-files/data_sheets/ADXL345.pdf
joe_tijerina 3:6d8574d8c9c1 47 */
joe_tijerina 3:6d8574d8c9c1 48
joe_tijerina 3:6d8574d8c9c1 49
joe_tijerina 3:6d8574d8c9c1 50
joe_tijerina 3:6d8574d8c9c1 51 #ifndef ADXL345_I2C_H
joe_tijerina 3:6d8574d8c9c1 52 #define ADXL345_I2C_H
joe_tijerina 3:6d8574d8c9c1 53
joe_tijerina 3:6d8574d8c9c1 54 /**
joe_tijerina 3:6d8574d8c9c1 55 * Includes
joe_tijerina 3:6d8574d8c9c1 56 */
joe_tijerina 3:6d8574d8c9c1 57 #include "mbed.h"
joe_tijerina 3:6d8574d8c9c1 58
joe_tijerina 3:6d8574d8c9c1 59 /**
joe_tijerina 3:6d8574d8c9c1 60 * Defines
joe_tijerina 3:6d8574d8c9c1 61 */
joe_tijerina 3:6d8574d8c9c1 62 //Registers.
joe_tijerina 3:6d8574d8c9c1 63 #define ADXL345_DEVID_REG 0x00
joe_tijerina 3:6d8574d8c9c1 64 #define ADXL345_THRESH_TAP_REG 0x1D
joe_tijerina 3:6d8574d8c9c1 65 #define ADXL345_OFSX_REG 0x1E
joe_tijerina 3:6d8574d8c9c1 66 #define ADXL345_OFSY_REG 0x1F
joe_tijerina 3:6d8574d8c9c1 67 #define ADXL345_OFSZ_REG 0x20
joe_tijerina 3:6d8574d8c9c1 68 #define ADXL345_DUR_REG 0x21
joe_tijerina 3:6d8574d8c9c1 69 #define ADXL345_LATENT_REG 0x22
joe_tijerina 3:6d8574d8c9c1 70 #define ADXL345_WINDOW_REG 0x23
joe_tijerina 3:6d8574d8c9c1 71 #define ADXL345_THRESH_ACT_REG 0x24
joe_tijerina 3:6d8574d8c9c1 72 #define ADXL345_THRESH_INACT_REG 0x25
joe_tijerina 3:6d8574d8c9c1 73 #define ADXL345_TIME_INACT_REG 0x26
joe_tijerina 3:6d8574d8c9c1 74 #define ADXL345_ACT_INACT_CTL_REG 0x27
joe_tijerina 3:6d8574d8c9c1 75 #define ADXL345_THRESH_FF_REG 0x28
joe_tijerina 3:6d8574d8c9c1 76 #define ADXL345_TIME_FF_REG 0x29
joe_tijerina 3:6d8574d8c9c1 77 #define ADXL345_TAP_AXES_REG 0x2A
joe_tijerina 3:6d8574d8c9c1 78 #define ADXL345_ACT_TAP_STATUS_REG 0x2B
joe_tijerina 3:6d8574d8c9c1 79 #define ADXL345_BW_RATE_REG 0x2C
joe_tijerina 3:6d8574d8c9c1 80 #define ADXL345_POWER_CTL_REG 0x2D
joe_tijerina 3:6d8574d8c9c1 81 #define ADXL345_INT_ENABLE_REG 0x2E
joe_tijerina 3:6d8574d8c9c1 82 #define ADXL345_INT_MAP_REG 0x2F
joe_tijerina 3:6d8574d8c9c1 83 #define ADXL345_INT_SOURCE_REG 0x30
joe_tijerina 3:6d8574d8c9c1 84 #define ADXL345_DATA_FORMAT_REG 0x31
joe_tijerina 3:6d8574d8c9c1 85 #define ADXL345_DATAX0_REG 0x32
joe_tijerina 3:6d8574d8c9c1 86 #define ADXL345_DATAX1_REG 0x33
joe_tijerina 3:6d8574d8c9c1 87 #define ADXL345_DATAY0_REG 0x34
joe_tijerina 3:6d8574d8c9c1 88 #define ADXL345_DATAY1_REG 0x35
joe_tijerina 3:6d8574d8c9c1 89 #define ADXL345_DATAZ0_REG 0x36
joe_tijerina 3:6d8574d8c9c1 90 #define ADXL345_DATAZ1_REG 0x37
joe_tijerina 3:6d8574d8c9c1 91 #define ADXL345_FIFO_CTL 0x38
joe_tijerina 3:6d8574d8c9c1 92 #define ADXL345_FIFO_STATUS 0x39
joe_tijerina 3:6d8574d8c9c1 93
joe_tijerina 3:6d8574d8c9c1 94 //Data rate codes.
joe_tijerina 3:6d8574d8c9c1 95 #define ADXL345_3200HZ 0x0F
joe_tijerina 3:6d8574d8c9c1 96 #define ADXL345_1600HZ 0x0E
joe_tijerina 3:6d8574d8c9c1 97 #define ADXL345_800HZ 0x0D
joe_tijerina 3:6d8574d8c9c1 98 #define ADXL345_400HZ 0x0C
joe_tijerina 3:6d8574d8c9c1 99 #define ADXL345_200HZ 0x0B
joe_tijerina 3:6d8574d8c9c1 100 #define ADXL345_100HZ 0x0A
joe_tijerina 3:6d8574d8c9c1 101 #define ADXL345_50HZ 0x09
joe_tijerina 3:6d8574d8c9c1 102 #define ADXL345_25HZ 0x08
joe_tijerina 3:6d8574d8c9c1 103 #define ADXL345_12HZ5 0x07
joe_tijerina 3:6d8574d8c9c1 104 #define ADXL345_6HZ25 0x06
joe_tijerina 3:6d8574d8c9c1 105
joe_tijerina 3:6d8574d8c9c1 106 // read or write bytes
joe_tijerina 3:6d8574d8c9c1 107 #define ADXL345_I2C_READ 0xA7
joe_tijerina 3:6d8574d8c9c1 108 #define ADXL345_I2C_WRITE 0xA6
joe_tijerina 3:6d8574d8c9c1 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
joe_tijerina 3:6d8574d8c9c1 110
joe_tijerina 3:6d8574d8c9c1 111 /////////////when ALT ADDRESS pin is high:
joe_tijerina 3:6d8574d8c9c1 112 //#define ADXL345_I2C_READ 0x3B
joe_tijerina 3:6d8574d8c9c1 113 //#define ADXL345_I2C_WRITE 0x3A
joe_tijerina 3:6d8574d8c9c1 114 //#define ADXL345_I2C_ADDRESS 0x1D
joe_tijerina 3:6d8574d8c9c1 115
joe_tijerina 3:6d8574d8c9c1 116 #define ADXL345_X 0x00
joe_tijerina 3:6d8574d8c9c1 117 #define ADXL345_Y 0x01
joe_tijerina 3:6d8574d8c9c1 118 #define ADXL345_Z 0x02
joe_tijerina 3:6d8574d8c9c1 119
joe_tijerina 3:6d8574d8c9c1 120
joe_tijerina 3:6d8574d8c9c1 121
joe_tijerina 3:6d8574d8c9c1 122 // modes
joe_tijerina 3:6d8574d8c9c1 123 #define MeasurementMode 0x08
joe_tijerina 3:6d8574d8c9c1 124
joe_tijerina 3:6d8574d8c9c1 125
joe_tijerina 3:6d8574d8c9c1 126
joe_tijerina 3:6d8574d8c9c1 127
joe_tijerina 3:6d8574d8c9c1 128
joe_tijerina 3:6d8574d8c9c1 129
joe_tijerina 3:6d8574d8c9c1 130
joe_tijerina 3:6d8574d8c9c1 131 class ADXL345_I2C {
joe_tijerina 3:6d8574d8c9c1 132
joe_tijerina 3:6d8574d8c9c1 133 public:
joe_tijerina 3:6d8574d8c9c1 134
joe_tijerina 3:6d8574d8c9c1 135 /**
joe_tijerina 3:6d8574d8c9c1 136 * Constructor.
joe_tijerina 3:6d8574d8c9c1 137 *
joe_tijerina 3:6d8574d8c9c1 138 * @param mosi mbed pin to use for SDA line of I2C interface.
joe_tijerina 3:6d8574d8c9c1 139 * @param sck mbed pin to use for SCL line of I2C interface.
joe_tijerina 3:6d8574d8c9c1 140 */
joe_tijerina 3:6d8574d8c9c1 141 ADXL345_I2C(PinName sda, PinName scl);
joe_tijerina 3:6d8574d8c9c1 142
joe_tijerina 3:6d8574d8c9c1 143 /**
joe_tijerina 3:6d8574d8c9c1 144 * Get the output of all three axes.
joe_tijerina 3:6d8574d8c9c1 145 *
joe_tijerina 3:6d8574d8c9c1 146 * @param Pointer to a buffer to hold the accelerometer value for the
joe_tijerina 3:6d8574d8c9c1 147 * x-axis, y-axis and z-axis [in that order].
joe_tijerina 3:6d8574d8c9c1 148 */
joe_tijerina 3:6d8574d8c9c1 149 void getOutput(int* readings);
joe_tijerina 3:6d8574d8c9c1 150
joe_tijerina 3:6d8574d8c9c1 151 /**
joe_tijerina 3:6d8574d8c9c1 152 * Read the device ID register on the device.
joe_tijerina 3:6d8574d8c9c1 153 *
joe_tijerina 3:6d8574d8c9c1 154 * @return The device ID code [0xE5]
joe_tijerina 3:6d8574d8c9c1 155 */
joe_tijerina 3:6d8574d8c9c1 156 char getDeviceID(void);
joe_tijerina 3:6d8574d8c9c1 157
joe_tijerina 3:6d8574d8c9c1 158
joe_tijerina 3:6d8574d8c9c1 159
joe_tijerina 3:6d8574d8c9c1 160 /**
joe_tijerina 3:6d8574d8c9c1 161 * Set the power mode.
joe_tijerina 3:6d8574d8c9c1 162 *
joe_tijerina 3:6d8574d8c9c1 163 * @param mode 0 -> Normal operation.
joe_tijerina 3:6d8574d8c9c1 164 * 1 -> Reduced power operation.
joe_tijerina 3:6d8574d8c9c1 165 */
joe_tijerina 3:6d8574d8c9c1 166 int setPowerMode(char mode);
joe_tijerina 3:6d8574d8c9c1 167
joe_tijerina 3:6d8574d8c9c1 168 /**
joe_tijerina 3:6d8574d8c9c1 169 * Set the power control settings.
joe_tijerina 3:6d8574d8c9c1 170 *
joe_tijerina 3:6d8574d8c9c1 171 * See datasheet for details.
joe_tijerina 3:6d8574d8c9c1 172 *
joe_tijerina 3:6d8574d8c9c1 173 * @param The control byte to write to the POWER_CTL register.
joe_tijerina 3:6d8574d8c9c1 174 */
joe_tijerina 3:6d8574d8c9c1 175 int setPowerControl(char settings);
joe_tijerina 3:6d8574d8c9c1 176 /**
joe_tijerina 3:6d8574d8c9c1 177 * Get the power control settings.
joe_tijerina 3:6d8574d8c9c1 178 *
joe_tijerina 3:6d8574d8c9c1 179 * See datasheet for details.
joe_tijerina 3:6d8574d8c9c1 180 *
joe_tijerina 3:6d8574d8c9c1 181 * @return The contents of the POWER_CTL register.
joe_tijerina 3:6d8574d8c9c1 182 */
joe_tijerina 3:6d8574d8c9c1 183 char getPowerControl(void);
joe_tijerina 3:6d8574d8c9c1 184
joe_tijerina 3:6d8574d8c9c1 185
joe_tijerina 3:6d8574d8c9c1 186 /**
joe_tijerina 3:6d8574d8c9c1 187 * Get the data format settings.
joe_tijerina 3:6d8574d8c9c1 188 *
joe_tijerina 3:6d8574d8c9c1 189 * @return The contents of the DATA_FORMAT register.
joe_tijerina 3:6d8574d8c9c1 190 */
joe_tijerina 3:6d8574d8c9c1 191
joe_tijerina 3:6d8574d8c9c1 192 char getDataFormatControl(void);
joe_tijerina 3:6d8574d8c9c1 193
joe_tijerina 3:6d8574d8c9c1 194 /**
joe_tijerina 3:6d8574d8c9c1 195 * Set the data format settings.
joe_tijerina 3:6d8574d8c9c1 196 *
joe_tijerina 3:6d8574d8c9c1 197 * @param settings The control byte to write to the DATA_FORMAT register.
joe_tijerina 3:6d8574d8c9c1 198 */
joe_tijerina 3:6d8574d8c9c1 199 int setDataFormatControl(char settings);
joe_tijerina 3:6d8574d8c9c1 200
joe_tijerina 3:6d8574d8c9c1 201 /**
joe_tijerina 3:6d8574d8c9c1 202 * Set the data rate.
joe_tijerina 3:6d8574d8c9c1 203 *
joe_tijerina 3:6d8574d8c9c1 204 * @param rate The rate code (see #defines or datasheet).
joe_tijerina 3:6d8574d8c9c1 205 */
joe_tijerina 3:6d8574d8c9c1 206 int setDataRate(char rate);
joe_tijerina 3:6d8574d8c9c1 207
joe_tijerina 3:6d8574d8c9c1 208
joe_tijerina 3:6d8574d8c9c1 209 /**
joe_tijerina 3:6d8574d8c9c1 210 * Get the current offset for a particular axis.
joe_tijerina 3:6d8574d8c9c1 211 *
joe_tijerina 3:6d8574d8c9c1 212 * @param axis 0x00 -> X-axis
joe_tijerina 3:6d8574d8c9c1 213 * 0x01 -> Y-axis
joe_tijerina 3:6d8574d8c9c1 214 * 0x02 -> Z-axis
joe_tijerina 3:6d8574d8c9c1 215 * @return The current offset as an 8-bit 2's complement number with scale
joe_tijerina 3:6d8574d8c9c1 216 * factor 15.6mg/LSB.
joe_tijerina 3:6d8574d8c9c1 217 */
joe_tijerina 3:6d8574d8c9c1 218
joe_tijerina 3:6d8574d8c9c1 219 char getOffset(char axis);
joe_tijerina 3:6d8574d8c9c1 220
joe_tijerina 3:6d8574d8c9c1 221 /**
joe_tijerina 3:6d8574d8c9c1 222 * Set the offset for a particular axis.
joe_tijerina 3:6d8574d8c9c1 223 *
joe_tijerina 3:6d8574d8c9c1 224 * @param axis 0x00 -> X-axis
joe_tijerina 3:6d8574d8c9c1 225 * 0x01 -> Y-axis
joe_tijerina 3:6d8574d8c9c1 226 * 0x02 -> Z-axis
joe_tijerina 3:6d8574d8c9c1 227 * @param offset The offset as an 8-bit 2's complement number with scale
joe_tijerina 3:6d8574d8c9c1 228 * factor 15.6mg/LSB.
joe_tijerina 3:6d8574d8c9c1 229 */
joe_tijerina 3:6d8574d8c9c1 230 int setOffset(char axis, char offset);
joe_tijerina 3:6d8574d8c9c1 231
joe_tijerina 3:6d8574d8c9c1 232
joe_tijerina 3:6d8574d8c9c1 233
joe_tijerina 3:6d8574d8c9c1 234 /**
joe_tijerina 3:6d8574d8c9c1 235 * Get the FIFO control settings.
joe_tijerina 3:6d8574d8c9c1 236 *
joe_tijerina 3:6d8574d8c9c1 237 * @return The contents of the FIFO_CTL register.
joe_tijerina 3:6d8574d8c9c1 238 */
joe_tijerina 3:6d8574d8c9c1 239 char getFifoControl(void);
joe_tijerina 3:6d8574d8c9c1 240
joe_tijerina 3:6d8574d8c9c1 241 /**
joe_tijerina 3:6d8574d8c9c1 242 * Set the FIFO control settings.
joe_tijerina 3:6d8574d8c9c1 243 *
joe_tijerina 3:6d8574d8c9c1 244 * @param The control byte to write to the FIFO_CTL register.
joe_tijerina 3:6d8574d8c9c1 245 */
joe_tijerina 3:6d8574d8c9c1 246 int setFifoControl(char settings);
joe_tijerina 3:6d8574d8c9c1 247
joe_tijerina 3:6d8574d8c9c1 248 /**
joe_tijerina 3:6d8574d8c9c1 249 * Get FIFO status.
joe_tijerina 3:6d8574d8c9c1 250 *
joe_tijerina 3:6d8574d8c9c1 251 * @return The contents of the FIFO_STATUS register.
joe_tijerina 3:6d8574d8c9c1 252 */
joe_tijerina 3:6d8574d8c9c1 253 char getFifoStatus(void);
joe_tijerina 3:6d8574d8c9c1 254
joe_tijerina 3:6d8574d8c9c1 255 /**
joe_tijerina 3:6d8574d8c9c1 256 * Read the tap threshold on the device.
joe_tijerina 3:6d8574d8c9c1 257 *
joe_tijerina 3:6d8574d8c9c1 258 * @return The tap threshold as an 8-bit number with a scale factor of
joe_tijerina 3:6d8574d8c9c1 259 * 62.5mg/LSB.
joe_tijerina 3:6d8574d8c9c1 260 */
joe_tijerina 3:6d8574d8c9c1 261 char getTapThreshold(void);
joe_tijerina 3:6d8574d8c9c1 262
joe_tijerina 3:6d8574d8c9c1 263 /**
joe_tijerina 3:6d8574d8c9c1 264 * Set the tap threshold.
joe_tijerina 3:6d8574d8c9c1 265 *
joe_tijerina 3:6d8574d8c9c1 266 * @param The tap threshold as an 8-bit number with a scale factor of
joe_tijerina 3:6d8574d8c9c1 267 * 62.5mg/LSB.
joe_tijerina 3:6d8574d8c9c1 268 */
joe_tijerina 3:6d8574d8c9c1 269 int setTapThreshold(char threshold);
joe_tijerina 3:6d8574d8c9c1 270
joe_tijerina 3:6d8574d8c9c1 271 /**
joe_tijerina 3:6d8574d8c9c1 272 * Get the tap duration required to trigger an event.
joe_tijerina 3:6d8574d8c9c1 273 *
joe_tijerina 3:6d8574d8c9c1 274 * @return The max time that an event must be above the tap threshold to
joe_tijerina 3:6d8574d8c9c1 275 * qualify as a tap event, in microseconds.
joe_tijerina 3:6d8574d8c9c1 276 */
joe_tijerina 3:6d8574d8c9c1 277 float getTapDuration(void);
joe_tijerina 3:6d8574d8c9c1 278
joe_tijerina 3:6d8574d8c9c1 279 /**
joe_tijerina 3:6d8574d8c9c1 280 * Set the tap duration required to trigger an event.
joe_tijerina 3:6d8574d8c9c1 281 *
joe_tijerina 3:6d8574d8c9c1 282 * @param duration_us The max time that an event must be above the tap
joe_tijerina 3:6d8574d8c9c1 283 * threshold to qualify as a tap event, in microseconds.
joe_tijerina 3:6d8574d8c9c1 284 * Time will be normalized by the scale factor which is
joe_tijerina 3:6d8574d8c9c1 285 * 625us/LSB. A value of 0 disables the single/double
joe_tijerina 3:6d8574d8c9c1 286 * tap functions.
joe_tijerina 3:6d8574d8c9c1 287 */
joe_tijerina 3:6d8574d8c9c1 288 int setTapDuration(short int duration_us);
joe_tijerina 3:6d8574d8c9c1 289
joe_tijerina 3:6d8574d8c9c1 290 /**
joe_tijerina 3:6d8574d8c9c1 291 * Get the tap latency between the detection of a tap and the time window.
joe_tijerina 3:6d8574d8c9c1 292 *
joe_tijerina 3:6d8574d8c9c1 293 * @return The wait time from the detection of a tap event to the start of
joe_tijerina 3:6d8574d8c9c1 294 * the time window during which a possible second tap event can be
joe_tijerina 3:6d8574d8c9c1 295 * detected in milliseconds.
joe_tijerina 3:6d8574d8c9c1 296 */
joe_tijerina 3:6d8574d8c9c1 297 float getTapLatency(void);
joe_tijerina 3:6d8574d8c9c1 298
joe_tijerina 3:6d8574d8c9c1 299 /**
joe_tijerina 3:6d8574d8c9c1 300 * Set the tap latency between the detection of a tap and the time window.
joe_tijerina 3:6d8574d8c9c1 301 *
joe_tijerina 3:6d8574d8c9c1 302 * @param latency_ms The wait time from the detection of a tap event to the
joe_tijerina 3:6d8574d8c9c1 303 * start of the time window during which a possible
joe_tijerina 3:6d8574d8c9c1 304 * second tap event can be detected in milliseconds.
joe_tijerina 3:6d8574d8c9c1 305 * A value of 0 disables the double tap function.
joe_tijerina 3:6d8574d8c9c1 306 */
joe_tijerina 3:6d8574d8c9c1 307 int setTapLatency(short int latency_ms);
joe_tijerina 3:6d8574d8c9c1 308
joe_tijerina 3:6d8574d8c9c1 309 /**
joe_tijerina 3:6d8574d8c9c1 310 * Get the time of window between tap latency and a double tap.
joe_tijerina 3:6d8574d8c9c1 311 *
joe_tijerina 3:6d8574d8c9c1 312 * @return The amount of time after the expiration of the latency time
joe_tijerina 3:6d8574d8c9c1 313 * during which a second valid tap can begin, in milliseconds.
joe_tijerina 3:6d8574d8c9c1 314 */
joe_tijerina 3:6d8574d8c9c1 315 float getWindowTime(void);
joe_tijerina 3:6d8574d8c9c1 316
joe_tijerina 3:6d8574d8c9c1 317 /**
joe_tijerina 3:6d8574d8c9c1 318 * Set the time of the window between tap latency and a double tap.
joe_tijerina 3:6d8574d8c9c1 319 *
joe_tijerina 3:6d8574d8c9c1 320 * @param window_ms The amount of time after the expiration of the latency
joe_tijerina 3:6d8574d8c9c1 321 * time during which a second valid tap can begin,
joe_tijerina 3:6d8574d8c9c1 322 * in milliseconds.
joe_tijerina 3:6d8574d8c9c1 323 */
joe_tijerina 3:6d8574d8c9c1 324 int setWindowTime(short int window_ms);
joe_tijerina 3:6d8574d8c9c1 325
joe_tijerina 3:6d8574d8c9c1 326 /**
joe_tijerina 3:6d8574d8c9c1 327 * Get the threshold value for detecting activity.
joe_tijerina 3:6d8574d8c9c1 328 *
joe_tijerina 3:6d8574d8c9c1 329 * @return The threshold value for detecting activity as an 8-bit number.
joe_tijerina 3:6d8574d8c9c1 330 * Scale factor is 62.5mg/LSB.
joe_tijerina 3:6d8574d8c9c1 331 */
joe_tijerina 3:6d8574d8c9c1 332 char getActivityThreshold(void);
joe_tijerina 3:6d8574d8c9c1 333
joe_tijerina 3:6d8574d8c9c1 334 /**
joe_tijerina 3:6d8574d8c9c1 335 * Set the threshold value for detecting activity.
joe_tijerina 3:6d8574d8c9c1 336 *
joe_tijerina 3:6d8574d8c9c1 337 * @param threshold The threshold value for detecting activity as an 8-bit
joe_tijerina 3:6d8574d8c9c1 338 * number. Scale factor is 62.5mg/LSB. A value of 0 may
joe_tijerina 3:6d8574d8c9c1 339 * result in undesirable behavior if the activity
joe_tijerina 3:6d8574d8c9c1 340 * interrupt is enabled.
joe_tijerina 3:6d8574d8c9c1 341 */
joe_tijerina 3:6d8574d8c9c1 342 int setActivityThreshold(char threshold);
joe_tijerina 3:6d8574d8c9c1 343
joe_tijerina 3:6d8574d8c9c1 344 /**
joe_tijerina 3:6d8574d8c9c1 345 * Get the threshold value for detecting inactivity.
joe_tijerina 3:6d8574d8c9c1 346 *
joe_tijerina 3:6d8574d8c9c1 347 * @return The threshold value for detecting inactivity as an 8-bit number.
joe_tijerina 3:6d8574d8c9c1 348 * Scale factor is 62.5mg/LSB.
joe_tijerina 3:6d8574d8c9c1 349 */
joe_tijerina 3:6d8574d8c9c1 350 char getInactivityThreshold(void);
joe_tijerina 3:6d8574d8c9c1 351
joe_tijerina 3:6d8574d8c9c1 352 /**
joe_tijerina 3:6d8574d8c9c1 353 * Set the threshold value for detecting inactivity.
joe_tijerina 3:6d8574d8c9c1 354 *
joe_tijerina 3:6d8574d8c9c1 355 * @param threshold The threshold value for detecting inactivity as an
joe_tijerina 3:6d8574d8c9c1 356 * 8-bit number. Scale factor is 62.5mg/LSB.
joe_tijerina 3:6d8574d8c9c1 357 */
joe_tijerina 3:6d8574d8c9c1 358 int setInactivityThreshold(char threshold);
joe_tijerina 3:6d8574d8c9c1 359
joe_tijerina 3:6d8574d8c9c1 360 /**
joe_tijerina 3:6d8574d8c9c1 361 * Get the time required for inactivity to be declared.
joe_tijerina 3:6d8574d8c9c1 362 *
joe_tijerina 3:6d8574d8c9c1 363 * @return The amount of time that acceleration must be less than the
joe_tijerina 3:6d8574d8c9c1 364 * inactivity threshold for inactivity to be declared, in
joe_tijerina 3:6d8574d8c9c1 365 * seconds.
joe_tijerina 3:6d8574d8c9c1 366 */
joe_tijerina 3:6d8574d8c9c1 367 char getTimeInactivity(void);
joe_tijerina 3:6d8574d8c9c1 368
joe_tijerina 3:6d8574d8c9c1 369 /**
joe_tijerina 3:6d8574d8c9c1 370 * Set the time required for inactivity to be declared.
joe_tijerina 3:6d8574d8c9c1 371 *
joe_tijerina 3:6d8574d8c9c1 372 * @param inactivity The amount of time that acceleration must be less than
joe_tijerina 3:6d8574d8c9c1 373 * the inactivity threshold for inactivity to be
joe_tijerina 3:6d8574d8c9c1 374 * declared, in seconds. A value of 0 results in an
joe_tijerina 3:6d8574d8c9c1 375 * interrupt when the output data is less than the
joe_tijerina 3:6d8574d8c9c1 376 * threshold inactivity.
joe_tijerina 3:6d8574d8c9c1 377 */
joe_tijerina 3:6d8574d8c9c1 378 int setTimeInactivity(char timeInactivity);
joe_tijerina 3:6d8574d8c9c1 379
joe_tijerina 3:6d8574d8c9c1 380 /**
joe_tijerina 3:6d8574d8c9c1 381 * Get the activity/inactivity control settings.
joe_tijerina 3:6d8574d8c9c1 382 *
joe_tijerina 3:6d8574d8c9c1 383 * D7 D6 D5 D4
joe_tijerina 3:6d8574d8c9c1 384 * +-----------+--------------+--------------+--------------+
joe_tijerina 3:6d8574d8c9c1 385 * | ACT ac/dc | ACT_X enable | ACT_Y enable | ACT_Z enable |
joe_tijerina 3:6d8574d8c9c1 386 * +-----------+--------------+--------------+--------------+
joe_tijerina 3:6d8574d8c9c1 387 *
joe_tijerina 3:6d8574d8c9c1 388 * D3 D2 D1 D0
joe_tijerina 3:6d8574d8c9c1 389 * +-------------+----------------+----------------+----------------+
joe_tijerina 3:6d8574d8c9c1 390 * | INACT ac/dc | INACT_X enable | INACT_Y enable | INACT_Z enable |
joe_tijerina 3:6d8574d8c9c1 391 * +-------------+----------------+----------------+----------------+
joe_tijerina 3:6d8574d8c9c1 392 *
joe_tijerina 3:6d8574d8c9c1 393 * See datasheet for details.
joe_tijerina 3:6d8574d8c9c1 394 *
joe_tijerina 3:6d8574d8c9c1 395 * @return The contents of the ACT_INACT_CTL register.
joe_tijerina 3:6d8574d8c9c1 396 */
joe_tijerina 3:6d8574d8c9c1 397 char getActivityInactivityControl(void);
joe_tijerina 3:6d8574d8c9c1 398
joe_tijerina 3:6d8574d8c9c1 399 /**
joe_tijerina 3:6d8574d8c9c1 400 * Set the activity/inactivity control settings.
joe_tijerina 3:6d8574d8c9c1 401 *
joe_tijerina 3:6d8574d8c9c1 402 * D7 D6 D5 D4
joe_tijerina 3:6d8574d8c9c1 403 * +-----------+--------------+--------------+--------------+
joe_tijerina 3:6d8574d8c9c1 404 * | ACT ac/dc | ACT_X enable | ACT_Y enable | ACT_Z enable |
joe_tijerina 3:6d8574d8c9c1 405 * +-----------+--------------+--------------+--------------+
joe_tijerina 3:6d8574d8c9c1 406 *
joe_tijerina 3:6d8574d8c9c1 407 * D3 D2 D1 D0
joe_tijerina 3:6d8574d8c9c1 408 * +-------------+----------------+----------------+----------------+
joe_tijerina 3:6d8574d8c9c1 409 * | INACT ac/dc | INACT_X enable | INACT_Y enable | INACT_Z enable |
joe_tijerina 3:6d8574d8c9c1 410 * +-------------+----------------+----------------+----------------+
joe_tijerina 3:6d8574d8c9c1 411 *
joe_tijerina 3:6d8574d8c9c1 412 * See datasheet for details.
joe_tijerina 3:6d8574d8c9c1 413 *
joe_tijerina 3:6d8574d8c9c1 414 * @param settings The control byte to write to the ACT_INACT_CTL register.
joe_tijerina 3:6d8574d8c9c1 415 */
joe_tijerina 3:6d8574d8c9c1 416 int setActivityInactivityControl(char settings);
joe_tijerina 3:6d8574d8c9c1 417
joe_tijerina 3:6d8574d8c9c1 418 /**
joe_tijerina 3:6d8574d8c9c1 419 * Get the threshold for free fall detection.
joe_tijerina 3:6d8574d8c9c1 420 *
joe_tijerina 3:6d8574d8c9c1 421 * @return The threshold value for free-fall detection, as an 8-bit number,
joe_tijerina 3:6d8574d8c9c1 422 * with scale factor 62.5mg/LSB.
joe_tijerina 3:6d8574d8c9c1 423 */
joe_tijerina 3:6d8574d8c9c1 424 char getFreefallThreshold(void);
joe_tijerina 3:6d8574d8c9c1 425
joe_tijerina 3:6d8574d8c9c1 426 /**
joe_tijerina 3:6d8574d8c9c1 427 * Set the threshold for free fall detection.
joe_tijerina 3:6d8574d8c9c1 428 *
joe_tijerina 3:6d8574d8c9c1 429 * @return The threshold value for free-fall detection, as an 8-bit number,
joe_tijerina 3:6d8574d8c9c1 430 * with scale factor 62.5mg/LSB. A value of 0 may result in
joe_tijerina 3:6d8574d8c9c1 431 * undesirable behavior if the free-fall interrupt is enabled.
joe_tijerina 3:6d8574d8c9c1 432 * Values between 300 mg and 600 mg (0x05 to 0x09) are recommended.
joe_tijerina 3:6d8574d8c9c1 433 */
joe_tijerina 3:6d8574d8c9c1 434 int setFreefallThreshold(char threshold);
joe_tijerina 3:6d8574d8c9c1 435
joe_tijerina 3:6d8574d8c9c1 436 /**
joe_tijerina 3:6d8574d8c9c1 437 * Get the time required to generate a free fall interrupt.
joe_tijerina 3:6d8574d8c9c1 438 *
joe_tijerina 3:6d8574d8c9c1 439 * @return The minimum time that the value of all axes must be less than
joe_tijerina 3:6d8574d8c9c1 440 * the freefall threshold to generate a free-fall interrupt, in
joe_tijerina 3:6d8574d8c9c1 441 * milliseconds.
joe_tijerina 3:6d8574d8c9c1 442 */
joe_tijerina 3:6d8574d8c9c1 443 char getFreefallTime(void);
joe_tijerina 3:6d8574d8c9c1 444
joe_tijerina 3:6d8574d8c9c1 445 /**
joe_tijerina 3:6d8574d8c9c1 446 * Set the time required to generate a free fall interrupt.
joe_tijerina 3:6d8574d8c9c1 447 *
joe_tijerina 3:6d8574d8c9c1 448 * @return The minimum time that the value of all axes must be less than
joe_tijerina 3:6d8574d8c9c1 449 * the freefall threshold to generate a free-fall interrupt, in
joe_tijerina 3:6d8574d8c9c1 450 * milliseconds. A value of 0 may result in undesirable behavior
joe_tijerina 3:6d8574d8c9c1 451 * if the free-fall interrupt is enabled. Values between 100 ms
joe_tijerina 3:6d8574d8c9c1 452 * and 350 ms (0x14 to 0x46) are recommended.
joe_tijerina 3:6d8574d8c9c1 453 */
joe_tijerina 3:6d8574d8c9c1 454 int setFreefallTime(short int freefallTime_ms);
joe_tijerina 3:6d8574d8c9c1 455
joe_tijerina 3:6d8574d8c9c1 456 /**
joe_tijerina 3:6d8574d8c9c1 457 * Get the axis tap settings.
joe_tijerina 3:6d8574d8c9c1 458 *
joe_tijerina 3:6d8574d8c9c1 459 * D3 D2 D1 D0
joe_tijerina 3:6d8574d8c9c1 460 * +----------+--------------+--------------+--------------+
joe_tijerina 3:6d8574d8c9c1 461 * | Suppress | TAP_X enable | TAP_Y enable | TAP_Z enable |
joe_tijerina 3:6d8574d8c9c1 462 * +----------+--------------+--------------+--------------+
joe_tijerina 3:6d8574d8c9c1 463 *
joe_tijerina 3:6d8574d8c9c1 464 * (D7-D4 are 0s).
joe_tijerina 3:6d8574d8c9c1 465 *
joe_tijerina 3:6d8574d8c9c1 466 * See datasheet for more details.
joe_tijerina 3:6d8574d8c9c1 467 *
joe_tijerina 3:6d8574d8c9c1 468 * @return The contents of the TAP_AXES register.
joe_tijerina 3:6d8574d8c9c1 469 */
joe_tijerina 3:6d8574d8c9c1 470 char getTapAxisControl(void);
joe_tijerina 3:6d8574d8c9c1 471
joe_tijerina 3:6d8574d8c9c1 472 /**
joe_tijerina 3:6d8574d8c9c1 473 * Set the axis tap settings.
joe_tijerina 3:6d8574d8c9c1 474 *
joe_tijerina 3:6d8574d8c9c1 475 * D3 D2 D1 D0
joe_tijerina 3:6d8574d8c9c1 476 * +----------+--------------+--------------+--------------+
joe_tijerina 3:6d8574d8c9c1 477 * | Suppress | TAP_X enable | TAP_Y enable | TAP_Z enable |
joe_tijerina 3:6d8574d8c9c1 478 * +----------+--------------+--------------+--------------+
joe_tijerina 3:6d8574d8c9c1 479 *
joe_tijerina 3:6d8574d8c9c1 480 * (D7-D4 are 0s).
joe_tijerina 3:6d8574d8c9c1 481 *
joe_tijerina 3:6d8574d8c9c1 482 * See datasheet for more details.
joe_tijerina 3:6d8574d8c9c1 483 *
joe_tijerina 3:6d8574d8c9c1 484 * @param The control byte to write to the TAP_AXES register.
joe_tijerina 3:6d8574d8c9c1 485 */
joe_tijerina 3:6d8574d8c9c1 486 int setTapAxisControl(char settings);
joe_tijerina 3:6d8574d8c9c1 487
joe_tijerina 3:6d8574d8c9c1 488 /**
joe_tijerina 3:6d8574d8c9c1 489 * Get the source of a tap.
joe_tijerina 3:6d8574d8c9c1 490 *
joe_tijerina 3:6d8574d8c9c1 491 * @return The contents of the ACT_TAP_STATUS register.
joe_tijerina 3:6d8574d8c9c1 492 */
joe_tijerina 3:6d8574d8c9c1 493 char getTapSource(void);
joe_tijerina 3:6d8574d8c9c1 494
joe_tijerina 3:6d8574d8c9c1 495 /**
joe_tijerina 3:6d8574d8c9c1 496 * Get the interrupt enable settings.
joe_tijerina 3:6d8574d8c9c1 497 *
joe_tijerina 3:6d8574d8c9c1 498 * @return The contents of the INT_ENABLE register.
joe_tijerina 3:6d8574d8c9c1 499 */
joe_tijerina 3:6d8574d8c9c1 500
joe_tijerina 3:6d8574d8c9c1 501 char getInterruptEnableControl(void);
joe_tijerina 3:6d8574d8c9c1 502
joe_tijerina 3:6d8574d8c9c1 503 /**
joe_tijerina 3:6d8574d8c9c1 504 * Set the interrupt enable settings.
joe_tijerina 3:6d8574d8c9c1 505 *
joe_tijerina 3:6d8574d8c9c1 506 * @param settings The control byte to write to the INT_ENABLE register.
joe_tijerina 3:6d8574d8c9c1 507 */
joe_tijerina 3:6d8574d8c9c1 508 int setInterruptEnableControl(char settings);
joe_tijerina 3:6d8574d8c9c1 509
joe_tijerina 3:6d8574d8c9c1 510 /**
joe_tijerina 3:6d8574d8c9c1 511 * Get the interrupt mapping settings.
joe_tijerina 3:6d8574d8c9c1 512 *
joe_tijerina 3:6d8574d8c9c1 513 * @return The contents of the INT_MAP register.
joe_tijerina 3:6d8574d8c9c1 514 */
joe_tijerina 3:6d8574d8c9c1 515 char getInterruptMappingControl(void);
joe_tijerina 3:6d8574d8c9c1 516
joe_tijerina 3:6d8574d8c9c1 517 /**
joe_tijerina 3:6d8574d8c9c1 518 * Set the interrupt mapping settings.
joe_tijerina 3:6d8574d8c9c1 519 *
joe_tijerina 3:6d8574d8c9c1 520 * @param settings The control byte to write to the INT_MAP register.
joe_tijerina 3:6d8574d8c9c1 521 */
joe_tijerina 3:6d8574d8c9c1 522 int setInterruptMappingControl(char settings);
joe_tijerina 3:6d8574d8c9c1 523
joe_tijerina 3:6d8574d8c9c1 524 /**
joe_tijerina 3:6d8574d8c9c1 525 * Get the interrupt source.
joe_tijerina 3:6d8574d8c9c1 526 *
joe_tijerina 3:6d8574d8c9c1 527 * @return The contents of the INT_SOURCE register.
joe_tijerina 3:6d8574d8c9c1 528 */
joe_tijerina 3:6d8574d8c9c1 529 char getInterruptSource(void);
joe_tijerina 3:6d8574d8c9c1 530
joe_tijerina 3:6d8574d8c9c1 531
joe_tijerina 3:6d8574d8c9c1 532 private:
joe_tijerina 3:6d8574d8c9c1 533
joe_tijerina 3:6d8574d8c9c1 534 I2C i2c_;
joe_tijerina 3:6d8574d8c9c1 535
joe_tijerina 3:6d8574d8c9c1 536
joe_tijerina 3:6d8574d8c9c1 537 /**
joe_tijerina 3:6d8574d8c9c1 538 * Read one byte from a register on the device.
joe_tijerina 3:6d8574d8c9c1 539 *
joe_tijerina 3:6d8574d8c9c1 540 * @param: - the address to be read from
joe_tijerina 3:6d8574d8c9c1 541 *
joe_tijerina 3:6d8574d8c9c1 542 * @return: the value of the data read
joe_tijerina 3:6d8574d8c9c1 543 */
joe_tijerina 3:6d8574d8c9c1 544 char SingleByteRead(char address);
joe_tijerina 3:6d8574d8c9c1 545
joe_tijerina 3:6d8574d8c9c1 546 /**
joe_tijerina 3:6d8574d8c9c1 547 * Write one byte to a register on the device.
joe_tijerina 3:6d8574d8c9c1 548 *
joe_tijerina 3:6d8574d8c9c1 549 * @param:
joe_tijerina 3:6d8574d8c9c1 550 - address of the register to write to.
joe_tijerina 3:6d8574d8c9c1 551 - the value of the data to store
joe_tijerina 3:6d8574d8c9c1 552 */
joe_tijerina 3:6d8574d8c9c1 553
joe_tijerina 3:6d8574d8c9c1 554
joe_tijerina 3:6d8574d8c9c1 555 int SingleByteWrite(char address, char data);
joe_tijerina 3:6d8574d8c9c1 556
joe_tijerina 3:6d8574d8c9c1 557 /**
joe_tijerina 3:6d8574d8c9c1 558 * Read several consecutive bytes on the device and store them in a given location.
joe_tijerina 3:6d8574d8c9c1 559 *
joe_tijerina 3:6d8574d8c9c1 560 * @param startAddress: The address of the first register to read from.
joe_tijerina 3:6d8574d8c9c1 561 * @param ptr_output: a pointer to the location to store the data being read
joe_tijerina 3:6d8574d8c9c1 562 * @param size: The number of bytes to read.
joe_tijerina 3:6d8574d8c9c1 563 */
joe_tijerina 3:6d8574d8c9c1 564 void multiByteRead(char startAddress, char* ptr_output, int size);
joe_tijerina 3:6d8574d8c9c1 565
joe_tijerina 3:6d8574d8c9c1 566 /**
joe_tijerina 3:6d8574d8c9c1 567 * Write several consecutive bytes on the device.
joe_tijerina 3:6d8574d8c9c1 568 *
joe_tijerina 3:6d8574d8c9c1 569 * @param startAddress: The address of the first register to write to.
joe_tijerina 3:6d8574d8c9c1 570 * @param ptr_data: Pointer to a location which contains the data to write.
joe_tijerina 3:6d8574d8c9c1 571 * @param size: The number of bytes to write.
joe_tijerina 3:6d8574d8c9c1 572 */
joe_tijerina 3:6d8574d8c9c1 573 int multiByteWrite(char startAddress, char* ptr_data, int size);
joe_tijerina 3:6d8574d8c9c1 574
joe_tijerina 3:6d8574d8c9c1 575 };
joe_tijerina 3:6d8574d8c9c1 576
joe_tijerina 3:6d8574d8c9c1 577 #endif /* ADXL345_I2C_H */