Forked from Uwe Gartmann's ADXL345 library, customized as part of the 9DOF stick from Sparkfun.com

Fork of ADXL345 by Uwe Gartmann

ADXL345 is triple axis, digital interface, accelerometer.

This library is forked from Uwe Gartmann and Peter Swanson's work.

This library is for specific application using 9DoF-Stick.

Datasheet:

http://www.analog.com/static/imported-files/data_sheets/ADXL345.pdf

ADXL345は3軸のデジタルインターフェースを備えた加速度センサです。

このライブラリは 9DoF-Stick を使用した特定の企画のために保守しています。

mbed IDEが日本語をサポートするまでは英語でコメントを書いていきますが、サポートした後もきっと英語で書いていくでしょう。

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]);
 
 }