Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CSE340 Sensing and Location
Manage
Activity
Members
Labels
Plan
Issues
1
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cse340
exercises
CSE340 Sensing and Location
Commits
82a9c07c
Commit
82a9c07c
authored
1 year ago
by
Henry Heino
Browse files
Options
Downloads
Patches
Plain Diff
Adjust for unit mismatch: event.timestamp is in nanoseconds, not milliseconds
parent
54b1bb01
Branches
master
No related tags found
1 merge request
!3
Adjust for unit mismatch: event.timestamp is in nanoseconds, not milliseconds
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
app/src/main/java/cse340/sensing/SensorActivity.java
+14
-5
14 additions, 5 deletions
app/src/main/java/cse340/sensing/SensorActivity.java
with
14 additions
and
5 deletions
app/src/main/java/cse340/sensing/SensorActivity.java
+
14
−
5
View file @
82a9c07c
...
...
@@ -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
.
currentTimeMilli
s
();
mLastUpdate
=
System
Clock
.
elapsedRealtimeNano
s
();
}
/**
...
...
@@ -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
];
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment