Republished Library, to be refined for use with the SparkFun 9DOF in HARP project.
Fork of ADXL345 by
Revision 4:8046894b947e, committed 2012-09-17
- Comitter:
- gltest26
- Date:
- Mon Sep 17 10:39:19 2012 +0000
- Parent:
- 3:7b83694c7292
- Child:
- 5:122a504fcfa3
- Commit message:
- Added bit mask replace version of ADXL345::setDataFormatControl() as an overload.
Changed in this revision
ADXL345.cpp | Show annotated file Show diff for this revision Revisions of this file |
ADXL345.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/ADXL345.cpp Thu Sep 13 11:43:11 2012 +0000 +++ b/ADXL345.cpp Mon Sep 17 10:39:19 2012 +0000 @@ -117,7 +117,6 @@ } - void ADXL345::multiByteRead(char address, char* output, int size) { i2c_.write( ADXL345_WRITE, &address, 1); //tell it where to read from i2c_.read( ADXL345_READ , output, size); //tell it where to store the data read @@ -180,6 +179,13 @@ } +int ADXL345::setDataFormatControl(char settings, char mask, char *prev){ + char old = SingleByteRead(ADXL345_DATA_FORMAT_REG); + if(prev) + *prev = old; + return SingleByteWrite(ADXL345_DATA_FORMAT_REG, (old | (settings & mask)) & (settings | ~mask)); +} + int ADXL345::setDataRate(char rate) { //Get the current register contents, so we don't clobber the power bit.
--- a/ADXL345.h Thu Sep 13 11:43:11 2012 +0000 +++ b/ADXL345.h Mon Sep 17 10:39:19 2012 +0000 @@ -121,6 +121,12 @@ public: + static const char RANGE_BITS = 0x3; + static const char RANGE_2G = 0x0; + static const char RANGE_4G = 0x1; + static const char RANGE_8G = 0x2; + static const char RANGE_16G = 0x3; + /** * Constructor. * @@ -184,8 +190,16 @@ * @param settings The control byte to write to the DATA_FORMAT register. */ int setDataFormatControl(char settings); + + /** + * Set the data format settings with only specified bits. + * + * @param settings The control byte to write to the DATA_FORMAT register. + * @param mask The mask bits that + */ + int setDataFormatControl(char settings, char mask, char *prev = NULL); - /** + /** * Set the data rate. * * @param rate The rate code (see #defines or datasheet). @@ -535,9 +549,7 @@ - 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.