teamacid / android_device_samsung_galaxys4gmtd

CyanogenMod Device Tree for the Galaxy S 4G

Home Page:http://forum.xda-developers.com/showthread.php?t=1618016

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Compass returning inaccurate readings

RebelliousX opened this issue · comments

It seems the compass semi working If I hold the phone in landscape orientation, but doesn't give correct reading. It has been like that since I flashed CM7, I thought it could be magnetic interference.

Z-Device test app shows that Magnetic field Z is way off and even doesn't show on the graph (oscillator, liner or whatever it is called)

Calibrating the compass doesn't change anything. I used different apps all of them the same. It used to be working fine before when I was using Valhalla, if it wasn't just calibrating it would suffice to make it work. But now I can't :/

Google maps doesn't rotate correctly when I start moving in compass mode too..

Can anyone else confirm this is an issue on CM7 or CM9 or both?

I can confirm this occurs in maps also and did not occur in Valhalla. I am also unable to calibrate it out and everything else save the compass is working flawlessly. Compass is way off and I believe my GPS is also suffering from these incorrect readings put out by the compass. I can only sometimes get a lock but it still gets with in 30 meters.

I also upgraded to CM9, still the same.

Also, when I use Compass app made by Catch. As soon as I run it, it displays a message saying that Compass
readings is way off.

Recently, I noticed that if I hold my phone while the screen is facing the ground above my head, the compass will respond to the moving and rotation of the phone, but still gives incorrect readings. If the screen is facing the sky the compass is stuck at fixed point.

Dunno if it has anything to do with accelerometer affecting it. seems like one of the axes is flipped, I think it is the Z axis. I could be wrong though.

Latest Changes in official CM9 upstream should fix the Compass, but it doesn't
The compass almost works if the screen is facing the ground, and fixed (that is, not moving) if facing the sky.

Sensor: Add RotationVectorSensor2

Some ICS apps (namely, Google Maps) expects a rotation vector to be
available. Newer devices, this is provided by either Android's
sensor fusion (requires Gyro) or by hardware sensor fusion (MPL).

Older devices will lack this virtual sensor and compass in Google
Maps will not work. To fix this, we can provide our own rotation
vector sensor by converting the values from the orientation sensor.
(They are basically the same information in different formats.)

Thanks to Unhelpful for the help with related math.

Change-Id: I596f5dc44f8797bc280ae5d1e110bb92387c79d1

http://review.cyanogenmod.com/#/c/14609/

Here is a dump of logcat.
http://pastebin.com/vVXTba2B

as you can see, starting from

09-04 02:36:47.496 I/Compass (9642): Compass onCreate

there is

09-04 02:37:29.785 I/Compass (9642): Magnetic Declination: -3.5207634; Expected Field Strength: 54.27791
09-04 02:37:29.785 I/Compass (9642): Lower Abnormal Field Limit: 19.737421; Upper Abnormal Field Limit: 149.26425

I don't call my self expert in Android's world, but correct me if I am wrong or ignore my rants about the code.

I am not saying the following is wrong, since the code is used for many other devices, but it looks weird to me,
CompassSensor::enable(int32_t, int en) A function in CompassSensor.cpp called 3 times. This function uses the private data member mEnabled
without being initialized, as it seems from the constructor the line was commented out to set it to false. Further it was used also in readEvents(sensors_event_t* data, int count) function. I noticed, the person who wrote this code before is using
mEnabled and mHasPendingEvent interchangeably, in my opinion. I could be wrong here.

Also I suspect the latest changes from m4xm4n in this file about setDelay
has something to do with this.

// Kernel driver only support specific values
if (ns < 20000000L) {
val = 1;
} else if (ns < 60000000L) {
val = 20;
} else if (ns < 200000000L) {
val = 60;
} else if (ns < 1000000000L) {
val = 200;
} else {
val = 1000;
}

LogCat shows

CompassSensor::~setDelay(1, 200000000) val = 200

I wonder if delay value supposed to be 60 not 200.

Can someone else test this possible fix? It's been mostly working for me since I just restored the old KJ6 driver for compass. I've tested it under AOKP 4.0.4 and it works fine in Google Maps and GPS Test although it's a bit laggy.

fbis251/android_kernel_galaxys4gmtd@78cd493

i am building; will try