Starting up accelerometer logging on boot

miqmiq
edited May 2017 in Android
Hi Eric,

I am trying to teach Metawear C to log accelerometer readouts right after boot and I have troubles putting it correctly together.

The problem is with accelerometer and logging start commands. If I put them as in the code below, the logging never starts after reboot as if the continuation task is invisible to the macro. I need to connect to the board, run this code again and from this point logging starts working perfectly.

I tried two other alternatives... If I place accelerometer and logging start in Place A in the code, reboot the board, connect to it and dowload log all hell seems to break loose. I get lots of NullPointerExceptions from the board as if there is some thread race going on (understandable as I probably start logging before the route has been set up properly).

If I place acceloremeter and logging start in Place B in the code, reboot the board and connect to it and download the log it looks like the logging has started after reboot, but there is no acceloremeter data there. I download some data logged before reboot and then hundreds of empty log entries.

Do you have an idea how can I implement it properly?

Comments


  •         macro.startRecord(true);
            accelerometer.configure().odr(AccelerometerBmi160.OutputDataRate.ODR_6_25_HZ).range(AccelerometerBosch.AccRange.AR_8G).commit();
    accelerometer.acceleration().addRouteAsync(new RouteBuilder() {
    @Override
    public void configure(RouteComponent source) {
    source.multicast().
    to().split().index(0).log(new Subscriber() {
    @Override
    public void apply(Data data, Object... env) {
    Log.i("MainActivity", "x = " + String.format("%.2f", data.value(Float.class)));
    }
    });
    // *** Place B ***
    }
    }).continueWith(new Continuation<Route, Void>() {
    public Void then(Task<Route> task) throws Exception {
    accelerometer.acceleration().start();
    accelerometer.start();
    Log.i("MainActivity", "Accelerometer started");
    logging.start(false);
    Log.i("MainActivity", "Logging started");
    return null;
    }
    });

    // *** Place A ***

    macro.endRecordAsync().continueWith(new Continuation<Byte, Void>() {
    @Override
    public Void then(Task<Byte> task) throws Exception {
    Log.i("MainActivity", "Macro ID = " + task.getResult());
    return null;
    }
    });
This discussion has been closed.