サイコン用プログラム BLE通信送信確認
Dependencies: mbed BLE_API nRF51822
Revision 11:5a3dcafaffbb, committed 2015-03-15
- Comitter:
- mbed_tw_hoehoe
- Date:
- Sun Mar 15 12:13:13 2015 +0000
- Parent:
- 10:f226b7907cf2
- Child:
- 12:6ef51c5442dd
- Commit message:
- commit.
Changed in this revision
MPU6050_Mod.lib | Show annotated file Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/MPU6050_Mod.lib Sat Mar 14 15:22:51 2015 +0000 +++ b/MPU6050_Mod.lib Sun Mar 15 12:13:13 2015 +0000 @@ -1,1 +1,1 @@ -https://developer.mbed.org/users/ghz2000/code/MPU6050_Mod/#51e64f45125c +http://developer.mbed.org/users/mbed_tw_hoehoe/code/MPU6050_Mod/#8ed0265c2c92
--- a/main.cpp Sat Mar 14 15:22:51 2015 +0000 +++ b/main.cpp Sun Mar 15 12:13:13 2015 +0000 @@ -24,11 +24,10 @@ BLEDevice ble; -//MPU6050 mpu(p4, p5); MPU6050 mpu(I2C_SDA0, I2C_SCL0); static const char DEVICENAME[] = "BLE-Nano"; -//static volatile bool triggerSensorPolling = false; +static volatile bool triggerSensorPolling = false; //9FDF3283-9049-CF8D-5C4D-98E7E2002731 //const uint8_t MPU6050_adv_service_uuid[] = { @@ -113,13 +112,13 @@ *(float*)&accelPayload[sizeof(float)*0], *(float*)&accelPayload[sizeof(float)*1], *(float*)&accelPayload[sizeof(float)*2]); - + pc.printf("Gyro: %.3lf,%.3lf,%.3lf\r\n", - *(float*)&gyroPayload[sizeof(float)*0], - *(float*)&gyroPayload[sizeof(float)*1], - *(float*)&gyroPayload[sizeof(float)*2]); - - pc.printf("Temp: %.3lf\r\n", *(float*)&tempPayload[sizeof(float)*0]); + *(float*)&accelPayload[sizeof(float)*3], + *(float*)&accelPayload[sizeof(float)*4], + *(float*)&accelPayload[sizeof(float)*5]); + + pc.printf("Temp: %.3lf\r\n", *(float*)&accelPayload[sizeof(float)*6]); */ timer.stop(); @@ -167,7 +166,6 @@ } void onDataWrittenCallback(const GattCharacteristicWriteCBParams *params){ - char acceleroRange = 0xFF; char gyroRange = 0xFF; @@ -205,19 +203,20 @@ gyroRange = MPU6050_GYRO_RANGE_250; break; case 1: - gyroRange = MPU6050_GYRO_RANGE_250; + gyroRange = MPU6050_GYRO_RANGE_500; break; case 2: - gyroRange = MPU6050_GYRO_RANGE_250; + gyroRange = MPU6050_GYRO_RANGE_1000; break; case 3: - gyroRange = MPU6050_GYRO_RANGE_250; + gyroRange = MPU6050_GYRO_RANGE_2000; break; default: break; } - mpu.setAcceleroRange(acceleroRange); - mpu.setGyroRange(gyroRange); + mpu.mpu_set_accel_fsr(acceleroRange); + mpu.mpu_set_gyro_fsr(gyroRange); + } } } @@ -236,8 +235,7 @@ /* Note that the periodicCallback() executes in interrupt context, so it is safer to do * heavy-weight sensor polling from the main thread. */ - //triggerSensorPolling = true; - updateValue(); + triggerSensorPolling = true; } /**************************************************************************/ @@ -274,7 +272,7 @@ } Ticker ticker; - ticker.attach(periodicCallback, 0.25f); //1sec + ticker.attach(periodicCallback, 0.2f); //.2f-sec ble.init(); ble.onDisconnection(disconnectionCallback); @@ -299,12 +297,12 @@ ble.addService(MPU6050Service); while(true) { - //if (triggerSensorPolling && ble.getGapState().connected) { - //triggerSensorPolling = false; - //updateValue(); - //} else { + if (triggerSensorPolling && ble.getGapState().connected) { + triggerSensorPolling = false; + updateValue(); + } else { ble.waitForEvent(); - //} + } } }