Reworking Freefall example to Step Counter
I wanted to implement a step counter with MetaMotionC and after reading the tutorials it seemed that refactoring the 'freefall' example might be a good approach. Unfortunately, while I usually seem to establish a connection I get persistent 'Error setting up route java.util.concurrent.TimeoutException: Creating logger timed out ....". (Note: the metamotion C works perfectly with the metawear app so the device is not the problem.)
I think I understand the overall process: Android's onCreate() sets up the UI where I place the methods reacting to clicks, and implements ServiceConnection. onServiceConnected() takes care of connecting to the device, creating the data producer, and establishing the route for the data. I don't understand how to set up the route both in the big picture (what is it and how it should be behaving) and little picture (how is it constructed). Any answers or guidance to relevant info would be appreciated, I've included what I think is the code relevant to this question below.
import com.mbientlab.metawear.module.AccelerometerBmi160;
...
private AccelerometerBmi160 accelerometer;
...
public void onServiceConnected(ComponentName name, IBinder service) {
BtleService.LocalBinder serviceBinder = (BtleService.LocalBinder) service;
String mwMacAddress= "C1:84:A2:1A:45:DF"; ///< Put your board's MAC address here
BluetoothManager btManager= (BluetoothManager) getSystemService(BLUETOOTH_SERVICE);
BluetoothDevice btDevice= btManager.getAdapter().getRemoteDevice(mwMacAddress);
mwBoard= serviceBinder.getMetaWearBoard(btDevice);
mwBoard.connectAsync().onSuccessTask(task -> {
accelerometer = mwBoard.getModuleOrThrow(AccelerometerBmi160.class);
return accelerometer.stepCounter().addRouteAsync(source ->
source.log((data, env) -> Log.i(LOG_TAG, data.toString())));
}).continueWith((Continuation<Route, Void>) task -> {
if (task.isFaulted()) {
Log.e(LOG_TAG, mwBoard.isConnected() ? "Error setting up route" : "Error connecting", task.getError());
} else {
Log.i(LOG_TAG, "Connected");
debug = mwBoard.getModule(Debug.class);
logging= mwBoard.getModule(Logging.class);
}
return null;
});
}
This discussion has been closed.
Comments