コード例 #1
0
  @Override
  public void onSensorChanged(final SensorEvent se) {
    // se.timestamp returns a time in nanoseconds. Why divide it by 1000? The timestamps ought to be
    // in nanoseconds, not microseconds...
    long timestamp = (long) se.timestamp / 1000;
    this.accuracy = se.accuracy;

    if (se.sensor.getType() != Sensor.TYPE_ACCELEROMETER) {
      if (debug) Log.e(tag, "Sensor not accelerometer: " + se.sensor.getType());
      return;
    }

    // save the last vector
    prev_vector.set(curr_vector);
    if (prev_vector.getTimeStamp() <= 0) prev_vector.setTimeStamp(timestamp);
    prev_ori = curr_ori;

    /**
     * All values are in SI units (m/s^2) values[0]: Acceleration minus Gx on the x-axis values[1]:
     * Acceleration minus Gy on the y-axis values[2]: Acceleration minus Gz on the z-axis
     */
    curr_vector.set(se.values[0], se.values[1], se.values[2]);
    curr_vector.setTimeStamp(timestamp);

    // Orientation between position at timestamp x and timestamp (x-1)
    // Note: The first iteration, prev_vector will be 0;
    curr_ori = curr_vector.orientation(prev_vector);

    vectorList.add(curr_vector.copy());

    // db.addDataItem(this.deID, curr_vector.getTimeStamp(), se.accuracy, curr_vector.getX(),
    // curr_vector.getY(), curr_vector.getZ(), curr_vector.getRSS());

  }