metaWearBoard.connectAsync()
.onSuccessTask(task -> {
final SensorFusionBosch accelerometer = metaWearBoard.getModule(SensorFusionBosch.class);
accelerometer.configure()
.gyroExtra()
.mode(SensorFusionBosch.Mode.NDOF)
.accRange(SensorFusionBosch.AccRange.AR_16G)
.gyroRange(SensorFusionBosch.GyroRange.GR_2000DPS)
.commit();
accelerometerCapture.set(accelerometer);
final AsyncDataProducer orientation = accelerometer.quaternion();
orientCapture.set(orientation);
return orientation.addRouteAsync(source -> source.stream((data, env) -> {
final Quaternion quaternion = data.value(Quaternion.class);
listener.onValue((Math.abs(quaternion.x() * 1000)));
Log.d(TAG, " mEquipmentList.size() = " + mEquipmentList.size() +
" sensorsBar.isSetFirstValue(): " + sensorsBar.isSetFirstValue() +
" sensorsBar.isSetFirstValueSecond(): " + sensorsBar.isSetFirstValueSecond());
Log.d(TAG, "quaternion x = " + quaternion.x() + " value: " + (Math.abs(quaternion.x() * 1000)));
}));
})
.onSuccessTask(task -> metaWearBoard.getModule(Switch.class).state().addRouteAsync(source -> source.stream((data, env) -> {
Log.d(TAG, "pressed = " + data.value(Boolean.class));
}))).continueWith((Continuation<Route, Void>) task -> {
if (task.isFaulted() && !metaWearBoard.isConnected()) {
Log.d(TAG, "task.isFaulted() = " + task.isFaulted() + ";;metaWearBoard.isConnected()" + metaWearBoard.isConnected());
Log.d(TAG, "task.isFaulted() = " + task.getError() + "===" + task.getResult());
//reconnect(metaWearBoard);
} else if (task.isFaulted()) {
Log.d(TAG, "task.isFaulted() = " + task.isFaulted());
metaWearBoard.tearDown();
metaWearBoard.disconnectAsync();
} else {
orientCapture.get().start();
accelerometerCapture.get().start();
}
return null;
})
public static Task<Void> reconnect(final MetaWearBoard board) {
Log.d(TAG, "reconnect = " + board.getMacAddress());
return board.connectAsync()
.continueWithTask(task -> {
if (task.isFaulted()) {
Log.d(TAG, "reconnect = " + task.getResult() + "==" + task.getError());
return reconnect(board);
} else if (task.isCancelled()) {
return task;
} else {
Log.d(TAG, "reconnect = " + task.getResult() + "==" + task.toString());
}
return Task.forResult(null);
});
}
Comments
What is this? Please read our forum guidelines before posting or this post will be deleted.
oops, beacuse of some formation issue my quetion not display here. Sorry, I will delete this post if I am able to do that.