GR Peach based smart health monitor with IoT for Elder people mbed project Released Under Creative Commons Attribution-ShareAlike 3.0 Unported Licence

Dependencies:   ADT7320_SPI mbed

Committer:
rcele_85
Date:
Fri Jan 13 18:39:18 2017 +0000
Revision:
0:ea069e8429ef
GR Peach Smart Health Monitor with IoT for elder people mbed project;

Who changed what in which revision?

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