Access different power mode of BNO055 via nRF51-DK BLE

Dependencies:   BLE_API BNO055 mbed nRF51822 nrf51_rtc

Fork of BLE_LoopbackUART_with_LSM6DS3 by Sherry Yang

Revision:
4:65f91237b687
Parent:
3:c0d70871aa4d
Child:
5:cd414aaa44f6
diff -r c0d70871aa4d -r 65f91237b687 main.cpp
--- a/main.cpp	Tue Jun 21 18:13:49 2016 +0000
+++ b/main.cpp	Thu Jun 23 22:29:04 2016 +0000
@@ -33,8 +33,11 @@
 #endif /* #if NEED_CONSOLE_OUTPUT */
 
 BLEDevice  ble;
-DigitalOut led1(LED1);
-DigitalOut led4(LED4);
+// Status lights
+DigitalOut ledAlive(LED1);
+DigitalOut ledIntrG(LED3);
+// Interrupt pin connection
+InterruptIn intrGX(p14);    //INT (Gyro & Accel Interrupt)
 
 UARTService *uartServicePtr;
 
@@ -67,17 +70,20 @@
                 imu.setpowermode(POWER_MODE_LOWPOWER);
                 break;
             case 51:
-                DEBUG("High power\n\r");
+                DEBUG("No high power available for this sensor\n\r");
                 imu.setpowermode(POWER_MODE_NORMAL);
                 break;
             default:
-                DEBUG("Nothing happened\n\r");
+                DEBUG("Default power\n\r");
+                imu.setpowermode(POWER_MODE_NORMAL);
                 break;
         }
                 
         if (imu.check())
         {
-            pc.printf("BNO055 found\r\n");
+            pc.printf("BNO055 WHO_AM_I's returned: 0x%X\r\n", imu.ID.id);
+            pc.printf("Should be 0xA0\r\n");
+            imu.initIntr();
         }
         
         ble.updateCharacteristicValue(uartServicePtr->getRXCharacteristicHandle(), params->data, bytesRead);
@@ -86,17 +92,26 @@
 
 void periodicCallback(void)
 {
-    led1 = !led1;
+    ledAlive = !ledAlive;
 }
 
 // Interrupt signal
-void flip() {
-    led4 = !led4;
+void flip(DigitalOut led) {
+    led = !led;
+}
+
+void flip4() {
+//    pc.printf(" ++++ G/X Triggered!! ++++ \n\r");
+    flip(ledIntrG);
+    imu.resetIntr();
 }
 
 int main(void)
 {
-    led1 = 1;
+    // turn all LED off
+    ledAlive = 1;
+    ledIntrG = 1;
+    
     Ticker ticker;
     ticker.attach(periodicCallback, 1);
 
@@ -122,7 +137,12 @@
     
     // setup baud rate and reset sensor
     pc.baud(115200);
-    led4 = 1; 
+    
+    // setup Interrupt mode
+    intrGX.mode(PullUp);
+
+    // status light will be lit based on sensor/data change
+    intrGX.rise(&flip4);
 
     while (true) {
         ble.waitForEvent();
@@ -134,16 +154,19 @@
         pc.printf("%2f,%2f,%2f\r\n", imu.gyro.x, imu.gyro.y, imu.gyro.z);
         imu.get_mag();
         pc.printf("%2f,%2f,%2f\r\n", imu.mag.x, imu.mag.y, imu.mag.z);
+        
         // Interrupt stats: This is only enabled in Low Power Mode
         // 0 - no interrupt
         // 64 - interrupt
         // 128 - sleep
-        imu.get_intr();
-        pc.printf("intr: %d\r\n", imu.intr);
-        if(imu.intr != 0) {
-            pc.printf(" == interrupted == \r\n");
-            flip();
-        }
+        //imu.get_intr();
+//        pc.printf("intr: %d\r\n", imu.intr);
+//        if(imu.intr == 64) {
+//            pc.printf(" == interrupted == \r\n");
+//            imu.resetIntr();
+//            pc.printf("rx before: %d\r\n", imu.test3);
+//            pc.printf("rx after: %d\r\n", imu.test4);
+//        }
         
         wait(1.0);
     }