Possible bug in Android calibration

Hi everyone,

I'm a newbie at this forum so, greetings to all and my apologies in advance if I'm saying something known for all (I've searched in the forum but I haven't found anything about this topic).

Following the Android tutorial for the use of sensorFusion, in the calibration section appears this piece of code:

final SensorFusionBosch sensorFusion = metawear.getModule(SensorFusionBosch.class);
final CancellationTokenSource cts = new CancellationTokenSource();

sensorFusion.calibrate(cts.getToken(), state -> Log.i("MainActivity", state.toString()))
    .onSuccess(task -> {
        // calibration data is reloaded everytime mode changes
        sensorFusion.writeCalibrationData(task.getResult());
        return null;
    });

However, inside the SensorFusionBosch.calibrate(CancellationToken ct, long pollingPeriod, CalibrationStateUpdateHandler updateHandler) method there is a conditional assignment with the form:

ct.isCancellationRequested() ? readCalibrationStateAsync().onSuccessTask(task -> { /* calibration process */}) : Task.cancelled();

This means that the calibration only is done when ct.isCancellationRequested() is true so, using the sample code, the calibration is never done because, by default, cts.isCancellationRequested() is false unless cts.cancel() is called.

IMHO the conditional assignment should be switched (in order to clarify the semantics) but if not, the calibration code should look like this:

final SensorFusionBosch sensorFusion = metawear.getModule(SensorFusionBosch.class);
final CancellationTokenSource cts = new CancellationTokenSource();
cts.cancel();

sensorFusion.calibrate(cts.getToken(), state -> Log.i("MainActivity", state.toString()))
    .onSuccess(task -> {
        // calibration data is reloaded everytime mode changes
        sensorFusion.writeCalibrationData(task.getResult());
        return null;
    });

Comments

Sign In or Register to comment.