From 06a8a0abcb0080851fa1cccdb55a60c31d2a55f5 Mon Sep 17 00:00:00 2001 From: Andrzej Popowski Date: Thu, 3 Dec 2015 15:11:48 +0100 Subject: [PATCH] [Devicemotion] - fix first data got from accelerometer Change-Id: I947e6ad9d2a239ca7ddc0071d818c4177a8d7e0d Signed-off-by: Andrzej Popowski --- src/devicemotion/cordova_devicemotion_api.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/devicemotion/cordova_devicemotion_api.js b/src/devicemotion/cordova_devicemotion_api.js index 804cc38..353d0ee 100755 --- a/src/devicemotion/cordova_devicemotion_api.js +++ b/src/devicemotion/cordova_devicemotion_api.js @@ -21,6 +21,7 @@ cordova.define(plugin_name, function(require, exports, module) { // TODO: remove -> end var successCB = null; +var count = 0; function listener(eventData) { var accel = {}; @@ -35,12 +36,17 @@ function listener(eventData) { return; } + if (count++ === 0) { + return; + } + successCB && successCB(accel); } var Accelerometer = { start: function (success, error) { if (!successCB) { + count = 0; successCB = success; window.addEventListener('devicemotion', listener, false); } -- 2.7.4