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:22 UTC
[22/49] git commit: add ubuntu platform
add ubuntu platform
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/057813b8
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-device-motion/tree/057813b8
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-device-motion/diff/057813b8
Branch: refs/heads/cdvtest
Commit: 057813b85e65dd3cabcd270f2b63a306997009be
Parents: d660d02
Author: Maxim Ermilov <ma...@canonical.com>
Authored: Wed Nov 13 17:13:38 2013 +0400
Committer: Maxim Ermilov <ma...@canonical.com>
Committed: Wed Nov 13 17:13:38 2013 +0400
----------------------------------------------------------------------
plugin.xml | 8 +++++-
src/ubuntu/accelerometer.cpp | 58 +++++++++++++++++++++++++++++++++++++++
src/ubuntu/accelerometer.h | 55 +++++++++++++++++++++++++++++++++++++
3 files changed, 120 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-device-motion/blob/057813b8/plugin.xml
----------------------------------------------------------------------
diff --git a/plugin.xml b/plugin.xml
index 26e7485..04cabe3 100644
--- a/plugin.xml
+++ b/plugin.xml
@@ -29,7 +29,13 @@
<source-file src="src/android/AccelListener.java" target-dir="src/org/apache/cordova/devicemotion" />
</platform>
-
+
+ <!-- ubuntu -->
+ <platform name="ubuntu">
+ <header-file src="src/ubuntu/accelerometer.h" />
+ <source-file src="src/ubuntu/accelerometer.cpp" />
+ </platform>
+
<!-- ios -->
<platform name="ios">
http://git-wip-us.apache.org/repos/asf/cordova-plugin-device-motion/blob/057813b8/src/ubuntu/accelerometer.cpp
----------------------------------------------------------------------
diff --git a/src/ubuntu/accelerometer.cpp b/src/ubuntu/accelerometer.cpp
new file mode 100644
index 0000000..8d39174
--- /dev/null
+++ b/src/ubuntu/accelerometer.cpp
@@ -0,0 +1,58 @@
+/*
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+*/
+
+#include <cassert>
+#include "accelerometer.h"
+
+DeviceMotion::DeviceMotion(Cordova *cordova): CPlugin(cordova), _scId(0), _ecId(0) {
+ _accelerometerSource = QSharedPointer<QAccelerometer>(new QAccelerometer());
+ _sensorAvaliable = _accelerometerSource->start();
+ connect(_accelerometerSource.data(), SIGNAL(readingChanged()), SLOT(updateSensor()));
+}
+
+void DeviceMotion::start(int scId, int ecId) {
+ assert(_ecId == 0);
+ assert(_scId == 0);
+
+ _ecId = ecId;
+ _scId = scId;
+
+ if (!_sensorAvaliable) {
+ this->cb(ecId);
+ return;
+ }
+}
+
+void DeviceMotion::stop(int, int) {
+ _scId = 0;
+ _ecId = 0;
+}
+
+void DeviceMotion::updateSensor() {
+ QAccelerometerReading *accelerometer = _accelerometerSource->reading();
+
+ QVariantMap obj;
+ obj.insert("x", accelerometer->x());
+ obj.insert("y", accelerometer->y());
+ obj.insert("z", accelerometer->z());
+ // accelerometer->timestamp() is not sutiable.
+ // Timestamps values are microseconds since _a_ fixed point(depend on backend).
+ obj.insert("timestamp", QDateTime::currentDateTime().toMSecsSinceEpoch());
+
+ if (_scId)
+ this->cb(_scId, obj);
+}
http://git-wip-us.apache.org/repos/asf/cordova-plugin-device-motion/blob/057813b8/src/ubuntu/accelerometer.h
----------------------------------------------------------------------
diff --git a/src/ubuntu/accelerometer.h b/src/ubuntu/accelerometer.h
new file mode 100644
index 0000000..3f36a16
--- /dev/null
+++ b/src/ubuntu/accelerometer.h
@@ -0,0 +1,55 @@
+/*
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+*/
+
+#ifndef ACCELEROMETER_H
+#define ACCELEROMETER_H
+
+#include <cplugin.h>
+#include <QAccelerometer>
+#include <QtCore>
+
+class DeviceMotion: public CPlugin {
+ Q_OBJECT
+public:
+ explicit DeviceMotion(Cordova *cordova);
+
+ virtual const QString fullName() override {
+ return DeviceMotion::fullID();
+ }
+
+ virtual const QString shortName() override {
+ return "Accelerometer";
+ }
+
+ static const QString fullID() {
+ return "Accelerometer";
+ }
+
+public slots:
+ void start(int scId, int ecId);
+ void stop(int scId, int ecId);
+
+protected slots:
+ void updateSensor();
+
+private:
+ int _scId, _ecId;
+ bool _sensorAvaliable;
+ QSharedPointer<QAccelerometer> _accelerometerSource;
+};
+
+#endif