Skip to content
Snippets Groups Projects
Commit 82a9c07c authored by Henry Heino's avatar Henry Heino
Browse files

Adjust for unit mismatch: event.timestamp is in nanoseconds, not milliseconds

parent 54b1bb01
Branches master
No related tags found
1 merge request!3Adjust for unit mismatch: event.timestamp is in nanoseconds, not milliseconds
......@@ -11,6 +11,7 @@ import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.os.SystemClock;
import android.view.LayoutInflater;
import android.view.Menu;
import android.widget.TableLayout;
......@@ -38,6 +39,9 @@ public class SensorActivity extends AbstractMainActivity implements SensorEventL
*/
private static final int DELAY = SensorManager.SENSOR_DELAY_UI;
/** Minimum update time for _some_ of the sensors below, in nanoseconds. */
private static final long MIN_UPDATE_DELAY = 200 * 1000 * 1000;
/**
* Constants for creating the IDs for the table rows, and children in the row
*/
......@@ -52,6 +56,9 @@ public class SensorActivity extends AbstractMainActivity implements SensorEventL
/**
* The last time the screen was updated - this is so we can actually see the values
* This is in nanoseconds since the time the device was booted.
*
* @see SystemClock#elapsedRealtimeNanos()
*/
private long mLastUpdate;
......@@ -82,7 +89,7 @@ public class SensorActivity extends AbstractMainActivity implements SensorEventL
}
// Start the clock
mLastUpdate = System.currentTimeMillis();
mLastUpdate = SystemClock.elapsedRealtimeNanos();
}
/**
......@@ -280,9 +287,13 @@ public class SensorActivity extends AbstractMainActivity implements SensorEventL
double accelerationSquareRoot = Math.sqrt(x * x + y * y + z * z);
String output = "";
if (actualTime - mLastUpdate >= 200) {
if (actualTime - mLastUpdate >= MIN_UPDATE_DELAY) {
if (accelerationSquareRoot >= 1) {
mLastUpdate = actualTime;
// Note: We _really_ should be using strings.xml here. This makes it possible to
// translate them!
// OPTIONAL TODO: Move these to strings.xml!
output = String.format(Locale.ENGLISH, "Move: %.4f",
accelerationSquareRoot);
} else {
......@@ -306,11 +317,9 @@ public class SensorActivity extends AbstractMainActivity implements SensorEventL
long actualTime = event.timestamp;
String output = "";
if (actualTime - mLastUpdate >= 200) {
if (actualTime - mLastUpdate >= MIN_UPDATE_DELAY) {
mLastUpdate = actualTime;
float[] values = event.values;
// Axis of the rotation sample, not normalized.
float axisX = event.values[0];
float axisY = event.values[1];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment