0
嘿,夥計們我目前正在研究一個項目,該項目將訪問加速度計,並繪製出我的代碼目前無法工作,但我不確定推理的結果,任何幫助都會很大讚賞。Android加速計輸出零(零)值
該程序需要記錄數據30秒,然後輸出一個圖表,如何不斷輸出所有3軸的0值。
驗證碼:
public class AccelerometerData extends Activity implements SensorEventListener {
public float _x;
public float _y;
public float _z;
boolean senseA = false;
int Time = 30;
int samplerate=10;
int sampleSize=(Time*1000)/samplerate;
public double[] X = new double[sampleSize];
public double[] Y = new double[sampleSize];
public double[] Z = new double[sampleSize];
Sensor accelerometer;
SensorManager sm;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
sm=(SensorManager)getSystemService(SENSOR_SERVICE);
accelerometer=sm.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
sm.registerListener(this, accelerometer, SensorManager.SENSOR_DELAY_FASTEST);
final Timer updateTimer = new Timer();
updateTimer.scheduleAtFixedRate(new TimerTask(){
public void run(){
if (senseA= true){
for (int i = 0; i < sampleSize; i++){
X[i] = _x;
Y[i] = _y;
Z[i] = _z;
}
}
}
}, 0, samplerate);
}
public void onAccuracyChanged(Sensor sensor, int accuracy) {
// TODO Auto-generated method stub
}
public void onSensorChanged(SensorEvent event) {
// TODO Auto-generated method stub
if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER){
_x = event.values[0];
_y = event.values[1];
_z = event.values[2];
senseA = true;
}
}
}
的輸出值如下:
AccelerometerData data= new AccelerometerData();
double[] dataX = data.X;
double[] dataY = data.Y;
double[] dataZ = data.Z;
int length = data.sampleSize;
謝謝你的時間提前
得到它工作的感謝!花了我一段時間才明白你的意思 – user1686491