Unable to get step counter data
Hi all,
just recently looked into the mbientlab c / cpro again and I am currently evaluating the boards for a eHealth project. I want to do step counting, get double-taps, etc.
So I started with a plain and easy android app, no UI right now, all I want is to get the total number of steps. While I get called for each step taken, the total number of steps is never called - I never see that log output. Can someone see what is wrong with the code?
public void detectSteps()
{
Log.i("MainActivity", "Starting to detect steps...");
try {
final Bmi160Accelerometer bmi160AccModule= mwBoard.getModule(Bmi160Accelerometer.class);
bmi160AccModule.start();
bmi160AccModule.enableStepDetection();
bmi160AccModule.routeData().fromStepCounter(true).stream("step_counter").commit().onComplete(new AsyncOperation.CompletionHandler<RouteManager>() {
@Override
public void success(RouteManager result) {
result.subscribe("step_counter", new RouteManager.MessageHandler() {
@Override
public void process(Message msg) {
Log.i("MainActivity", "Steps= " + msg.getData(Integer.class));
}
});
}
});
// Receive notifications for each step Eed
bmi160AccModule.routeData().fromStepDetection().stream("step_detector").commit()
.onComplete(new AsyncOperation.CompletionHandler<RouteManager>() {
@Override
public void success(RouteManager result) {
result.subscribe("step_detector", new RouteManager.MessageHandler() {
@Override
public void process(Message message) {
Log.i("MainActivity", "You took a step");
}
});
}
}
);
} catch (UnsupportedModuleException e) {
e.printStackTrace();
}
}
This discussion has been closed.
Comments
thx!
Sven
final Bmi160Accelerometer bmi160AccModule= mwBoard.getModule(Bmi160Accelerometer.class);
final boolean silent= false;
bmi160AccModule.configureStepDetection().enableStepCounter().setSensitivity(Bmi160Accelerometer.StepSensitivity.ROBUST).commit();
bmi160AccModule.enableStepDetection();
bmi160AccModule.routeData().fromStepCounter(silent).stream("step_counter").commit().onComplete(new AsyncOperation.CompletionHandler<RouteManager>() {
@Override
public void success(RouteManager result) {
result.subscribe("step_counter", new RouteManager.MessageHandler() {
@Override
public void process(Message msg) {
Log.i("MainActivity", "Steps= " + msg.getData(Integer.class));
}
});
}
});
bmi160AccModule.start();
AsyncOperation<Timer.Controller> taskResult= mwBoard.getModule(Timer.class)
.scheduleTask(new Timer.Task() {
@Override
public void commands() {
bmi160AccModule.readStepCounter(silent);
}
}, 10000, false);
taskResult.onComplete(new AsyncOperation.CompletionHandler<Timer.Controller>() {
@Override
public void success(Timer.Controller result) {
// start executing the task
result.start();
}
});
This code works for me on my CPro.