You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by he...@apache.org on 2012/04/05 21:41:02 UTC

[2/18] webos commit: get compass api to pass mobile spec tests

get compass api to pass mobile spec tests


Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-webos/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-webos/commit/04382019
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-webos/tree/04382019
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-webos/diff/04382019

Branch: refs/heads/master
Commit: 043820194bc42c951067c575b69448c980c5f9f4
Parents: 5e8870b
Author: hermwong <he...@gmail.com>
Authored: Wed Apr 4 17:13:27 2012 -0700
Committer: hermwong <he...@gmail.com>
Committed: Thu Apr 5 12:21:09 2012 -0700

----------------------------------------------------------------------
 Makefile                   |    2 +-
 framework/cordova-1.6.0.js |   65 +++++++++++++++++++++++++++++++++++++-
 framework/index.html       |    8 +++-
 js/compass.js              |   48 +++++++++++++++++++++++++++-
 4 files changed, 116 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-webos/blob/04382019/Makefile
----------------------------------------------------------------------
diff --git a/Makefile b/Makefile
index 4a93f3e..61ffeeb 100755
--- a/Makefile
+++ b/Makefile
@@ -46,7 +46,7 @@ copy_js:
 	
 js: lib/cordova.js
 
-lib/cordova.js: js/cordova-core.js js/acceleration.js js/accelerometer.js js/application.js js/audio.js js/camera.js js/contacts.js js/debugconsole.js js/device.js js/file.js js/geolocation.js js/map.js js/mojo.js js/mouse.js js/network.js js/notification.js js/orientation.js js/position.js js/service.js js/sms.js js/telephony.js js/window.js js/windowproperties.js lib/thumbs.0.5.2.js
+lib/cordova.js: js/cordova-core.js js/acceleration.js js/accelerometer.js js/application.js js/audio.js js/camera.js js/compass.js js/contacts.js js/debugconsole.js js/device.js js/file.js js/geolocation.js js/map.js js/mojo.js js/mouse.js js/network.js js/notification.js js/orientation.js js/position.js js/service.js js/sms.js js/telephony.js js/window.js js/windowproperties.js lib/thumbs.0.5.2.js
 	$(MKPATH) lib
 	$(RM_F) $@
 	$(CAT) js/cordova-core.js >> $@

http://git-wip-us.apache.org/repos/asf/incubator-cordova-webos/blob/04382019/framework/cordova-1.6.0.js
----------------------------------------------------------------------
diff --git a/framework/cordova-1.6.0.js b/framework/cordova-1.6.0.js
index 66b6848..f72da12 100644
--- a/framework/cordova-1.6.0.js
+++ b/framework/cordova-1.6.0.js
@@ -752,7 +752,7 @@ function Compass() {
   /*
 	 * The last known heading.
 	 */
-	this.lastHeading = null;
+	this.lastHeading = null;//new CompassHeading;
 };
 
 /*
@@ -768,6 +768,8 @@ function Compass() {
 Compass.prototype.getCurrentHeading = function(successCallback, errorCallback, options) {
 
     var referenceTime = 0;
+	var compassHeading = new CompassHeading();
+
     if (this.lastHeading)
         referenceTime = this.lastHeading.timestamp;
     else
@@ -790,7 +792,19 @@ Compass.prototype.getCurrentHeading = function(successCallback, errorCallback, o
  
 		//if we have a new compass heading, call success and cancel the timer
         if (typeof(dis.lastHeading) == 'object' && dis.lastHeading != null && dis.lastHeading.timestamp > referenceTime) {
-            successCallback(dis.lastHeading.magHeading);
+
+			compassHeading.timestamp = new Date(referenceTime);
+			compassHeading.magneticHeading = dis.lastHeading.magHeading;
+			compassHeading.trueHeading = dis.lastHeading.trueHeading;
+			
+			if (dis.lastHeading.headingAccuracy === undefined)
+				compassHeading.headingAccuracy = 1;
+			else
+				compassHeading.headingAccuracy = dis.lastHeading.headingAccuracy;
+
+			successCallback(compassHeading);
+
+            //successCallback(dis.lastHeading.magHeading);
             clearInterval(timer);
         } else if (delay >= timeout) { //else if timeout has occured then call error and cancel the timer
             errorCallback();
@@ -845,6 +859,36 @@ Compass.prototype.start = function() {
 	});
 };
 
+function CompassHeading(mHeading, tHeading, accuracy, time) {
+	if (mHeading === undefined)
+		this.magneticHeading = null;
+	else
+		this.magneticHeading = mHeading;
+		
+	if (tHeading === undefined)
+		this.trueHeading = null;
+	else
+		this.trueHeading = tHeading;
+		
+	if (accuracy === undefined)	
+		this.headingAccuracy = null;
+	else
+		this.headingAccuracy = accuracy;
+		
+	if (time === undefined)	
+		this.timestamp = new Date();
+	else
+		this.timestamp = new Date(time);
+};
+
+function CompassError() {
+	this.code = null;
+	this.message = "";	
+};
+
+CompassError.COMPASS_INTERNAL_ERR = 0;
+CompassError.COMPASS_NOT_SUPPORTED = 20;
+
 if (typeof navigator.compass == "undefined") navigator.compass = new Compass();
 /*
  * This class provides access to the debugging console.
@@ -1400,6 +1444,23 @@ Network.prototype.connection = function(hostName, successCallback, options) {
 	});	
 };
 
+Network.prototype.connection.type = function(hostName, successCallback, options) {
+	navigator.network.isReachable(hostName,successCallback, options);
+};
+
+function Connection() {
+	this.code = null;
+	this.message = "";
+};
+
+Connection.UNKNOWN = 'unknown';
+Connection.ETHERNET = 'ethernet';
+Connection.WIFI = 'wifi';
+Connection.CELL_2G = '2g';
+Connection.CELL_3G = '3g';
+Connection.CELL_4G = '4g';
+Connection.NONE = 'none';
+
 /*
  * This class contains information about any NetworkStatus.
  * @constructor

http://git-wip-us.apache.org/repos/asf/incubator-cordova-webos/blob/04382019/framework/index.html
----------------------------------------------------------------------
diff --git a/framework/index.html b/framework/index.html
index 666ea60..d39a04e 100644
--- a/framework/index.html
+++ b/framework/index.html
@@ -112,6 +112,7 @@
     <p>Watch Heading</p>
     <button id="btnStartCompassWatch" onclick="startCompassWatch();">Start Compass Watch</button>
     <button id="btnStopCompassWatch" onclick="stopCompassWatch();">Stop Compass Watch</button>
+    <div id="compassResult"></div>
 
 </div>
 
@@ -125,7 +126,10 @@ var watchId = null;
 function displayCurrentHeading() {
     
     function successful(response) {
-        navigator.notification.alert("last heading: " + response);
+        //navigator.notification.alert("last heading: " + JSON.stringify(response));
+        var compassPage = document.getElementById("compassResult");
+        compassPage.innerHTML = "current heading: "
+        compassPage.innerHTML += JSON.stringify(response);
     }
     
     var request = navigator.compass.getCurrentHeading(successful, {});
@@ -151,7 +155,7 @@ function stopCompassWatch() {
 }
 
 function onCompassError(compassError) {
-    navigator.notification.alert("Compass error: " + compassError.code);
+    navigator.notification.alert("Compass error");// + compassError.code);
 }
 
 

http://git-wip-us.apache.org/repos/asf/incubator-cordova-webos/blob/04382019/js/compass.js
----------------------------------------------------------------------
diff --git a/js/compass.js b/js/compass.js
index 824d0df..355aabc 100644
--- a/js/compass.js
+++ b/js/compass.js
@@ -6,7 +6,7 @@ function Compass() {
   /*
 	 * The last known heading.
 	 */
