Hi all. I wanted to get to grips with the orientation sensors (using
HTC Hero) and have written a simple Spirit Level app which has two
bars displayed, one showing the horizontal level, and the other
showing the vertical. Just like a real spirit level :-)
I've played around with the Sensor and SensorManager classes, but they
just don't seem to work quite correctly. There are two issues:
1) I would expect the tilt reading to give Zero when it is level - a
tip either way gives a positive or negative reading. But I can see
from looking at my device that zero clearly isn't level - it's just
off. About 5 is actually level!
2) For the vertical reading from the same sensor, the sensor readings
seem to get stuck. They get as far as about 75 degrees, as you get
near vertical, but then the readings seem to stick and eventually jump
to somewhere over 100. You can imagine, my app needs a smooth
transition of readings, and this is useless.
So either the sensor doesn't work, or I'm missing something. The
latter is the more likely! What could be going wrong? Here's some of
the code:
mSensorManager = (SensorManager) this.getSystemService
(Context.SENSOR_SERVICE);
sensors = mSensorManager.getSensorList(Sensor.TYPE_ORIENTATION);
Sensor dirSensor = sensors.get(0);
mSensorManager.registerListener(mySensorListener, dirSensor,
SensorManager.SENSOR_DELAY_NORMAL);
public void onSensorChanged(SensorEvent event) {
// event.values[1] gives me my tilt reading
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---