Combine AS7000 into BNO055

Fork of BNO055 by Sog Yang

Revision:
1:2c3322a8d417
Parent:
0:24f23c36dd24
Child:
2:695c6e5d239a
diff -r 24f23c36dd24 -r 2c3322a8d417 BNO055.cpp
--- a/BNO055.cpp	Thu May 28 19:22:25 2015 +0000
+++ b/BNO055.cpp	Sat May 30 18:36:36 2015 +0000
@@ -8,7 +8,7 @@
     accel_scale = 1.0f;
     rate_scale = 1.0f/16.0f;
     angle_scale = 1.0f/16.0f;
-    temp_scale = 1.0f;
+    temp_scale = 1;
     }
     
 void BNO055::reset(){
@@ -93,16 +93,23 @@
 void BNO055::set_temp_units(char units){
     readchar(BNO055_UNIT_SEL_ADDR);
     if (units == CENTIGRADE){
-        rx = rx & 0x7F;
-        temp_scale = 1.0f;
+        rx = rx & 0xEF;
+        temp_scale = 1;
         }
     else {
         rx = rx | units;
-        temp_scale = 2.0f;
+        temp_scale = 2;
         }
     writechar(BNO055_UNIT_SEL_ADDR,rx);
 }    
 
+void BNO055::set_orientation(char units){
+    readchar(BNO055_UNIT_SEL_ADDR);
+    if (units == WINDOWS) rx = rx &0x7F;
+    else rx = rx | units;
+    writechar(BNO055_UNIT_SEL_ADDR,rx);
+}        
+
 void BNO055::setmode(char omode){
     writechar(BNO055_OPR_MODE_ADDR,omode);
     op_mode = omode;
@@ -173,7 +180,88 @@
     gravity.z = float(gravity.rawz)*accel_scale;
 }
 
+void BNO055::get_quat(void){
+    tx[0] = BNO055_QUATERNION_DATA_W_LSB_ADDR;
+    _i2c.write(address,tx,1,true);  
+    _i2c.read(address+1,rawdata,8,0); 
+    quat.raww = (rawdata[1] << 8 | rawdata[0]);
+    quat.rawx = (rawdata[3] << 8 | rawdata[2]);
+    quat.rawy = (rawdata[5] << 8 | rawdata[4]);
+    quat.rawz = (rawdata[7] << 8 | rawdata[6]);
+    quat.w = float(quat.raww)/16384.0f;
+    quat.x = float(quat.rawx)/16384.0f;
+    quat.y = float(quat.rawy)/16384.0f;
+    quat.z = float(quat.rawz)/16384.0f;
+}
+
+void BNO055::get_temp(void){
+    readchar(BNO055_TEMP_ADDR);
+    temperature = rx / temp_scale;
+}
+
 void BNO055::get_calib(void){
      readchar(BNO055_CALIB_STAT_ADDR);
      calib = rx;
+}
+
+void BNO055::read_calibration_data(void){
+    char tempmode = op_mode;
+    setmode(OPERATION_MODE_CONFIG);
+    wait_ms(20);
+    tx[0] = ACCEL_OFFSET_X_LSB_ADDR;
+    _i2c.write(address,tx,1,true);  
+    _i2c.read(address,calibration,22,false); 
+    setmode(tempmode);
+    wait_ms(10);
+}
+
+void BNO055::write_calibration_data(void){
+    char tempmode = op_mode;
+    setmode(OPERATION_MODE_CONFIG);
+    wait_ms(20);
+    tx[0] = ACCEL_OFFSET_X_LSB_ADDR;
+    _i2c.write(address,tx,1,true);  
+    _i2c.write(address,calibration,22,false); 
+    setmode(tempmode);
+    wait_ms(10);
+}
+
+void BNO055::set_mapping(char orient){
+    switch (orient){
+        case 0: 
+            writechar(BNO055_AXIS_MAP_CONFIG_ADDR,0x21);
+            writechar(BNO055_AXIS_MAP_SIGN_ADDR,0x04);
+            break;
+        case 1:
+            writechar(BNO055_AXIS_MAP_CONFIG_ADDR,0x24);
+            writechar(BNO055_AXIS_MAP_SIGN_ADDR,0x00);
+            break;
+        case 2:
+            writechar(BNO055_AXIS_MAP_CONFIG_ADDR,0x24);
+            writechar(BNO055_AXIS_MAP_SIGN_ADDR,0x00);
+            break;
+        case 3:
+            writechar(BNO055_AXIS_MAP_CONFIG_ADDR,0x21);
+            writechar(BNO055_AXIS_MAP_SIGN_ADDR,0x02);
+            break;
+        case 4:
+            writechar(BNO055_AXIS_MAP_CONFIG_ADDR,0x24);
+            writechar(BNO055_AXIS_MAP_SIGN_ADDR,0x03);
+            break;
+        case 5:
+            writechar(BNO055_AXIS_MAP_CONFIG_ADDR,0x21);
+            writechar(BNO055_AXIS_MAP_SIGN_ADDR,0x01);
+            break;
+        case 6:
+            writechar(BNO055_AXIS_MAP_CONFIG_ADDR,0x21);
+            writechar(BNO055_AXIS_MAP_SIGN_ADDR,0x07);
+            break;
+        case 7:
+            writechar(BNO055_AXIS_MAP_CONFIG_ADDR,0x24);
+            writechar(BNO055_AXIS_MAP_SIGN_ADDR,0x05);
+            break;
+        default:
+            writechar(BNO055_AXIS_MAP_CONFIG_ADDR,0x24);
+            writechar(BNO055_AXIS_MAP_SIGN_ADDR,0x00);
+        }
 }
\ No newline at end of file