-	this.lastHeading = null;
+	this.lastHeading = null;//new CompassHeading;
 };
 
 /*
@@ -22,6 +22,8 @@ function Compass() {
 Compass.prototype.getCurrentHeading = function(successCallback, errorCallback, options) {
 
     var referenceTime = 0;
+	var compassHeading = new CompassHeading();
+
     if (this.lastHeading)
         referenceTime = this.lastHeading.timestamp;
     else
@@ -44,7 +46,19 @@ Compass.prototype.getCurrentHeading = function(successCallback, errorCallback, o
  
 		//if we have a new compass heading, call success and cancel the timer
         if (typeof(dis.lastHeading) == 'object' && dis.lastHeading != null && dis.lastHeading.timestamp > referenceTime) {
-            successCallback(dis.lastHeading.magHeading);
+
+			compassHeading.timestamp = new Date(referenceTime);
+			compassHeading.magneticHeading = dis.lastHeading.magHeading;
+			compassHeading.trueHeading = dis.lastHeading.trueHeading;
+			
+			if (dis.lastHeading.headingAccuracy === undefined)
+				compassHeading.headingAccuracy = 1;
+			else
+				compassHeading.headingAccuracy = dis.lastHeading.headingAccuracy;
+
+			successCallback(compassHeading);
+
+            //successCallback(dis.lastHeading.magHeading);
             clearInterval(timer);
         } else if (delay >= timeout) { //else if timeout has occured then call error and cancel the timer
             errorCallback();
@@ -99,4 +113,34 @@ Compass.prototype.start = function() {
 	});
 };
 
+function CompassHeading(mHeading, tHeading, accuracy, time) {
+	if (mHeading === undefined)
+		this.magneticHeading = null;
+	else
+		this.magneticHeading = mHeading;
+		
+	if (tHeading === undefined)
+		this.trueHeading = null;
+	else
+		this.trueHeading = tHeading;
+		
+	if (accuracy === undefined)	
+		this.headingAccuracy = null;
+	else
+		this.headingAccuracy = accuracy;
+		
+	if (time === undefined)	
+		this.timestamp = new Date();
+	else
+		this.timestamp = new Date(time);
+};
+
+function CompassError() {
+	this.code = null;
+	this.message = "";	
+};
+
+CompassError.COMPASS_INTERNAL_ERR = 0;
+CompassError.COMPASS_NOT_SUPPORTED = 20;
+
 if (typeof navigator.compass == "undefined") navigator.compass = new Compass();