在15560ae型号的“WIKO Highway Star”上,从加速度计和磁传感器获取数据时遇到问题。
调用SensorManager.getSensorList(),加速度计的最短延迟为10ms,磁性为100ms。
我注册了这两个传感器:
Sensor sensorAccelerometer = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
sensorManager.registerListener(this, sensorAccelerometer, 20000);
Sensor sensorMagneticField = sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
sensorManager.registerListener(this, sensorMagneticField, 20000);
每20000微秒接收传感器数据= 20ms。
但它发生了一些非常奇怪的事情。 当我记录收到的延迟和数据时:
@Override
public void onSensorChanged(SensorEvent event) {
long now = Calendar.getInstance().getTimeInMillis();
if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
Log("acc: time = " + time +
", delay = " + (now - lastSensorAcc) + "ms" +
", values = " + arrayToString(event.values));
lastSensorAcc = now;
}
if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) {
Log("mag: time = " + time +
", delay = " + (now - lastSensorMag) + "ms" +
", values = " + arrayToString(event.values));
lastSensorMag = now;
}
}
我得到了这个输出:
Accelerometer values in log:
acc: time = 21:30:13.556, delay = 84ms, values = -0,41 5,12 8,65
acc: time = 21:30:13.559, delay = 3ms, values = -0,41 5,12 8,65
acc: time = 21:30:13.560, delay = 1ms, values = -0,41 5,12 8,65
acc: time = 21:30:13.561, delay = 1ms, values = -0,41 5,12 8,65
acc: time = 21:30:13.562, delay = 1ms, values = -0,41 5,12 8,65
acc: time = 21:30:13.646, delay = 84ms, values = -0,58 5,05 8,74
acc: time = 21:30:13.649, delay = 3ms, values = -0,58 5,05 8,74
acc: time = 21:30:13.650, delay = 1ms, values = -0,58 5,05 8,74
acc: time = 21:30:13.651, delay = 1ms, values = -0,58 5,05 8,74
acc: time = 21:30:13.652, delay = 1ms, values = -0,58 5,05 8,74
Magnetic field values in log:
mag: time = 21:30:15.845, delay = 100ms, values = 12,60 -37,98 -23,34
mag: time = 21:30:15.846, delay = 1ms, values = 12,60 -37,98 -23,34
mag: time = 21:30:15.944, delay = 99ms, values = 12,00 -37,68 -23,76
mag: time = 21:30:16.045, delay = 100ms, values = 12,00 -37,68 -23,76
mag: time = 21:30:16.047, delay = 3ms, values = 12,00 -37,68 -23,76
mag: time = 21:30:16.145, delay = 97ms, values = 10,92 -37,62 -23,94
mag: time = 21:30:16.147, delay = 2ms, values = 10,92 -37,62 -23,94
mag: time = 21:30:16.246, delay = 100ms, values = 9,84 -37,80 -23,64
mag: time = 21:30:16.248, delay = 2ms, values = 9,84 -37,80 -23,64
mag: time = 21:30:16.345, delay = 96ms, values = 8,34 -38,46 -22,38
如您所见,重复这些值。
新的acc值每80-90毫秒递送一次(我要求每20毫秒!!),重复值之间(为什么,我不需要它们!)。
每100毫秒传递一次新的磁力值(这正是我所期望的),但为什么在1-3毫秒后再次出现相同的值?
我的其他智能手机(Galaxy Alpha,Galaxy SII,Nexus 7,Galaxy A3,Sony Experia XA,Asus Memopad 10)都没有所描述的问题。