cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mmo...@apache.org
Subject [01/49] git commit: fxos added, not working
Date Mon, 05 May 2014 16:09:01 GMT
Repository: cordova-plugin-device-motion
Updated Branches:
  refs/heads/cdvtest 4607cba87 -> 1954d48b4


fxos added, not working


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-device-motion/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-device-motion/commit/6d3a17bc
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-device-motion/tree/6d3a17bc
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-device-motion/diff/6d3a17bc

Branch: refs/heads/cdvtest
Commit: 6d3a17bca3e02c8130fdd2a8c83c57cf1da4c12f
Parents: 81b8f96
Author: Piotr Zalewa <piotr@zalewa.info>
Authored: Fri Sep 20 11:09:30 2013 +0200
Committer: Piotr Zalewa <piotr@zalewa.info>
Committed: Fri Sep 20 11:09:30 2013 +0200

----------------------------------------------------------------------
 plugin.xml                     | 13 +++++++++++
 src/firefoxos/accelerometer.js | 44 +++++++++++++++++++++++++++++++++++++
 2 files changed, 57 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-device-motion/blob/6d3a17bc/plugin.xml
----------------------------------------------------------------------
diff --git a/plugin.xml b/plugin.xml
index 032ab01..cd7e840 100644
--- a/plugin.xml
+++ b/plugin.xml
@@ -17,6 +17,19 @@
         <clobbers target="navigator.accelerometer" />
     </js-module>
     
+    <!-- firefoxos -->
+    <platform name="firefoxos">
+        <config-file target="config.xml" parent="/*">
+            <feature name="Accelerometer">
+                <param name="firefoxos-package" value="Accelerometer" />
+            </feature>
+        </config-file>                                         
+        
+        <js-module src="src/firefoxos/accelerometer.js" name="accelerometer-impl">
+          <runs />
+        </js-module>
+    </platform>
+
     <!-- android -->
     <platform name="android">
 	    

http://git-wip-us.apache.org/repos/asf/cordova-plugin-device-motion/blob/6d3a17bc/src/firefoxos/accelerometer.js
----------------------------------------------------------------------
diff --git a/src/firefoxos/accelerometer.js b/src/firefoxos/accelerometer.js
new file mode 100644
index 0000000..bde8acc
--- /dev/null
+++ b/src/firefoxos/accelerometer.js
@@ -0,0 +1,44 @@
+var firefoxos = require('cordova/platform');
+
+// initiate watching the acceleration and clear it straight afterwards
+function getCurrentAcceleration(accelerometerSuccess, accelerometerError) {
+    var listener = document.addEventListener('devicemotion', accelerationCallback, false);
+    function accelerationCallback(deviceMotionEvent) {
+        accelerometerSuccess(deviceMotionEvent.acceleration);
+        document.removeEventListener('devicemotion', listener, false);
+    }
+}
+
+// listen to acceleration and call accelerometerSuccess every x milliseconds
+function watchAcceleration(accelerometerSuccess, accelerometerError, options) {
+    // last timestamp when callback was called
+    var hit = 0;
+    var frequency = 0;
+    if (options && options.frequency) {
+        frequency = options.frequency;
+    }
+    function accelerationCallback(deviceMotionEvent) {
+        var newHit;
+        if (frequency) {
+          newHit = new Date().getTime();
+        }
+        if (!frequency || newHit >= hit + frequency) {
+            // return acceleration object instead of event
+            accelerometerSuccess(deviceMotionEvent.acceleration);
+            hit = newHit;
+        }
+    }
+    return document.removeEventListener('devicemotion', accelerationCallback, false);
+}
+
+function clearWatch(watchId) {
+    document.removeEventListener('devicemotion', watchId);
+}
+
+var Accelerometer = {
+    getCurrentAcceleration: getCurrentAcceleration,
+    watchAcceleration: watchAcceleration,
+    clearWatch: clearWatch,
+};
+
+firefoxos.registerPlugin('Accelerometer', Accelerometer);


Mime
View raw message