Advertisement
ivanco0071

Untitled

Feb 22nd, 2018
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.59 KB | None | 0 0
  1. public void onServiceConnected(ComponentName name, IBinder service) {
  2.         serviceBinder = (BtleService.LocalBinder) service;
  3.         String mwMacAddress= "board's MAC address ";
  4.         BluetoothManager btManager= (BluetoothManager) getSystemService(BLUETOOTH_SERVICE);
  5.         btDevice1= btManager.getAdapter().getRemoteDevice(mwMacAddress);
  6.  
  7.         mwBoard= serviceBinder.getMetaWearBoard(btDevice1);
  8.         mwBoard.connectAsync().onSuccessTask(new Continuation<Void, Task<Route>>() {
  9.             @Override
  10.             public Task<Route> then(Task<Void> task) throws Exception {
  11.  
  12.                 //accelerometer
  13.                 accelerometer = mwBoard.getModule(Accelerometer.class);
  14.                 accelerometer.configure()
  15.                         .odr(50f)
  16.                         .commit();
  17.                 Accelerometer.ConfigEditor<?> editor = accelerometer.configure();
  18.                 editor.odr(ACC_FREQ);
  19.                 if (accelerometer instanceof AccelerometerBosch) {
  20.                     editor.range(BOSCH_RANGES[rangeIndex]);
  21.                 } else if (accelerometer instanceof AccelerometerMma8452q) {
  22.                     editor.range(MMA845Q_RANGES[rangeIndex]);
  23.                 }
  24.                 editor.commit();
  25.                 samplePeriod= 1 / accelerometer.getOdr();
  26.                 final AsyncDataProducer producerAcc = accelerometer.packedAcceleration() == null ?
  27.                         accelerometer.packedAcceleration() :
  28.                         accelerometer.acceleration();
  29.                 producerAcc.addRouteAsync(source -> source.stream((data, env) -> {
  30.                     final Acceleration value = data.value(Acceleration.class);
  31.                     //HERE I HAVE ACCESS TO ACCELERATION VALUES
  32.                 })).continueWith(taskAcc -> {
  33.                     streamRouteAcc = taskAcc.getResult();
  34.                     producerAcc.start();
  35.                     accelerometer.start();
  36.                     return null;
  37.                 });
  38.  
  39.                 //gyro
  40.                 gyroBmi160 = mwBoard.getModule(GyroBmi160.class);
  41.                 gyroBmi160.configure()
  42.                         .odr(GyroBmi160.OutputDataRate.ODR_50_HZ)
  43.                         .range(GyroBmi160.Range.FSR_2000)
  44.                         .commit();
  45.                 final float period = 1 / GYR_ODR;
  46.                 final AsyncDataProducer producerGYRO = gyroBmi160.packedAngularVelocity() == null ?
  47.                         gyroBmi160.packedAngularVelocity() :
  48.                         gyroBmi160.angularVelocity();
  49.                 producerGYRO.addRouteAsync(source -> source.stream((data, env) -> {
  50.                     final AngularVelocity value = data.value(AngularVelocity.class);
  51.                     //HERE I HAVE ACCESS TO GYRO VALUES
  52.                 })).continueWith(taskGYRO -> {
  53.                     streamRouteGYRO = taskGYRO.getResult();
  54.                     gyroBmi160.angularVelocity().start();
  55.                     gyroBmi160.start();
  56.                     return null;
  57.                 });
  58.  
  59.                 return null;
  60.             }
  61.         }).continueWith(new Continuation<Route, Void>() {
  62.             @Override
  63.             public Void then(Task<Route> task) throws Exception {
  64.                 accelerometer.acceleration().start();
  65.                 accelerometer.start();
  66.                 return null;
  67.             }
  68.         });
  69.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement