add Environment module with light and proximity sensors as well as untested and unsty...
authorRobert Kaiser <kairo@kairo.at>
Thu, 13 Nov 2014 03:17:19 +0000 (04:17 +0100)
committerRobert Kaiser <kairo@kairo.at>
Thu, 13 Nov 2014 03:17:19 +0000 (04:17 +0100)
.htaccess [new file with mode: 0644]
TODO
index.html
js/tricorder.js
manifest.appcache
manifest.webapp

diff --git a/.htaccess b/.htaccess
new file mode 100644 (file)
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 3c384fb00ddd360034000dabc1e9d1fec809e52b..6f6d2d4adebc7741139f642fb12de9d6e3bf30ee 100644 (file)
--- 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
 *** 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
 ** Video analysis
 *** histograms, etc.
 * Make output more beautiful
index 265df47fccaa315ab69c994c9c409f79e5bb0781..16ee42cb28fb51d07812a2bb824bc861c21dc890 100644 (file)
@@ -35,6 +35,7 @@
 <li id="navPos">Position</li>
 <li id="navGrav">Gravity</li>
 <li id="navSound">Sound</li>
 <li id="navPos">Position</li>
 <li id="navGrav">Gravity</li>
 <li id="navSound">Sound</li>
+<li id="navEnv">Environment</li>
 <li id="navDev">Device</li>
 <li id="navOther">Other</li>
 </ul>
 <li id="navDev">Device</li>
 <li id="navOther">Other</li>
 </ul>
@@ -111,6 +112,28 @@ a better device.
 </div>
 </section>
 
 </div>
 </section>
 
+<section id="sectEnv">
+<p id="envunavail">
+Environment sensors are unavailable on this tricorder device.
+<br/>Please talk to your superior officer or Starfleet contact to acquire
+a better device.
+</p>
+<div id="envavail" style="display:none">
+<table>
+<tr><td>Light:</td><td id="envLight" class="envVal">...</td></tr>
+<tr><td>Distance:</td><td id="envDistance" class="envVal">...</td></tr>
+</table>
+<div id="envFlashAvail" style="display:none">
+Flashlight:
+<button id="envFlashOn" class="envButton">On</button>
+<button id="envFlashOff" class="envButton">Off</button>
+</div>
+<div id="envFlashUnavail">
+<!-- No camera with flash available -->
+</div>
+</div>
+</section>
+
 <section id="sectDev">
 <table>
 <tr><td>Battery Level:</td><td id="devBattLevel" class="deviceVal">...</td></tr>
 <section id="sectDev">
 <table>
 <tr><td>Battery Level:</td><td id="devBattLevel" class="deviceVal">...</td></tr>
index de33ae3a630e2c2eed70a95e946c314aea24b8fd..3ab7ee948fe0f41b15b6723efffcf05cff3403f8 100644 (file)
@@ -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();
 var gModDev = {
   activate: function() {
     gSounds.scan.play();
index da56acf51f200a7a44bf1d9befd3680851d1cbb7..6e5b5869637d09f67c2c74a8810e27ee246f5cca 100644 (file)
@@ -1,11 +1,15 @@
 CACHE MANIFEST
 
 CACHE MANIFEST
 
-# 2013-01-28.
+# 2014-11-13
 manifest.webapp
 js/tricorder.js
 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/tricorder.css
-style/DejaVuSansCondensed.ttf
-style/DejaVuSansCondensed-Bold.ttf
+style/OSPDIN.ttf
 style/tilex16.png
 style/tilex32.png
 style/tilex48.png
 style/tilex16.png
 style/tilex32.png
 style/tilex48.png
index 29c1c1825b4bf3ab360cbe309ef86becab2912ec..17479a3a0290c671c722114d7f76f69764d815c6 100644 (file)
@@ -3,12 +3,16 @@
   "description": "Display data from your device sensors in Star Trek style.",
   "version": "1.DVER",
   "launch_path": "/index.html",
   "description": "Display data from your device sensors in Star Trek style.",
   "version": "1.DVER",
   "launch_path": "/index.html",
+  "type": "privileged",
   "permissions": {
     "geolocation": {
   "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."
     },
     "audio-capture": {
       "description": "Capture microphone audio for the sound module."
+    },
+    "camera": {
+      "description": "Turn camera flash light on/off in environment module."
     }
   },
   "developer": {
     }
   },
   "developer": {