Search code examples
androidaccelerometersensors

Android sensor issues when unplug usb


i got a kind of weird issue with my HTC desire.

I currently test some opengl things using the accelerometer and geomagnetic sensors.

it seem that the two of them return sometimes (quite a few) the exact same values .

i got this on my onSensorChanged()

    if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
        gravity = event.values;
    } 
    if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) {
        geomagnetic = event.values;
    }

and i don't know why but when i unplug the usb (to computer) it's gettin worse , (i use thoses values to rotate a camera around an object like sky map, and when i unplug , it's look like the values are correct about 1 one time per 2 seconds ~).

and sometimes (with usb plugged in AND looking at the logcat) it work juste fine and never get the same values from the two sensors.

it's not my device , other program like sky map runs fine , but i don't get what i'm doing wrong. i never mixed up the two arrays gravity and geomagnetic , they juste global and used with SensorManager.getRotationMatrix(R,gravity,geomagnetic).

i'm wondering if i just don't get values too fast , but even if i define SENSOR_DELAY_UI in the listener , it's the same story.


Solution

  • sigh i'm ....

    gravity = event.values; point to it. A simple loop like:

    for (int i=0 ; i<3 ; i++) {
                gravity[i] = event.values[i];
    }
    

    and it's ok (why i always found the solutions after asking somewhere...)