4 <title>Device Motion/Orientation diagnostic measurements
</title>
14 <td>Motion Supported
</td>
15 <td width=
"250px" id=
"motionSupported"></td>
18 <td>motion acceleration (x, y, z)
</td>
19 <td id=
"motionAccel"></td>
22 <td>motion acceleration incl. gravity (x, y, z)
</td>
23 <td id=
"motionAccelG"></td>
26 <td>motion rotation rate (
α,
β,
γ)
</td>
27 <td id=
"motionRotation"></td>
30 <td>real-time motion frequency (Hz)
</td>
31 <td id=
"motionFreq"></td>
34 <td>motion max frequency (Hz)
</td>
35 <td id=
"motionMaxFreq"></td>
38 <td>motion stated interval
</td>
39 <td id=
"motionInterval"></td>
47 <td>Orientation Supported
</td>
48 <td id=
"orientationSupported"></td>
51 <td>orientation values (
α,
β,
γ)
</td>
52 <td id=
"orientationValues"></td>
55 <td>orientation absolute
</td>
56 <td id=
"orientationAbsolute"></td>
59 <td>orientation frequency (Hz)
</td>
60 <td id=
"orientationFreq"></td>
63 <td>orientation max frequency (Hz)
</td>
64 <td id=
"orientationMaxFreq"></td>
68 <script type=
"text/javascript">
69 var numberMotionEvents
= 0;
70 var numberOrientationEvents
= 0;
71 var motionMaxFreq
= 0;
72 var orientationMaxFreq
= 0;
73 var updateIntervalDelaySec
= 2;
75 function onMotion(event
) {
76 document
.getElementById('motionAccel').innerHTML
=
77 roundToFixedArray([event
.acceleration
.x
,
79 event
.acceleration
.z
]);
81 document
.getElementById("motionAccelG").innerHTML
=
82 roundToFixedArray([event
.accelerationIncludingGravity
.x
,
83 event
.accelerationIncludingGravity
.y
,
84 event
.accelerationIncludingGravity
.z
]);
86 document
.getElementById("motionRotation").innerHTML
=
87 roundToFixedArray([event
.rotationRate
.alpha
,
88 event
.rotationRate
.beta
,
89 event
.rotationRate
.gamma
]);
91 document
.getElementById("motionInterval").innerHTML
= event
.interval
;
95 function roundToFixed(value
) {
96 return value
==null ? value
: value
.toFixed(4);
99 function roundToFixedArray(values
) {
100 return '[' + values
.map(function(value
) {
101 return roundToFixed(value
);
105 function onOrientation(event
) {
106 document
.getElementById("orientationValues").innerHTML
=
107 roundToFixedArray([event
.alpha
, event
.beta
, event
.gamma
]);
108 document
.getElementById("orientationAbsolute").innerHTML
= event
.absolute
;
109 ++numberOrientationEvents
;
112 function updateMeasurements() {
113 var motionFreq
= numberMotionEvents
/updateIntervalDelaySec
;
114 var orientationFreq
= numberOrientationEvents
/updateIntervalDelaySec
;
115 motionMaxFreq
= Math
.max(motionMaxFreq
, motionFreq
);
116 orientationMaxFreq
= Math
.max(orientationMaxFreq
, orientationFreq
);
118 document
.getElementById("motionFreq").innerHTML
= motionFreq
;
119 document
.getElementById("motionMaxFreq").innerHTML
= motionMaxFreq
;
120 document
.getElementById("orientationFreq").innerHTML
= orientationFreq
;
121 document
.getElementById("orientationMaxFreq").innerHTML
= orientationMaxFreq
;
123 numberMotionEvents
= 0;
124 numberOrientationEvents
= 0;
127 var motionSupported
="not supported";
128 var orientationSupported
="not supported";
130 if (window
.DeviceMotionEvent
) {
131 window
.addEventListener('devicemotion', onMotion
)
132 motionSupported
="supported";
134 document
.getElementById("motionSupported").innerHTML
= motionSupported
;
136 if (window
.DeviceOrientationEvent
) {
137 window
.addEventListener('deviceorientation', onOrientation
);
138 orientationSupported
= "supported";
140 document
.getElementById("orientationSupported").innerHTML
= orientationSupported
;
142 setInterval(function(){updateMeasurements()}, updateIntervalDelaySec
*1000);