Added check for sensor data accuracy to ignore data when sensor accuracy is unreliable.

Fixed error in log entry when sensor accuracy changes
Added log entry on calibration of axis

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9789 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
iwg..ic 12 years ago
parent 77a1ec09f8
commit 3afb803c68
  1. 17
      engine/src/android/com/jme3/input/android/AndroidSensorJoyInput.java

@ -121,6 +121,7 @@ public class AndroidSensorJoyInput implements JoyInput, SensorEventListener {
int androidSensorType = -1;
int androidSensorSpeed = SensorManager.SENSOR_DELAY_GAME;
Sensor sensor = null;
int sensorAccuracy = 0;
float[] lastValues;
final Object valuesLock = new Object();
ArrayList<AndroidJoystickAxis> axes = new ArrayList<AndroidJoystickAxis>();
@ -360,6 +361,10 @@ public class AndroidSensorJoyInput implements JoyInput, SensorEventListener {
return false;
}
if (sensorData.sensorAccuracy == SensorManager.SENSOR_STATUS_UNRELIABLE) {
return false;
}
synchronized(sensorData.valuesLock) {
accValues[0] = sensorData.lastValues[0];
accValues[1] = sensorData.lastValues[1];
@ -371,6 +376,10 @@ public class AndroidSensorJoyInput implements JoyInput, SensorEventListener {
return false;
}
if (sensorData.sensorAccuracy == SensorManager.SENSOR_STATUS_UNRELIABLE) {
return false;
}
synchronized(sensorData.valuesLock) {
magValues[0] = sensorData.lastValues[0];
magValues[1] = sensorData.lastValues[1];
@ -619,6 +628,9 @@ public class AndroidSensorJoyInput implements JoyInput, SensorEventListener {
SensorData sensorData = sensors.get(sensorType);
if (sensorData != null && sensorData.sensor.equals(se.sensor) && sensorData.enabled) {
if (sensorData.sensorAccuracy == SensorManager.SENSOR_STATUS_UNRELIABLE) {
return;
}
synchronized(sensorData.valuesLock) {
for (int i=0; i<sensorData.lastValues.length; i++) {
sensorData.lastValues[i] = se.values[i];
@ -656,9 +668,10 @@ public class AndroidSensorJoyInput implements JoyInput, SensorEventListener {
SensorData sensorData = sensors.get(sensorType);
if (sensorData != null) {
logger.log(Level.INFO, "onAccuracyChanged for {0}: accuracy: {1}",
new Object[]{sensor.toString(), i});
new Object[]{sensor.getName(), i});
logger.log(Level.INFO, "MaxRange: {0}, Resolution: {1}",
new Object[]{sensor.getMaximumRange(), sensor.getResolution()});
sensorData.sensorAccuracy = i;
}
}
@ -781,6 +794,8 @@ public class AndroidSensorJoyInput implements JoyInput, SensorEventListener {
public void calibrateCenter() {
zeroRawValue = lastRawValue;
logger.log(Level.INFO, "Calibrating axis {0} to {1}",
new Object[]{getName(), zeroRawValue});
}
}

Loading…
Cancel
Save