MPU6050センサ Wallbot_BLE用 サンプル

Dependencies:   BLE_API mbed nRF51822

Revision:
15:f0306f9dc7ad
Parent:
14:700c99bb766c
Child:
16:e2386ded5c74
diff -r 700c99bb766c -r f0306f9dc7ad main.cpp
--- a/main.cpp	Tue May 19 11:35:13 2015 +0000
+++ b/main.cpp	Mon May 25 15:44:28 2015 +0000
@@ -19,7 +19,7 @@
 //#define MAX_CONN_INTERVAL 350  /**< Maximum connection interval */
 #define CONN_INTERVAL 313  /**< connection interval 250ms; in multiples of 0.125ms. (durationInMillis * 1000) / UNIT_0_625_MS; */
 #define CONN_SUP_TIMEOUT  8000 /**< Connection supervisory timeout (6 seconds); in multiples of 0.125ms. */
-#define SLAVE_LATENCY     4
+#define SLAVE_LATENCY     0
 
 
 BLEDevice   ble;
@@ -29,7 +29,6 @@
 static const char DEVICENAME[] = "BLE-Nano";
 static volatile bool  triggerSensorPolling = false;
 
-//9FDF3283-9049-CF8D-5C4D-98E7E2002731
 //const uint8_t MPU6050_adv_service_uuid[] = {
 //    0x9F,0xDF,0x32,0x83,
 //    0x90,0x49,
@@ -39,25 +38,16 @@
 //};
 
 const uint8_t MPU6050_service_uuid[] = {
-    0x31,0x27,0x00,0xE2,0xE7,0x98,
-    0x4D,0x5C,
-    0x8D,0xCF,
-    0x49,0x90,0x83,0x32,0xDF,0x9F
+    0x79,0x0B,0x56,0x80,0x62,0xC3,0x58,0x90,0xC4,0x42,0xCC,0x39,0x76,0x5E,0xC1,0x64
 };
 
 const uint8_t MPU6050_Accel_Characteristic_uuid[] = {
-    0xFF,0xA2,0x8C,0xDE,0x65,0x25,
-    0x44,0x89,
-    0x80,0x1C,
-    0x1C,0x06,0x0C,0xAC,0x97,0x67
+    0x79,0x0B,0x56,0x81,0x62,0xC3,0x58,0x90,0xC4,0x42,0xCC,0x39,0x76,0x5E,0xC1,0x64
 };
 
-static const uint8_t MPU6050_Write_Characteristic_uuid[] =
+const uint8_t MPU6050_Write_Characteristic_uuid[] =
 {
-    0x65, 0x60, 0xBE, 0x95,0xD9, 0x31, 
-    0x4F, 0x64,
-    0x95, 0x75,
-    0xC6, 0xDD, 0xB5, 0xAE, 0x7F, 0xA5
+    0x79,0x0B,0x56,0x83,0x62,0xC3,0x58,0x90,0xC4,0x42,0xCC,0x39,0x76,0x5E,0xC1,0x64
 };
 
 uint8_t accelPayload[sizeof(float)*10] = {0,};
@@ -86,26 +76,26 @@
     float   at = 0.0f;
     float   gt = 0.0f;
     float   tickerInterval = 0.0f;
-
-    Timer timer;
-    timer.start();
     
     //加速度を取得
+    Timer acTimer;
+    acTimer.start();
     mpu.getAccelero(acData);
-    timer.stop();
-    at = timer.read_ms();
-    timer.reset();
+    acTimer.stop();
+    at = acTimer.read_ms();
+    acTimer.reset();
 
     memcpy(accelPayload+sizeof(float)*0, &acData[0], sizeof(acData[0]));
     memcpy(accelPayload+sizeof(float)*1, &acData[1], sizeof(acData[1]));
     memcpy(accelPayload+sizeof(float)*2, &acData[2], sizeof(acData[2]));
 
     //ジャイロを取得
-    timer.start();
+    Timer gyTimer;
+    gyTimer.start();
     mpu.getGyro(gyData);
-    timer.stop();
-    gt = timer.read_ms();
-    timer.reset();
+    gyTimer.stop();
+    gt = gyTimer.read_ms();
+    gyTimer.reset();
     
     memcpy(accelPayload+sizeof(float)*3, &gyData[0], sizeof(gyData[0]));
     memcpy(accelPayload+sizeof(float)*4, &gyData[1], sizeof(gyData[1]));
@@ -131,7 +121,7 @@
     memcpy(accelPayload+sizeof(float)*7, &at, sizeof(at));
     memcpy(accelPayload+sizeof(float)*8, &gt, sizeof(gt));
 
-    tickerInterval = 0.02f;//(float)Gap::MSEC_TO_GAP_DURATION_UNITS(CONN_INTERVAL);
+    tickerInterval = 0.02f;
     memcpy(accelPayload+sizeof(float)*9, &tickerInterval, sizeof(tickerInterval));
 
     ble.updateCharacteristicValue(accelChar.getValueAttribute().getHandle(), accelPayload, sizeof(accelPayload));    //Mod