From: Robert Kaiser Date: Thu, 13 Nov 2014 03:17:19 +0000 (+0100) Subject: add Environment module with light and proximity sensors as well as untested and unsty... X-Git-Tag: production~5 X-Git-Url: https://git-public.kairo.at/?a=commitdiff_plain;h=0c4c028bd224b3f9da26d71ce7b1d61c166a0ae2;p=tricorder.git add Environment module with light and proximity sensors as well as untested and unstyled flashlight support --- diff --git a/.htaccess b/.htaccess new file mode 100644 index 0000000..d31f16e --- /dev/null +++ b/.htaccess @@ -0,0 +1 @@ +AddType application/x-web-app-manifest+json package diff --git a/TODO b/TODO index 3c384fb..6f6d2d4 100644 --- a/TODO +++ b/TODO @@ -8,9 +8,6 @@ Tasks to complete for Web Tricorder: *** Nearby Bluetooth devices: https://wiki.mozilla.org/WebAPI/WebBluetooth ** Device properties: *** Storage: https://github.com/mozilla-b2g/gaia/blob/master/apps/settings/js/app_storage.js -** Environment: -*** Ambient Light: http://www.w3.org/TR/ambient-light/ -*** Proximity: http://www.w3.org/TR/2012/WD-proximity-20120712/ - https://hacks.mozilla.org/2013/06/the-proximity-api/ ** Video analysis *** histograms, etc. * Make output more beautiful diff --git a/index.html b/index.html index 265df47..16ee42c 100644 --- a/index.html +++ b/index.html @@ -35,6 +35,7 @@ + @@ -111,6 +112,28 @@ a better device. +
+

+Environment sensors are unavailable on this tricorder device. +
Please talk to your superior officer or Starfleet contact to acquire +a better device. +

+ +
+
diff --git a/js/tricorder.js b/js/tricorder.js index de33ae3..3ab7ee9 100644 --- a/js/tricorder.js +++ b/js/tricorder.js @@ -305,6 +305,72 @@ var gModSound = { }, } +var gModEnv = { + activate: function() { + gSounds.scan.play(); + document.getElementById("envunavail").style.display = "none"; + document.getElementById("envavail").style.display = "block"; + window.addEventListener("devicelight", this.lightEvent, true); + window.addEventListener("deviceproximity", this.proxEvent, true); + setTimeout(function() { + if ((document.getElementById("envLight").textContent == "...") && + (document.getElementById("envDistance").textContent == "...")) { + gModEnv.deactivate(); + } + }, 5000); + try { + for (var cameraId of window.navigator.mozCameras.getListOfCameras()) { + window.navigator.mozCameras.getCamera({camera: cameraId}, function(aCamera) { + if (aCamera.capabilities.flashModes.indexOf('torch') !== -1) { + this.flashCamera = aCamera; + } + }); + } + if (this.flashCamera) { + document.getElementById("envFlashOn").onclick = gModEnv.switchFlashlight(true); + document.getElementById("envFlashOff").onclick = gModEnv.switchFlashlight(false); + document.getElementById("envFlashUnavail").style.display = "none"; + document.getElementById("envFlashAvail").style.display = "block"; + } + } catch (e) { + // camera api not supported + document.getElementById("envFlashUnavail").style.display = "block"; + document.getElementById("envFlashAvail").style.display = "none"; + } + }, + deactivate: function() { + gSounds.scan.pause(); + window.removeEventListener("devicelight", this.lightEvent, true); + window.removeEventListener("deviceproximity", this.proxEvent, true); + document.getElementById("envunavail").style.display = "block"; + document.getElementById("envavail").style.display = "none"; + document.getElementById("envLight").textContent = "..."; + document.getElementById("envDistance").textContent = "..."; + }, + lightEvent: function(lightData) { + // See http://www.w3.org/TR/ambient-light/ + document.getElementById("envLight").textContent = lightData.value + " lux"; + }, + proxEvent: function(proxData) { + // See http://www.w3.org/TR/2012/WD-proximity-20120712/ + if (proxData.value >= proxData.max) { + document.getElementById("envDistance").textContent = "(maximum, >= " + proxData.value + " cm)"; + } + else if (proxData.value <= proxData.min) { + document.getElementById("envDistance").textContent = "(minimum, <= " + proxData.value + " cm)"; + } + else { + document.getElementById("envDistance").textContent = proxData.value + " cm"; + } + }, + flashCamera: null, + switchFlashlight: function(aEnabled) { + if (this.flashCamera) { + this.flashCamera.flashMode = aEnabled ? 'torch' : 'off'; + } + } +} + var gModDev = { activate: function() { gSounds.scan.play(); diff --git a/manifest.appcache b/manifest.appcache index da56acf..6e5b586 100644 --- a/manifest.appcache +++ b/manifest.appcache @@ -1,11 +1,15 @@ CACHE MANIFEST -# 2013-01-28. +# 2014-11-13 manifest.webapp js/tricorder.js +sound/key-action.opus +sound/key-press.opus +sound/launch.opus +sound/scan.opus +sound/shutdown.opus style/tricorder.css -style/DejaVuSansCondensed.ttf -style/DejaVuSansCondensed-Bold.ttf +style/OSPDIN.ttf style/tilex16.png style/tilex32.png style/tilex48.png diff --git a/manifest.webapp b/manifest.webapp index 29c1c18..17479a3 100644 --- a/manifest.webapp +++ b/manifest.webapp @@ -3,12 +3,16 @@ "description": "Display data from your device sensors in Star Trek style.", "version": "1.DVER", "launch_path": "/index.html", + "type": "privileged", "permissions": { "geolocation": { - "description": "Determine the global position to display in the tricorder." + "description": "Determine the location in the position module." }, "audio-capture": { "description": "Capture microphone audio for the sound module." + }, + "camera": { + "description": "Turn camera flash light on/off in environment module." } }, "developer": {
Battery Level:...