I am currently working on an app that needs to know, as accurately as possible, the bearing of the host device.
To do this I am using the Phonesensors object to obtain the device's accelerometer, magnetometer and (optionally) gyroscope sensor readings which I then "fuse" using a piece of code I created by translating into B4X the Java code at:
http://plaw.info/2012/03/android-sensor-fusion-tutorial/
All seems to be working fine - except that the magnetometer readings are a real bear in that the magnetometer needs regular recalibrating.
My problem is finding a way to get the app to tell the user when recalibrating is required.
I have written a small activity that allows you to visually ascertain the state of calibration of the magnetometer by comparing measured magnetic intensity and inclination with that expected at the device's lat/long. But this doesn't really help with ascertaining when the magnetometer should be recalibrated.
Various compass apps seem to have the ability to do this and my Samsung S5 has a "secret" indicator of magnetometer calibration "health" (go to Phone app, dial *#0*# then tap [Sensor] then look under [Magnetic Sensor] for a small black dial with a number between 0 and 3 in it).
Looking at:
https://developer.android.com/reference/android/hardware/SensorEvent.html
it would appear that the Android SensorEvent has an accuracy property that is updated every time a new set of magnetometer sensor readings is given. This property can have values of SENSOR_STATUS_ACCURACY_HIGH(3), SENSOR_STATUS_ACCURACY_MEDIUM(2), SENSOR_STATUS_ACCURACY_LOW(1), SENSOR_STATUS_UNRELIABLE(0) or SENSOR_STATUS_NO_CONTACT(-1).
I'm guessing, but it would appear highly likely that the B4A Phonesensors object uses the Android Sensorevent to fire the Phonesensors.SensorChanged event.
If this is the case then it seems like a pretty trivial exercise for someone with the appropriate skills to add an Accuracy property to the Phonesensors object that would provide the functionality I am looking for.
If this is not readily possible is there any JavaObject style workaround possible.
Thanks...
To do this I am using the Phonesensors object to obtain the device's accelerometer, magnetometer and (optionally) gyroscope sensor readings which I then "fuse" using a piece of code I created by translating into B4X the Java code at:
http://plaw.info/2012/03/android-sensor-fusion-tutorial/
All seems to be working fine - except that the magnetometer readings are a real bear in that the magnetometer needs regular recalibrating.
My problem is finding a way to get the app to tell the user when recalibrating is required.
I have written a small activity that allows you to visually ascertain the state of calibration of the magnetometer by comparing measured magnetic intensity and inclination with that expected at the device's lat/long. But this doesn't really help with ascertaining when the magnetometer should be recalibrated.
Various compass apps seem to have the ability to do this and my Samsung S5 has a "secret" indicator of magnetometer calibration "health" (go to Phone app, dial *#0*# then tap [Sensor] then look under [Magnetic Sensor] for a small black dial with a number between 0 and 3 in it).
Looking at:
https://developer.android.com/reference/android/hardware/SensorEvent.html
it would appear that the Android SensorEvent has an accuracy property that is updated every time a new set of magnetometer sensor readings is given. This property can have values of SENSOR_STATUS_ACCURACY_HIGH(3), SENSOR_STATUS_ACCURACY_MEDIUM(2), SENSOR_STATUS_ACCURACY_LOW(1), SENSOR_STATUS_UNRELIABLE(0) or SENSOR_STATUS_NO_CONTACT(-1).
I'm guessing, but it would appear highly likely that the B4A Phonesensors object uses the Android Sensorevent to fire the Phonesensors.SensorChanged event.
If this is the case then it seems like a pretty trivial exercise for someone with the appropriate skills to add an Accuracy property to the Phonesensors object that would provide the functionality I am looking for.
If this is not readily possible is there any JavaObject style workaround possible.
Thanks...