Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void onServiceConnected(ComponentName name, IBinder service) {
- serviceBinder = (BtleService.LocalBinder) service;
- String mwMacAddress= "board's MAC address ";
- BluetoothManager btManager= (BluetoothManager) getSystemService(BLUETOOTH_SERVICE);
- btDevice1= btManager.getAdapter().getRemoteDevice(mwMacAddress);
- mwBoard= serviceBinder.getMetaWearBoard(btDevice1);
- mwBoard.connectAsync().onSuccessTask(new Continuation<Void, Task<Route>>() {
- @Override
- public Task<Route> then(Task<Void> task) throws Exception {
- //accelerometer
- accelerometer = mwBoard.getModule(Accelerometer.class);
- accelerometer.configure()
- .odr(50f)
- .commit();
- Accelerometer.ConfigEditor<?> editor = accelerometer.configure();
- editor.odr(ACC_FREQ);
- if (accelerometer instanceof AccelerometerBosch) {
- editor.range(BOSCH_RANGES[rangeIndex]);
- } else if (accelerometer instanceof AccelerometerMma8452q) {
- editor.range(MMA845Q_RANGES[rangeIndex]);
- }
- editor.commit();
- samplePeriod= 1 / accelerometer.getOdr();
- final AsyncDataProducer producerAcc = accelerometer.packedAcceleration() == null ?
- accelerometer.packedAcceleration() :
- accelerometer.acceleration();
- producerAcc.addRouteAsync(source -> source.stream((data, env) -> {
- final Acceleration value = data.value(Acceleration.class);
- //HERE I HAVE ACCESS TO ACCELERATION VALUES
- })).continueWith(taskAcc -> {
- streamRouteAcc = taskAcc.getResult();
- producerAcc.start();
- accelerometer.start();
- return null;
- });
- //gyro
- gyroBmi160 = mwBoard.getModule(GyroBmi160.class);
- gyroBmi160.configure()
- .odr(GyroBmi160.OutputDataRate.ODR_50_HZ)
- .range(GyroBmi160.Range.FSR_2000)
- .commit();
- final float period = 1 / GYR_ODR;
- final AsyncDataProducer producerGYRO = gyroBmi160.packedAngularVelocity() == null ?
- gyroBmi160.packedAngularVelocity() :
- gyroBmi160.angularVelocity();
- producerGYRO.addRouteAsync(source -> source.stream((data, env) -> {
- final AngularVelocity value = data.value(AngularVelocity.class);
- //HERE I HAVE ACCESS TO GYRO VALUES
- })).continueWith(taskGYRO -> {
- streamRouteGYRO = taskGYRO.getResult();
- gyroBmi160.angularVelocity().start();
- gyroBmi160.start();
- return null;
- });
- return null;
- }
- }).continueWith(new Continuation<Route, Void>() {
- @Override
- public Void then(Task<Route> task) throws Exception {
- accelerometer.acceleration().start();
- accelerometer.start();
- return null;
- }
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement