Calibrate Sensor

edited March 2022 in Android

I am trying to calibrate my sensors using the sample code provided in the documentation. I can get it to work with no problems when displaying the calibration results to the log, but I cannot get it to update TextView fields on my device. In the following code the state.acceleromter.toString() will out the value to the log properly, but I cannot get it to change the value of the text fields on the device using setText(state.accelerometer.toString()). I get the following errors: Only the original thread that created a view hierarchy can touch its views.

I put the calibrate inside a runOnUiThread and that did not help. Any idea what I am doing wrong? Also, when I add the lines to log or settext other than the first Log.i the code will only run one time through and then stop. If I remove all of those lines and have only the first Log.I it runs properly.

sensorFusionBosch.calibrate(cts.getToken(), state -> {
Log.i("MainActivity", state.toString());
Log.d("MainActivity", state.accelerometer.toString());
Log.d("MainActivity", state.gyroscope.toString());
Log.d("MainActivity", state.magnetometer.toString());

Thank you.

Sign In or Register to comment.