OLD | NEW |
(Empty) | |
| 1 <html> |
| 2 <head> |
| 3 <title>DeviceMotion test</title> |
| 4 <script type="text/javascript"> |
| 5 var eventCount = 0; |
| 6 |
| 7 function checkMotionEvent(event) { |
| 8 // Return true iff the motion is close enough to |
| 9 // (1, 2, 3, 4, 5, 6, 7, 8, 9, 10). |
| 10 return Math.abs(event.acceleration.x - 1) < 0.01 && |
| 11 Math.abs(event.acceleration.y - 2) < 0.01 && |
| 12 Math.abs(event.acceleration.z - 3) < 0.01 && |
| 13 Math.abs(event.accelerationIncludingGravity.x - 4) < 0.01 && |
| 14 Math.abs(event.accelerationIncludingGravity.y - 5) < 0.01 && |
| 15 Math.abs(event.accelerationIncludingGravity.z - 6) < 0.01 && |
| 16 Math.abs(event.rotationRate.alpha - 7) < 0.01 && |
| 17 Math.abs(event.rotationRate.beta - 8) < 0.01 && |
| 18 Math.abs(event.rotationRate.gamma - 9) < 0.01 && |
| 19 Math.abs(event.interval - 10) < 0.01; |
| 20 } |
| 21 |
| 22 function onMotion(event) { |
| 23 if (checkMotionEvent(event)) { |
| 24 window.removeEventListener('devicemotion', onMotion); |
| 25 pass(); |
| 26 } else { |
| 27 fail(); |
| 28 } |
| 29 } |
| 30 |
| 31 function pass() { |
| 32 document.getElementById('status').innerHTML = 'PASS'; |
| 33 document.location = '#pass'; |
| 34 } |
| 35 |
| 36 function fail() { |
| 37 document.location = '#fail'; |
| 38 } |
| 39 </script> |
| 40 </head> |
| 41 <body onLoad="window.addEventListener('devicemotion', onMotion)"> |
| 42 <div id="status">FAIL</div> |
| 43 </body> |
| 44 </html> |
OLD | NEW |