| OLD | NEW |
| (Empty) |
| 1 <!DOCTYPE html> | |
| 2 <html> | |
| 3 <head> | |
| 4 <title>Device Motion/Orientation diagnostic measurements</title> | |
| 5 </head> | |
| 6 <body> | |
| 7 <table> | |
| 8 <tr> | |
| 9 <td colspan="2"> | |
| 10 <hr> | |
| 11 </td> | |
| 12 </tr> | |
| 13 <tr> | |
| 14 <td>Motion Supported</td> | |
| 15 <td width="250px" id="motionSupported"></td> | |
| 16 </tr> | |
| 17 <tr> | |
| 18 <td>motion acceleration (x, y, z)</td> | |
| 19 <td id="motionAccel"></td> | |
| 20 </tr> | |
| 21 <tr> | |
| 22 <td>motion acceleration incl. gravity (x, y, z)</td> | |
| 23 <td id="motionAccelG"></td> | |
| 24 </tr> | |
| 25 <tr> | |
| 26 <td>motion rotation rate (α, β, γ)</td> | |
| 27 <td id="motionRotation"></td> | |
| 28 </tr> | |
| 29 <tr> | |
| 30 <td>real-time motion frequency (Hz)</td> | |
| 31 <td id="motionFreq"></td> | |
| 32 </tr> | |
| 33 <tr> | |
| 34 <td>motion max frequency (Hz)</td> | |
| 35 <td id="motionMaxFreq"></td> | |
| 36 </tr> | |
| 37 <tr> | |
| 38 <td>motion stated interval</td> | |
| 39 <td id="motionInterval"></td> | |
| 40 </tr> | |
| 41 <tr> | |
| 42 <td colspan="2"> | |
| 43 <hr> | |
| 44 </td> | |
| 45 </tr> | |
| 46 <tr> | |
| 47 <td>Orientation Supported</td> | |
| 48 <td id="orientationSupported"></td> | |
| 49 </tr> | |
| 50 <tr> | |
| 51 <td>orientation values (α, β, γ)</td> | |
| 52 <td id="orientationValues"></td> | |
| 53 </tr> | |
| 54 <tr> | |
| 55 <td>orientation absolute</td> | |
| 56 <td id="orientationAbsolute"></td> | |
| 57 </tr> | |
| 58 <tr> | |
| 59 <td>orientation frequency (Hz)</td> | |
| 60 <td id="orientationFreq"></td> | |
| 61 </tr> | |
| 62 <tr> | |
| 63 <td>orientation max frequency (Hz)</td> | |
| 64 <td id="orientationMaxFreq"></td> | |
| 65 </tr> | |
| 66 </table> | |
| 67 | |
| 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; | |
| 74 | |
| 75 function onMotion(event) { | |
| 76 document.getElementById('motionAccel').innerHTML = | |
| 77 roundToFixedArray([event.acceleration.x, | |
| 78 event.acceleration.y, | |
| 79 event.acceleration.z]); | |
| 80 | |
| 81 document.getElementById("motionAccelG").innerHTML = | |
| 82 roundToFixedArray([event.accelerationIncludingGravity.x, | |
| 83 event.accelerationIncludingGravity.y, | |
| 84 event.accelerationIncludingGravity.z]); | |
| 85 | |
| 86 document.getElementById("motionRotation").innerHTML = | |
| 87 roundToFixedArray([event.rotationRate.alpha, | |
| 88 event.rotationRate.beta, | |
| 89 event.rotationRate.gamma]); | |
| 90 | |
| 91 document.getElementById("motionInterval").innerHTML = event.interval; | |
| 92 ++numberMotionEvents; | |
| 93 } | |
| 94 | |
| 95 function roundToFixed(value) { | |
| 96 return value==null ? value : value.toFixed(4); | |
| 97 } | |
| 98 | |
| 99 function roundToFixedArray(values) { | |
| 100 return '[' + values.map(function(value) { | |
| 101 return roundToFixed(value); | |
| 102 }).join(',') + ']'; | |
| 103 } | |
| 104 | |
| 105 function onOrientation(event) { | |
| 106 document.getElementById("orientationValues").innerHTML = | |
| 107 roundToFixedArray([event.alpha, event.beta, event.gamma]); | |
| 108 document.getElementById("orientationAbsolute").innerHTML = event.absolut
e; | |
| 109 ++numberOrientationEvents; | |
| 110 } | |
| 111 | |
| 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); | |
| 117 | |
| 118 document.getElementById("motionFreq").innerHTML = motionFreq; | |
| 119 document.getElementById("motionMaxFreq").innerHTML = motionMaxFreq; | |
| 120 document.getElementById("orientationFreq").innerHTML = orientationFreq; | |
| 121 document.getElementById("orientationMaxFreq").innerHTML = orientationMax
Freq; | |
| 122 | |
| 123 numberMotionEvents = 0; | |
| 124 numberOrientationEvents = 0; | |
| 125 } | |
| 126 | |
| 127 var motionSupported="not supported"; | |
| 128 var orientationSupported="not supported"; | |
| 129 | |
| 130 if (window.DeviceMotionEvent) { | |
| 131 window.addEventListener('devicemotion', onMotion) | |
| 132 motionSupported="supported"; | |
| 133 } | |
| 134 document.getElementById("motionSupported").innerHTML = motionSupported; | |
| 135 | |
| 136 if (window.DeviceOrientationEvent) { | |
| 137 window.addEventListener('deviceorientation', onOrientation); | |
| 138 orientationSupported = "supported"; | |
| 139 } | |
| 140 document.getElementById("orientationSupported").innerHTML = orientationSup
ported; | |
| 141 | |
| 142 setInterval(function(){updateMeasurements()}, updateIntervalDelaySec*1000)
; | |
| 143 | |
| 144 </script> | |
| 145 | |
| 146 </body> | |
| 147 </html> | |
| OLD | NEW |