Modified getOffset for calibrating Thermal Drift coefficients.

Dependents:   9Dof_unit_testing

Fork of ITG3200 by James Watanabe

Modified to make getOffset() function easier to use.

Revision:
8:ac0365ab3cef
Parent:
7:43b936a53b64
Child:
9:05396b551a9a
--- a/ITG3200.cpp	Sat Sep 29 14:34:17 2012 +0000
+++ b/ITG3200.cpp	Tue Oct 02 17:09:20 2012 +0000
@@ -34,8 +34,11 @@
  */
 
 #include "ITG3200.h"
+#include <new>
 
-ITG3200::ITG3200(PinName sda, PinName scl, bool fastmode) : calibSamples(0), i2c_(sda, scl){
+ITG3200::ITG3200(PinName sda, PinName scl, bool fastmode) : calibSamples(0), i2c_(*reinterpret_cast<I2C*>(i2cRaw)){
+    // Placement new to avoid additional heap memory allocation.
+    new(i2cRaw) I2C(sda, scl);
 
     offset[0] = offset[1] = offset[2] = 0;
 
@@ -45,7 +48,15 @@
     }
     else
         i2c_.frequency(100000);
+}    
     
+ITG3200::~ITG3200(){
+    // If the I2C object is initialized in the buffer in this object, call destructor of it.
+    if(&i2c_ == reinterpret_cast<I2C*>(&i2cRaw))
+        reinterpret_cast<I2C*>(&i2cRaw)->~I2C();
+}
+
+void ITG3200::init(){
     //Set FS_SEL to 0x03 for proper operation.
     //See datasheet for details.
     char tx[2];