Permalink
Browse files

Merge pull request #111 from starpax/master

webworks Compass sensor Javascript API
  • Loading branch information...
2 parents 21cf0ec + bf4920d commit d37a891b397be03712497e0ac5db3a31ba31bde7 @timwindsor timwindsor committed Oct 26, 2012
Showing with 3,144 additions and 0 deletions.
  1. +4 −0 .gitignore
  2. +81 −0 BB10/COMPASS/README.md
  3. +3 −0 BB10/COMPASS/TestApplication/README.md
  4. +30 −0 BB10/COMPASS/TestApplication/config.xml
  5. +42 −0 BB10/COMPASS/TestApplication/index.htm
  6. +38 −0 BB10/COMPASS/javascript_src/client.js
  7. +121 −0 BB10/COMPASS/javascript_src/index.js
  8. +5 −0 BB10/COMPASS/javascript_src/manifest.json
  9. +320 −0 BB10/COMPASS/native_src/public/plugin.cpp
  10. +70 −0 BB10/COMPASS/native_src/public/plugin.h
  11. +222 −0 BB10/COMPASS/native_src/public/tokenizer.cpp
  12. +55 −0 BB10/COMPASS/native_src/public/tokenizer.h
  13. +301 −0 BB10/COMPASS/native_src/src/compass_js.cpp
  14. +53 −0 BB10/COMPASS/native_src/src/compass_js.hpp
  15. +38 −0 BB10/COMPASS/output/community.compass/client.js
  16. BIN BB10/COMPASS/output/community.compass/device/compassJnext.so
  17. +121 −0 BB10/COMPASS/output/community.compass/index.js
  18. +5 −0 BB10/COMPASS/output/community.compass/manifest.json
  19. BIN BB10/COMPASS/output/community.compass/simulator/compassJnext.so
  20. +525 −0 BB10/COMPASS/project/compassJnext/.cproject
  21. +89 −0 BB10/COMPASS/project/compassJnext/.project
  22. +320 −0 BB10/COMPASS/project/compassJnext/public/plugin.cpp
  23. +70 −0 BB10/COMPASS/project/compassJnext/public/plugin.h
  24. +222 −0 BB10/COMPASS/project/compassJnext/public/tokenizer.cpp
  25. +55 −0 BB10/COMPASS/project/compassJnext/public/tokenizer.h
  26. +301 −0 BB10/COMPASS/project/compassJnext/src/compass_js.cpp
  27. +53 −0 BB10/COMPASS/project/compassJnext/src/compass_js.hpp
