如何在加速度计的TextView 3轴上显示

时间:2014-08-13 10:55:21

标签: java android

我想在三个TextView中打印accelerometer的每个轴(scaledX,scaledY,scaledZ)的三个值。

有人能帮助我吗? 感谢。

CODE:

MainActivity.java。

public class MainActivity extends Activity implements BluetoothAdapter.LeScanCallback {

    private TextView  mAccelerometerx, mAccelerometery, mAccelerometerz;
        mAccelerometerx =(TextView) findViewById(R.id.ejex);
        mAccelerometery =(TextView) findViewById(R.id.ejey);
        mAccelerometerz =(TextView) findViewById(R.id.ejez);

 private void updateAccelerometerValue(BluetoothGattCharacteristic characteristic ){

        double accelerometerx = SensorTagData.extractAccelerometer(characteristic, mAccelerometerx);
        double accelerometery = SensorTagData.extractAccelerometer(characteristic, mAccelerometery);
        double accelerometerz = SensorTagData.extractAccelerometer(characteristic, mAccelerometerz);

        mAccelerometerx.setText(String.format("%.4f", accelerometerx));
        mAccelerometery.setText(String.format("%.4f", accelerometery));
        mAccelerometerz.setText(String.format("%.4f", accelerometerz));
    }

}

SensorData.java

public class SensorData {

  public static double [] extractAccelerometer(BluetoothGattCharacteristic c) {

        Integer x = c.getIntValue(FORMAT_SINT8, 0);
        Integer y = c.getIntValue(FORMAT_SINT8, 1);
        Integer z = c.getIntValue(FORMAT_SINT8, 2) * -1;

        double scaledX = x / 64.0;
        double scaledY = y / 64.0;
        double scaledZ = z / 64.0;

        return new double[] {scaledX, scaledY, scaledZ};
    }
 }   

1 个答案:

答案 0 :(得分:0)

private void updateAccelerometerValue(BluetoothGattCharacteristic characteristic){

    double accelerometerx = SensorTagData.extractAccelerometer(characteristic, mAccelerometerx);
    double accelerometery = SensorTagData.extractAccelerometer(characteristic, mAccelerometery);
    double accelerometerz = SensorTagData.extractAccelerometer(characteristic, mAccelerometerz);

    mAccelerometerx.setText(String.format("%.4f", accelerometerx));  //ERROR HERE
    mAccelerometery.setText(String.format("%.4f", accelerometery));  //ERROR HERE
    mAccelerometerz.setText(String.format("%.4f", accelerometerz));  //ERROR HERE
}

错误类型 SensorTagData类型中的extractAccelerometer(BluetoothGattCharacteristic)方法不适用于参数(BluetoothGattCharacteristic,TextView)

我知道我提供了两个以上的参数,但如果我删除" accelerometerx","加速计" ," accelerometerz"错误消失但我想不会看到任何东西。