Republished Library, to be refined for use with the SparkFun 9DOF in HARP project.
Fork of ADXL345 by
Diff: ADXL345.cpp
- Revision:
- 3:7b83694c7292
- Parent:
- 2:e64d8b9096cd
- Child:
- 4:8046894b947e
--- a/ADXL345.cpp Sun Sep 09 15:37:26 2012 +0000 +++ b/ADXL345.cpp Thu Sep 13 11:43:11 2012 +0000 @@ -1,4 +1,5 @@ /** + * @file ADXL345.cpp * @author Peter Swanson * A personal note from me: Jesus Christ has changed my life so much it blows my mind. I say this because * today, religion is thought of as something that you do or believe and has about as @@ -46,7 +47,7 @@ * http://www.analog.com/static/imported-files/data_sheets/ADXL345.pdf */ -/** +/* * Includes */ #include "ADXL345.h" @@ -136,12 +137,9 @@ char buffer[6]; multiByteRead(ADXL345_DATAX0_REG, buffer, 6); - // Readings are expressed in 16bit 2's complement, so we must first - // concatenate two bytes to make a word and sign extend it to obtain - // correct negative values. - readings[0] = (int)int16_t(uint16_t(buffer[1]) << 8 | buffer[0]); - readings[1] = (int)int16_t(uint16_t(buffer[3]) << 8 | buffer[2]); - readings[2] = (int)int16_t(uint16_t(buffer[5]) << 8 | buffer[4]); + readings[0] = wordExtend(&buffer[0]); + readings[1] = wordExtend(&buffer[2]); + readings[2] = wordExtend(&buffer[4]); }