Fixed compass gyro at last

master
Keith Irwin 2018-08-30 18:01:11 +00:00
parent 98cba6ad7e
commit 527caa8ae5
No known key found for this signature in database
GPG Key ID: 378933C743E2BBC0
3 changed files with 41 additions and 32 deletions

View File

@ -1,10 +1,12 @@
'use strict';
/* global navigator $ GyroNorm */
'use strict'
/* global navigator $ */
alert('coordinates loaded')
// Set units based on browser locale
const metric = !(window.navigator.language=='en-US'||window.navigator.language=='my');
// Track GPS location
// Track location
if (!navigator.geolocation){ $('#no-gps').show(); }
else { navigator.geolocation.watchPosition(
@ -37,31 +39,3 @@ else { navigator.geolocation.watchPosition(
);
}
// Set compass orientation
var gn = new GyroNorm()
gn.init().then(function(){
gn.start(function(data){
// No orientation data
if (!data.do.absolute) {
$('#rotated').hide();
$('#no-dir').show();
}
// Set orientation
else {
const rot = 'rotate('+data.do.alpha.toString().substring(0,5)+'deg)';
$('#rose').css({
'-ms-transform': rot,
'-webkit-transform': rot,
'transform': rot
})
}
})
})
window.addEventListener("deviceorientation", setRose, true);

34
direction.js Normal file
View File

@ -0,0 +1,34 @@
'use strict'
/* global $ GyroNorm */
alert('direction loaded')
// Set compass orientation
var gn = new GyroNorm()
gn.init().then(function(){
gn.start(function(data){
console.log(data.do.alpha)
// No orientation data
// if (!data.do.absolute) {
// $('#rotated').hide()
// $('#no-dir').show()
// }
// Set orientation
// else {
const rot = 'rotate('+data.do.alpha.toString().substring(0,5)+'deg)'
$('#rose').css({
'-ms-transform': rot,
'-webkit-transform': rot,
'transform': rot
})
// }
})
})
//window.addEventListener("deviceorientation", setRose, true)

View File

@ -71,7 +71,8 @@
<script src="gyronorm.complete.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="script.js"></script>
<script src="coordinates.js"></script>
<script src="direction.js"></script>
</body>