View
@@ -1,2 +1,6 @@
add
.DS_Store
+.metadata/
+.settings/
+*.[o]
+webworks-1.0.2.9.js
View
@@ -0,0 +1,81 @@
+# Compass API
+
+The Compass API allows you to read the leading of the compass in your device.
+
+**Tested On**
+
+* BlackBerry 10.0.9.388
+
+**Author(s)**
+
+* [Arman Fallah](https://github.com/starpax)
+
+**To contribute code to this repository you must be [signed up as an official contributor](http://blackberry.github.com/howToContribute.html).**
+
+## How To Install The Extension
+
+1. Clone the repo to your local machine
+2. Locate your BlackBerry WebWorks SDK **C:\Program Files\Research In Motion\BlackBerry 10 WebWorks SDK <version>\Framework\ext** (Windows) or **~/SDKs/BlackBerry 10 WebWorks SDK <version>/Framework/ext** (Mac)
+3. Create a new directory **community.compass** in the **ext** directory
+4. Copy **output/community.compass/compassJnext.so** to **/path/to/sdk/ext/community.compass/device/compassJnext.so**
+5. Copy everything in **javascript_src** to **/path/to/sdk/ext/community.compass/**
+
+## Required Feature ID
+Whenever you use the below feature id in any of your WebWorks applications this extension will be loaded for use.
+
+ <feature id="community.compass" required="true" version="1.0.0.0" />
+
+## Summary
+
+**community.compass.readCompass()**
+
+Return:
+number - degrees from Magnetic North
+
+Example:
+
+ <script type="text/javascript">
+ var leading = community.compass.readCompass();
+ </script>
+
+**community.compass.startMonitoringCompass([Function:fun])**
+
+Parameter:
+fun: a one parameter method to call each second, that parameter stores the compass leading
+
+Return:
+[String] - status message of monitoring the compass
+
+Example:
+
+ <script type="text/javascript">
+ function compassCallback(compassLeading)
+ {
+ document.getElementById("leading").innerHTML = "Degrees from Magnetic North: " + compassLeading;
+ }
+
+ function startMonitoringCompass()
+ {
+ var ret = community.compass.startMonitoringCompass(compassCallback);
+ alert(ret);
+ }
+ </script>
+
+**community.compass.stopMonitoringCompass()**
+
+Return:
+[String] - status message of stopping the monitoring the compass
+
+Example:
+
+ <script type="text/javascript">
+ function stopMonitoringCompass()
+ {
+ var ret = community.compass.stopMonitoringCompass();
+ alert(ret);
+ }
+ </script>
+
+## Disclaimer
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,3 @@
+# Where to find the missing file webworks-1.0.0.7.js
+
+You will find it under Framework/clientFiles/webworks-1.0.0.7.js in your WebWorks SDK installation folder and copy it to this folder.
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright 2012 Research In Motion Limited.
+
+ 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.
+-->
+<widget xmlns="http://www.w3.org/ns/widgets"
+ xmlns:rim="http://www.blackberry.com/ns/widgets"
+ version="1.0.0"
+ id="CompassExtension">
+ <name>Compass Test</name>
+ <content src="index.htm"/>
+ <author>
+ Research In Motion Ltd.
+ </author>
+ <description>This application shows how to use the compass extension.</description>
+ <feature id="community.compass" required="true" version="1.0.0.0"/>
+ <access uri="*"/>
+ <license href="http://www.apache.org/licenses/LICENSE-2.0">My License</license>
+</widget>
@@ -0,0 +1,42 @@
+<html>
+ <head>
+ <title>Community - Compass Extension</title>
+ <script type="text/javascript" src="webworks-1.0.2.9.js"></script>
+ <script type="text/javascript">
+ function compassCallback(compassLeading) {
+ document.getElementById("leading").innerHTML = "Degrees from Magnetic North: " + compassLeading;
+ }
+
+ function startMonitoringCompass() {
+ var ret = community.compass.startMonitoringCompass(compassCallback);
+ alert(ret);
+ }
+
+ function getCompassLeading() {
+ var ret = community.compass.readCompass();
+ alert(ret);
+ }
+
+ function stopMonitoringCompass() {
+ var ret = community.compass.stopMonitoringCompass();
+ alert(ret);
+ }
+ </script>
+ </head>
+ <body bgcolor="#FF9900">
+ <div align="center">
+ <button style="width:280px; height: 240px; font-size: 200%; background-color: lightgreen" onClick="startMonitoringCompass()">
+ Start Monitoring Compass
+ </button>
+ <button style="width:280px; height: 240px; font-size: 200%; background-color: lightgreen" onClick="stopMonitoringCompass()">
+ Stop Monitoring Compass
+ </button>
+ <button style="width:280px; height: 240px; font-size: 200%; background-color: lightgreen" onClick="getCompassLeading()">
+ Get Compass Leading
+ </button>
+ <br />
+ </div>
+ <div id="leading" style="font-size: 200%; background-color: lightblue">
+ </div>
+ </body>
+</html>
@@ -0,0 +1,38 @@
+/*
+* Copyright 2012 Research In Motion Limited.
+*
+* 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.
+*/
+
+var _self = {},
+ _ID = require("./manifest.json").namespace;
+
+_self.readCompass = function (cb)
+{
+ return window.webworks.execSync(_ID, "readCompassServer", null);
+};
+
+_self.stopMonitoringCompass = function (cb)
+{
+ return window.webworks.execSync(_ID, "stopMonitoringCompassServer", null);
+};
+
+
+_self.startMonitoringCompass = function (cb)
+{
+ window.webworks.event.add(_ID, "community.compass.compassEvent", cb);
+
+ return window.webworks.execSync(_ID, "startMonitoringCompassServer", null);
+};
+
+module.exports = _self;
@@ -0,0 +1,121 @@
+/*
+ * Copyright 2012 Research In Motion Limited.
+ *
+ * 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.
+ */
+var compassJNext,
+ _event = require("../../lib/event");
+
+module.exports =
+{
+ startMonitoringCompassServer: function (success, fail, args, env)
+ {
+ try
+ {
+ success(compassJNext.startMonitoringCompassJNext());
+ }
+ catch (e)
+ {
+ fail(-1, e);
+ }
+ },
+
+ stopMonitoringCompassServer: function (success, fail, args, env)
+ {
+ try
+ {
+ success(compassJNext.stopMonitoringCompassJNext());
+ }
+ catch (e)
+ {
+ fail(-1, e);
+ }
+ },
+
+ readCompassServer: function (success, fail, args, env)
+ {
+ try
+ {
+ success(compassJNext.readCompassJNext());
+ }
+ catch (e)
+ {
+ fail(-1, e);
+ }
+ },
+};
+
+///////////////////////////////////////////////////////////////////
+// JavaScript wrapper for JNEXT plugin
+///////////////////////////////////////////////////////////////////
+
+JNEXT.CompassJNext = function ()
+{
+ var _self = this;
+
+ _self.startMonitoringCompassJNext = function ()
+ {
+ return JNEXT.invoke(_self._id, "startMonitoringNative");
+ };
+
+ _self.stopMonitoringCompassJNext = function ()
+ {
+ return JNEXT.invoke(_self._id, "stopMonitoringNative");
+ };
+
+ _self.readCompassJNext = function ()
+ {
+ return JNEXT.invoke(_self._id, "readCompassNative");
+ };
+
+ _self.getId = function ()
+ {
+ return _self._id;
+ };
+
+ _self.init = function ()
+ {
+ if (!JNEXT.require("compassJnext"))
+ {
+ return false;
+ }
+
+ _self._id = JNEXT.createObject("compassJnext.Compass");
+
+ if (!_self._id || _self._id === "")
+ {
+ return false;
+ }
+
+ JNEXT.registerEvents(_self);
+ };
+
+ _self.onEvent = function (strData)
+ {
+ var arData = strData.split(" "),
+ strEventId = arData[0],
+ arg = arData[1];
+
+ // Trigger the event handler of specific Push events
+ if (strEventId === "CompassLeading")
+ {
+ _event.trigger("community.compass.compassEvent", arg);
+ }
+ };
+
+ _self._id = "";
+
+ _self.init();
+};
+
+compassJNext = new JNEXT.CompassJNext();
@@ -0,0 +1,5 @@
+{
+ "global": false,
+ "namespace": "community.compass",
+ "dependencies": []
+}
Oops, something went wrong.

0 comments on commit d37a891

Please sign in to comment.