Slightly modified version (to work with processing GUI)
Fork of 6DoF_IMU_readvalue by
Diff: ADXL345_I2C.h
- Revision:
- 3:04df9b19199b
- Parent:
- 0:cda6d9f5a43c
- Child:
- 5:e4a11d519322
diff -r 39468ef68358 -r 04df9b19199b ADXL345_I2C.h --- a/ADXL345_I2C.h Fri Oct 11 00:09:31 2013 +0000 +++ b/ADXL345_I2C.h Tue Oct 22 00:13:07 2013 +0000 @@ -4,14 +4,14 @@ * today, religion is thought of as something that you do or believe and has about as * little impact on a person as their political stance. But for me, God gives me daily * strength and has filled my life with the satisfaction that I could never find in any - * of the other things that I once looked for it in. + * of the other things that I once looked for it in. * If your interested, heres verse that changed my life: * Rom 8:1-3: "Therefore, there is now no condemnation for those who are in Christ Jesus, * because through Christ Jesus, the law of the Spirit who gives life has set - * me free from the law of sin (which brings...) and death. For what the law + * me free from the law of sin (which brings...) and death. For what the law * was powerless to do in that it was weakened by the flesh, God did by sending * His own Son in the likeness of sinful flesh to be a sin offering. And so He - * condemned sin in the flesh in order that the righteous requirements of the + * condemned sin in the flesh in order that the righteous requirements of the * (God's) law might be fully met in us, who live not according to the flesh * but according to the Spirit." * @@ -44,7 +44,7 @@ * Datasheet: * * http://www.analog.com/static/imported-files/data_sheets/ADXL345.pdf - */ + */ @@ -104,14 +104,14 @@ #define ADXL345_6HZ25 0x06 // read or write bytes -#define ADXL345_I2C_READ 0xA7 -#define ADXL345_I2C_WRITE 0xA6 +#define ADXL345_I2C_READ 0xA7 +#define ADXL345_I2C_WRITE 0xA6 #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 /////////////when ALT ADDRESS pin is high: -//#define ADXL345_I2C_READ 0x3B +//#define ADXL345_I2C_READ 0x3B //#define ADXL345_I2C_WRITE 0x3A -//#define ADXL345_I2C_ADDRESS 0x1D +//#define ADXL345_I2C_ADDRESS 0x1D #define ADXL345_X 0x00 #define ADXL345_Y 0x01 @@ -128,7 +128,8 @@ -class ADXL345_I2C { +class ADXL345_I2C +{ public: @@ -156,67 +157,67 @@ char getDeviceID(void); - - /** - * Set the power mode. - * - * @param mode 0 -> Normal operation. - * 1 -> Reduced power operation. - */ -int setPowerMode(char mode); - - /** - * Set the power control settings. - * - * See datasheet for details. - * - * @param The control byte to write to the POWER_CTL register. - */ - int setPowerControl(char settings); - /** - * Get the power control settings. - * - * See datasheet for details. - * - * @return The contents of the POWER_CTL register. - */ + + /** + * Set the power mode. + * + * @param mode 0 -> Normal operation. + * 1 -> Reduced power operation. + */ + int setPowerMode(char mode); + + /** + * Set the power control settings. + * + * See datasheet for details. + * + * @param The control byte to write to the POWER_CTL register. + */ + int setPowerControl(char settings); + /** + * Get the power control settings. + * + * See datasheet for details. + * + * @return The contents of the POWER_CTL register. + */ char getPowerControl(void); - + /** * Get the data format settings. * * @return The contents of the DATA_FORMAT register. */ - + char getDataFormatControl(void); - + /** * Set the data format settings. * * @param settings The control byte to write to the DATA_FORMAT register. */ int setDataFormatControl(char settings); - - /** - * Set the data rate. - * - * @param rate The rate code (see #defines or datasheet). - */ + + /** + * Set the data rate. + * + * @param rate The rate code (see #defines or datasheet). + */ int setDataRate(char rate); - + - /** - * Get the current offset for a particular axis. - * - * @param axis 0x00 -> X-axis - * 0x01 -> Y-axis - * 0x02 -> Z-axis - * @return The current offset as an 8-bit 2's complement number with scale - * factor 15.6mg/LSB. - */ - - char getOffset(char axis); + /** + * Get the current offset for a particular axis. + * + * @param axis 0x00 -> X-axis + * 0x01 -> Y-axis + * 0x02 -> Z-axis + * @return The current offset as an 8-bit 2's complement number with scale + * factor 15.6mg/LSB. + */ + + char getOffset(char axis); /** * Set the offset for a particular axis. @@ -230,28 +231,28 @@ int setOffset(char axis, char offset); - + /** * Get the FIFO control settings. * * @return The contents of the FIFO_CTL register. */ char getFifoControl(void); - + /** * Set the FIFO control settings. * * @param The control byte to write to the FIFO_CTL register. */ int setFifoControl(char settings); - + /** * Get FIFO status. * * @return The contents of the FIFO_STATUS register. */ char getFifoStatus(void); - + /** * Read the tap threshold on the device. * @@ -329,7 +330,7 @@ * @return The threshold value for detecting activity as an 8-bit number. * Scale factor is 62.5mg/LSB. */ - char getActivityThreshold(void); + char getActivityThreshold(void); /** * Set the threshold value for detecting activity. @@ -347,7 +348,7 @@ * @return The threshold value for detecting inactivity as an 8-bit number. * Scale factor is 62.5mg/LSB. */ - char getInactivityThreshold(void); + char getInactivityThreshold(void); /** * Set the threshold value for detecting inactivity. @@ -364,8 +365,8 @@ * inactivity threshold for inactivity to be declared, in * seconds. */ - char getTimeInactivity(void); - + char getTimeInactivity(void); + /** * Set the time required for inactivity to be declared. * @@ -376,7 +377,7 @@ * threshold inactivity. */ int setTimeInactivity(char timeInactivity); - + /** * Get the activity/inactivity control settings. * @@ -394,8 +395,8 @@ * * @return The contents of the ACT_INACT_CTL register. */ - char getActivityInactivityControl(void); - + char getActivityInactivityControl(void); + /** * Set the activity/inactivity control settings. * @@ -414,25 +415,25 @@ * @param settings The control byte to write to the ACT_INACT_CTL register. */ int setActivityInactivityControl(char settings); - + /** * Get the threshold for free fall detection. * * @return The threshold value for free-fall detection, as an 8-bit number, * with scale factor 62.5mg/LSB. */ - char getFreefallThreshold(void); - + char getFreefallThreshold(void); + /** * Set the threshold for free fall detection. * * @return The threshold value for free-fall detection, as an 8-bit number, - * with scale factor 62.5mg/LSB. A value of 0 may result in + * with scale factor 62.5mg/LSB. A value of 0 may result in * undesirable behavior if the free-fall interrupt is enabled. * Values between 300 mg and 600 mg (0x05 to 0x09) are recommended. */ int setFreefallThreshold(char threshold); - + /** * Get the time required to generate a free fall interrupt. * @@ -440,19 +441,19 @@ * the freefall threshold to generate a free-fall interrupt, in * milliseconds. */ - char getFreefallTime(void); - + char getFreefallTime(void); + /** * Set the time required to generate a free fall interrupt. * * @return The minimum time that the value of all axes must be less than * the freefall threshold to generate a free-fall interrupt, in * milliseconds. A value of 0 may result in undesirable behavior - * if the free-fall interrupt is enabled. Values between 100 ms + * if the free-fall interrupt is enabled. Values between 100 ms * and 350 ms (0x14 to 0x46) are recommended. */ int setFreefallTime(short int freefallTime_ms); - + /** * Get the axis tap settings. * @@ -466,9 +467,9 @@ * See datasheet for more details. * * @return The contents of the TAP_AXES register. - */ - char getTapAxisControl(void); - + */ + char getTapAxisControl(void); + /** * Set the axis tap settings. * @@ -484,55 +485,55 @@ * @param The control byte to write to the TAP_AXES register. */ int setTapAxisControl(char settings); - + /** * Get the source of a tap. * * @return The contents of the ACT_TAP_STATUS register. */ - char getTapSource(void); - - /** - * Get the interrupt enable settings. - * - * @return The contents of the INT_ENABLE register. - */ + char getTapSource(void); - char getInterruptEnableControl(void); - + /** + * Get the interrupt enable settings. + * + * @return The contents of the INT_ENABLE register. + */ + + char getInterruptEnableControl(void); + /** * Set the interrupt enable settings. * * @param settings The control byte to write to the INT_ENABLE register. */ int setInterruptEnableControl(char settings); - + /** * Get the interrupt mapping settings. * * @return The contents of the INT_MAP register. */ - char getInterruptMappingControl(void); - + char getInterruptMappingControl(void); + /** * Set the interrupt mapping settings. * * @param settings The control byte to write to the INT_MAP register. */ int setInterruptMappingControl(char settings); - + /** * Get the interrupt source. * * @return The contents of the INT_SOURCE register. */ - char getInterruptSource(void); - - + char getInterruptSource(void); + + private: I2C i2c_; - + /** * Read one byte from a register on the device. @@ -550,9 +551,9 @@ - address of the register to write to. - the value of the data to store */ - - - int SingleByteWrite(char address, char data); + + + int SingleByteWrite(char address, char data); /** * Read several consecutive bytes on the device and store them in a given location.