You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by mm...@apache.org on 2014/05/05 18:09:02 UTC
[02/49] git commit: accelerometer registers, but is not responding
accelerometer registers, but is not responding
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/3dad5222
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-device-motion/tree/3dad5222
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-device-motion/diff/3dad5222
Branch: refs/heads/cdvtest
Commit: 3dad522215752b086ed106f82d4f6792750e82fe
Parents: 6d3a17b
Author: Piotr Zalewa <pi...@zalewa.info>
Authored: Fri Sep 20 12:22:47 2013 +0200
Committer: Piotr Zalewa <pi...@zalewa.info>
Committed: Fri Sep 20 12:22:47 2013 +0200
----------------------------------------------------------------------
src/firefoxos/accelerometer.js | 44 ++++++++-----------------------------
1 file changed, 9 insertions(+), 35 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-device-motion/blob/3dad5222/src/firefoxos/accelerometer.js
----------------------------------------------------------------------
diff --git a/src/firefoxos/accelerometer.js b/src/firefoxos/accelerometer.js
index bde8acc..696f1e5 100644
--- a/src/firefoxos/accelerometer.js
+++ b/src/firefoxos/accelerometer.js
@@ -1,44 +1,18 @@
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
+var Accelerometer = {
+ start: function start(accelerometerSuccess, accelerometerError) {
+ console.log('start watching acecelerometer');
+ function accelerationCallback(deviceMotionEvent) {
accelerometerSuccess(deviceMotionEvent.acceleration);
- hit = newHit;
}
+ return document.addEventListener('devicemotion', accelerationCallback, false);
+ },
+ stop: function stop(watchId) {
+ console.log('stop watching acecelerometer');
+ document.removeEventListener('devicemotion', watchId);
}
- 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);