X-Git-Url: https://git-public.kairo.at/?p=tricorder.git;a=blobdiff_plain;f=js%2Ftricorder.js;h=28852a02b72c504475529d29f8bf298ec1e79ca2;hp=707910a9ba0d9f7e6fd8633bfbccfea70709e83f;hb=d9387df27c6cba7af91f17c52661254b2710acd7;hpb=d3e5ba11e304b4a5f3ed3c0625c2dc6cc2a4073b;ds=sidebyside diff --git a/js/tricorder.js b/js/tricorder.js index 707910a..28852a0 100644 --- a/js/tricorder.js +++ b/js/tricorder.js @@ -14,6 +14,17 @@ window.onload = function() { gSounds.keyaction = new Audio("sound/key-action.opus"); gSounds.keypress = new Audio("sound/key-press.opus"); + document.getElementById("fullScreenButton").addEventListener("click", + function(aEvent) { toggleFullscreen(); }, false); + + var navItems = document.getElementById("navlist").children; + for (var i = 0; i <= navItems.length - 1; i++) { + navItems[i].addEventListener("click", + function(aEvent) { + switchModule(aEvent.target.id.replace("nav", "")); + }, false); + } + gSounds.launch.play(); window.addEventListener("beforeunload", function( event ) { gSounds.shutdown.play(); @@ -26,8 +37,10 @@ function updateStardate() { var curDate = new Date(); + // Star Trek famously premiered on Thursday, September 8, 1966, at 8:30 p.m. + // See http://www.startrek.com/article/what-if-the-original-star-trek-had-debuted-on-friday-nights if (!gSDBase) - gSDBase = new Date("September 8, 1966 20:00:00 EST"); + gSDBase = new Date("September 8, 1966 20:30:00 EST"); var sdateval = (curDate - gSDBase) / (86400 * 365.2425); gStardate.textContent = sdateval.toFixed(1); @@ -60,7 +73,7 @@ function toggleFullscreen() { } } -function switchModule(modname) { +function switchModule(aModname) { gSounds.keyaction.play(); var sections = document.getElementsByTagName('section'); for (var i = 0; i <= sections.length - 1; i++) { @@ -74,10 +87,13 @@ function switchModule(modname) { navs[i].classList.remove("active"); } - document.getElementById("nav" + modname).classList.add("active"); - document.getElementById("sect" + modname).classList.add("active"); + var navItem = document.getElementById("nav" + aModname); + navItem.classList.add("active"); + document.getElementById("sect" + aModname).classList.add("active"); + document.getElementById("mainHeader").textContent = + (aModname == "Other") ? "Web Tricorder" : navItem.textContent; - window["gMod" + modname].activate(); + window["gMod" + aModname].activate(); } var gModPos = { @@ -88,13 +104,20 @@ var gModPos = { document.getElementById("posavail").style.display = "block"; this.watchID = navigator.geolocation.watchPosition( function(position) { - document.getElementById("posLat").textContent = position.coords.latitude; - document.getElementById("posLong").textContent = position.coords.longitude; - document.getElementById("posAlt").textContent = position.coords.altitude; - document.getElementById("posAcc").textContent = position.coords.accuracy; - document.getElementById("posAltAcc").textContent = position.coords.altitudeAccuracy; - document.getElementById("posHead").textContent = position.coords.heading || "---"; - document.getElementById("posSpd").textContent = position.coords.speed || "---"; + document.getElementById("posLat").textContent = + position.coords.latitude + "°"; + document.getElementById("posLong").textContent = + position.coords.longitude + "°"; + document.getElementById("posAlt").textContent = + position.coords.altitude.toFixed(0) + " m"; + document.getElementById("posAcc").textContent = + position.coords.accuracy.toFixed(0) + " m"; + document.getElementById("posAltAcc").textContent = + position.coords.altitudeAccuracy.toFixed(0) + " m"; + document.getElementById("posHead").textContent = + position.coords.heading ? position.coords.heading.toFixed(0) + "°" : "---"; + document.getElementById("posSpd").textContent = + position.coords.speed ? position.coords.speed.toFixed(1) + " m/s" : "---"; var locTime = new Date(position.timestamp); document.getElementById("posTime").textContent = locTime.toISOString(); }, @@ -109,13 +132,15 @@ var gModPos = { document.getElementById("posHead").textContent = "..."; document.getElementById("posSpd").textContent = "..."; document.getElementById("posTime").textContent = "..."; + setTimeout(function() { gModPos.deactivate(); }, 5000); } else { document.getElementById("posunavail").style.display = "block"; document.getElementById("posavail").style.display = "none"; } + gSounds.scan.pause(); }, - {enableHighAccuracy: true} + {enableHighAccuracy: true, maximumAge: 10000, timeout: 60000} ); } else { @@ -166,6 +191,7 @@ var gModGrav = { document.getElementById("gravAlpha").textContent = "..."; document.getElementById("gravBeta").textContent = "..."; document.getElementById("gravGamma").textContent = "..."; + document.getElementById("gravTotal").textContent = "..."; document.getElementById("gravX").textContent = "..."; document.getElementById("gravY").textContent = "..."; document.getElementById("gravZ").textContent = "..."; @@ -178,6 +204,11 @@ var gModGrav = { document.getElementById("gravGamma").textContent = orientData.gamma.toFixed(1) + "°"; }, motionEvent: function(event) { + var gravTotal = + Math.sqrt(Math.pow(event.accelerationIncludingGravity.x, 2) + + Math.pow(event.accelerationIncludingGravity.y, 2) + + Math.pow(event.accelerationIncludingGravity.z, 2)); + document.getElementById("gravTotal").textContent = gravTotal.toFixed(2) + " m/s²"; document.getElementById("gravX").textContent = event.accelerationIncludingGravity.x.toFixed(2) + " m/s²"; document.getElementById("gravY").textContent = event.accelerationIncludingGravity.y.toFixed(2) + " m/s²"; document.getElementById("gravZ").textContent = event.accelerationIncludingGravity.z.toFixed(2) + " m/s²"; @@ -185,6 +216,54 @@ var gModGrav = { }, } + +var gModDev = { + activate: function() { + gSounds.scan.play(); + this.batteryTimer = + setInterval(function () { gModDev.updateBattery(); }, 100); + }, + deactivate: function() { + clearTimeout(this.batteryTimer); + gSounds.scan.pause(); + }, + updateBattery: function() { + document.getElementById("devBattLevel").textContent = + (navigator.battery.level * 100).toFixed(1) + "%"; + if (navigator.battery.charging) { + if (navigator.battery.chargingTime == 0 || + navigator.battery.chargingTime == Infinity) { + document.getElementById("devBattStatus").textContent = "charging"; + } + else { + document.getElementById("devBattStatus").textContent = + "charging, " + navigator.battery.chargingTime + "s remaining"; + } + } + else { + if (navigator.battery.dischargingTime == 0 || + navigator.battery.dischargingTime == Infinity) { + document.getElementById("devBattStatus").textContent = "discharging"; + } + else { + document.getElementById("devBattStatus").textContent = + navigator.battery.dischargingTime + "s usage remaining"; + } + } + }, + batteryTimer: null, +} + +var gModSound = { + activate: function() { + //gSounds.scan.play(); + }, + // getUserMedia ("WebRTC") + MediaElementAudioSourceNode (WebAudio) + deactivate: function() { + gSounds.scan.pause(); + }, +} + var gModOther = { activate: function() { //gSounds.scan.play();