var mount = {}; var tracking = false; function mount_slew(direction, state) { const rate = document.getElementById("slew_rate").value; const xhttp = new XMLHttpRequest(); xhttp.onload = function() { } xhttp.open("GET", "/mount_slew?direction=" + direction + "&rate=" + rate + "&state=" + state, true); xhttp.send(); } function mount_park() { const xhttp = new XMLHttpRequest(); xhttp.onload = function() { } xhttp.open("GET", "/mount_park", true); xhttp.send(); } function mount_unpark() { const xhttp = new XMLHttpRequest(); xhttp.onload = function() { } xhttp.open("GET", "/mount_unpark", true); xhttp.send(); } function mount_connect() { const xhttp = new XMLHttpRequest(); xhttp.onload = function() { } xhttp.open("GET", "/mount_connect", true); xhttp.send(); } function mount_disconnect() { const xhttp = new XMLHttpRequest(); xhttp.onload = function() { } xhttp.open("GET", "/mount_disconnect", true); xhttp.send(); } function mount_set_pier_side(pier_side) { const xhttp = new XMLHttpRequest(); xhttp.onload = function() { } xhttp.open("GET", "/mount_pier_side?pier_side=" + pier_side , true); xhttp.send(); } function mount_get_messages() { const xhttp = new XMLHttpRequest(); xhttp.onload = function() { control = document.getElementById("mount_messages"); if (this.responseText != "{}") { message = JSON.parse(this.responseText); text = String(message.message); if (text.length > 160) { text = text.slice(0, 160) + "..."; } control.innerHTML = "

" + text + "

" } } xhttp.open("GET", "/mount_messages", true); xhttp.send(); } function mount_get_current_ra_dec() { const xhttp = new XMLHttpRequest(); xhttp.onload = function() { mount_ra = document.getElementById("mount_ra"); mount_dec = document.getElementById("mount_dec"); mount_alt = document.getElementById("mount_alt"); mount_az = document.getElementById("mount_az"); var nf2 = Intl.NumberFormat('en-IN', { minimumIntegerDigits: 2, minimumFractionDigits: 4, maximumFractionDigits: 4 }); var nf3 = Intl.NumberFormat('en-IN', { minimumIntegerDigits: 3, minimumFractionDigits: 3, maximumFractionDigits: 3 }); if (this.responseText != "{}") { vector = JSON.parse(this.responseText) const now = new Date; const observer = new Astronomy.Observer(local_observer.latitude, local_observer.longitude, local_observer.altitude); var alt = 0; var az = 0; if (typeof vector.members.RA !== "undefined" && typeof vector.members.DEC !== "undefined") { const hor = Astronomy.Horizon(now, observer, parseFloat(vector.members.RA.value), parseFloat(vector.members.DEC.value), 'normal'); alt = hor.altitude; az = hor.azimuth; } mount.online = vector.online; if(vector.online == true) { mount_ra.innerHTML = "

RA: " + nf2.format(vector.members.RA.value) + "

" mount_dec.innerHTML = "

DEC: " + nf3.format(vector.members.DEC.value) + "

" mount_alt.innerHTML = "

ALT: " + nf2.format(alt) + "

" mount_az.innerHTML = "

AZ: " + nf3.format(az) + "

" mount.ra = vector.members.RA.value; mount.dec = vector.members.DEC.value; mount.alt = alt; mount.az = az; } else { mount_ra.innerHTML = "

RA: --.----

" mount_dec.innerHTML = "

DEC: ---.---

" mount_alt.innerHTML = "

ALT: --.----

" mount_az.innerHTML = "

AZ: ---.---

" mount.ra = 0; mount.dec = 0; mount.alt = 0; mount.az = 0; } } } xhttp.open("GET", "/current_ra_dec", true); xhttp.send(); } function mount_set_track_mode(body) { if (body.dataset.body_name == "Moon") { mode = "LUNAR"; } else if (body.dataset.body_name == "Sun") { mode = "SOLAR"; } else { mode = "SIDEREAL"; } const xhttp = new XMLHttpRequest(); xhttp.onload = function() { } xhttp.open("GET", "/track_mode?track_mode=" + mode, true); xhttp.send(); } function mount_goto_body(body) { mount_set_track_mode(body); window.setTimeout("", 100); const xhttp = new XMLHttpRequest(); xhttp.onload = function() { } xhttp.open("GET", "/goto_ra_dec?ra=" + body.dataset.ra + "&dec=" + body.dataset.dec, true); xhttp.send(); } function mount_random_goto(e) { const width = sky_view.offsetWidth; const height = sky_view.offsetHeight; var alt = -(e.offsetY / height * 180 - 90); if (alt == 90){ alt = 0; } if (az == 0){ az = 180; } var az = e.offsetX / width * 360; const now = new Date; const observer = new Astronomy.Observer(local_observer.latitude, local_observer.longitude, local_observer.altitude); var mercury = Astronomy.Equator("Mercury", now, observer, true, true); var matrix = Astronomy.Rotation_HOR_EQD(now, observer); var spherical = {lat:alt, lon:az, dist:mercury.dist}; var in_vector = Astronomy.VectorFromHorizon(spherical, now, "normal"); var out_vector = Astronomy.RotateVector(matrix, in_vector); var equator = Astronomy.EquatorFromVector(out_vector); const xhttp = new XMLHttpRequest(); xhttp.onload = function() { } xhttp.open("GET", "/goto_ra_dec?ra=" + equator.ra + "&dec=" + equator.dec, true); xhttp.send(); } function mount_get_pier_side() { const xhttp = new XMLHttpRequest(); xhttp.onload = function() { document.getElementById("mount_pier_side").innerHTML = "PIER_SIDE: " + this.responseText; } xhttp.open("GET", "/pier_side", true); xhttp.send(); }