MPU6050センサ Wallbot_BLE用 サンプル
Dependencies: BLE_API mbed nRF51822
Diff: main.cpp
- Revision:
- 6:e640afab8288
- Parent:
- 5:807096fdd895
- Child:
- 7:e18346358299
diff -r 807096fdd895 -r e640afab8288 main.cpp --- a/main.cpp Fri Jan 30 16:42:24 2015 +0000 +++ b/main.cpp Sat Jan 31 21:54:53 2015 +0000 @@ -57,8 +57,8 @@ // 0xC6, 0xDD, 0xB5, 0xAE, 0x7F, 0xA5 //}; -uint8_t accelPayload[sizeof(float)*7] = {0,}; -uint8_t writePayload[3] = {0}; +uint8_t accelPayload[sizeof(float)*8] = {0,}; +uint8_t writePayload[3] = {0,}; //uint8_t gyroPayload[sizeof(float)*3] = {0,0,0}; //uint8_t tempPayload[sizeof(float)*1] = {0}; @@ -66,7 +66,7 @@ //uint8_t read_batt = 0; /* Variable to hold battery level reads */ GattCharacteristic accelChar (MPU6050_Accel_Characteristic_uuid, - accelPayload, (sizeof(float) * 7), (sizeof(float) * 7), + accelPayload, (sizeof(float) * 8), (sizeof(float) * 8), GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ); GattCharacteristic writeChar (MPU6050_Write_Characteristic_uuid, @@ -82,6 +82,8 @@ GattCharacteristic *ControllerChars[] = { &accelChar, &writeChar, }; GattService MPU6050Service(MPU6050_service_uuid, ControllerChars, sizeof(ControllerChars) / sizeof(GattCharacteristic *)); +Timer timer; + void updateValue(); void disconnectionCallback(Gap::Handle_t handle, Gap::DisconnectionReason_t reason) // Mod @@ -217,8 +219,8 @@ //pc.printf("mpu test:NG\n\r"); } - Ticker ticker; - ticker.attach(periodicCallback, 0.25f); //1sec + //Ticker ticker; + //ticker.attach(periodicCallback, 0.25f); //1sec ble.init(); ble.onDisconnection(disconnectionCallback); @@ -243,12 +245,12 @@ ble.addService(MPU6050Service); while(true) { - if (triggerSensorPolling && ble.getGapState().connected) { - triggerSensorPolling = false; + //if (triggerSensorPolling && ble.getGapState().connected) { + //triggerSensorPolling = false; updateValue(); - } else { - ble.waitForEvent(); - } + //} else { + // ble.waitForEvent(); + //} } } @@ -256,7 +258,10 @@ float acData[3]; float gyData[3]; - float tempData = 0.0; + float tempData = 0.0f; + float t = 0.0f; + + timer.start(); //加速度を取得 mpu.getAccelero(acData); @@ -290,6 +295,9 @@ pc.printf("Temp: %.3lf\r\n", *(float*)&tempPayload[sizeof(float)*0]); pc.printf("Battery: %d\r\n", batt); */ - + timer.stop(); + t = timer.read_ms(); + memcpy(accelPayload+sizeof(float)*7, &t, sizeof(t)); + timer.reset(); ble.updateCharacteristicValue(accelChar.getValueAttribute().getHandle(), accelPayload, sizeof(accelPayload)); //Mod }