This repository has been archived by the owner on Jun 14, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMotionJS.js
72 lines (59 loc) · 1.46 KB
/
MotionJS.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
var Motion = require("Motion");
var Observable = require("FuseJS/Observable");
var accelerometer = Observable({
acceleration: {x: 0, y: 0, z: 0}
}),
gyroscope = Observable({
rotationRate: {x: 0, y: 0, z: 0}
}),
magnetometer = Observable({
magneticField: {x: 0, y: 0, z: 0}
}),
motion = Observable({
attitude: {yaw: 0, pitch: 0, roll: 0},
rotationRate: {x: 0, y: 0, z: 0},
gravity: {x: 0, y: 0, z: 0},
magneticField: {accuracy: -1, x: 0, y: 0, z: 0},
userAcceleration: {x: 0, y: 0, z: 0}
}),
activity = Observable({
unknown: true,
stationary: false,
walking: false,
running: false,
automotive: false,
cycling: false,
confidence: "low"
});
Motion.on("accelerometerChanged", function(values){
values = JSON.parse(values);
if(!values.error)
accelerometer.value = values;
});
Motion.on("gyroscopeChanged", function(values){
values = JSON.parse(values);
if(!values.error)
gyroscope.value = values;
});
Motion.on("motionChanged", function(values){
values = JSON.parse(values);
if(!values.error)
motion.value = values;
});
Motion.on("magnetometerChanged", function(values){
values = JSON.parse(values);
if(!values.error)
magnetometer.value = values;
});
Motion.on("activityChanged", function(values){
values = JSON.parse(values);
if(!values.error)
activity.value = values;
});
module.exports = {
accelerometer: accelerometer,
gyroscope: gyroscope,
motion: motion,
magnetometer: magnetometer,
activity: activity
};