Skip to content

Commit

Permalink
Update Test_Sighting.html Rev D
Browse files Browse the repository at this point in the history
  • Loading branch information
pdr0663 authored Sep 4, 2024
1 parent 1861646 commit eaed8d9
Showing 1 changed file with 13 additions and 26 deletions.
39 changes: 13 additions & 26 deletions Test_Sighting.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,58 +25,45 @@
</head>
<body>
<h1>Compass Bearing</h1>
<p id="instruction">Press the button to request permission and capture the bearing.<br>Rev C</p>
<p id="instruction">Press the button to request permission and capture the bearing.<br>Rev D</p>
<input type="text" id="bearing" readonly placeholder="Bearing will appear here">
<button id="permissionButton">Request Permission & Capture Bearing</button>
<button id="captureButton" style="display: none;">Capture Bearing</button>

<script>
let currentBearing = null;
let true_bearing = null;
let magnetic_bearing = null;
let magnetic_declination = 12.84;

function fixBearing(bearing) {
if (bearing < 0) {
return bearing + 360;
} else if (bearing >= 360) {
return bearing - 360;
}
}
// Function to update the bearing
function updateBearing(event) {
let alpha = event.alpha;
true_bearing = Math.round(event.alpha);
magnetic_bearing = Math.round(event.webkitCompassHeading);
/*
// Adjust for different screen orientations
if (window.orientation === 0) { // Portrait
alpha -= 90;
} else if (window.orientation === -90) { // Landscape right
alpha -= 180;
} else if (window.orientation === -90) { // Landscape left
// alpha += 0;
} else if (window.orientation === 180) { // Portrait upside-down
// Chrome doesn't seem to allow this orientation
// alpha += 180;
}
// Invert the alpha to correct the direction
alpha = 360 - alpha;
// Add declination for Sydney to yield true bearing
alpha += 13
magnetic_bearing = event.webkitCompassHeading;
true_bearing = fixBearing(magnetic_bearing + magnetic_declination);
// Normalize the alpha value to be between 0 and 360
if (alpha < 0) {
alpha += 360;
} else if (alpha >= 360) {
alpha -= 360;
}
*/
currentBearing = Math.round(alpha);
}

// Function to capture the bearing when the button is pressed
function captureBearing() {
if (currentBearing !== null) {
if (magnetic_bearing !== null) {
// document.getElementById('bearing').value = currentBearing + "°";
console.log(true_bearing);
console.log(magnetic_bearing);
console.log();
document.getElementById('bearing').value = "M" + magnetic_bearing + " T" + true_bearing;
document.getElementById('bearing').value = "M" + Math.round(magnetic_bearing) + "° T" + Math.round(true_bearing) + "°";
} else {
document.getElementById('bearing').value = "No compass data available";
}
Expand Down

0 comments on commit eaed8d9

Please sign in to comment.