get compass api to pass mobile spec tests
diff --git a/Makefile b/Makefile
index 4a93f3e..61ffeeb 100755
--- a/Makefile
+++ b/Makefile
@@ -46,7 +46,7 @@
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 >> $@
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 @@
/*
* The last known heading.
*/
- this.lastHeading = null;
+ this.lastHeading = null;//new CompassHeading;
};
/*
@@ -768,6 +768,8 @@
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 @@
//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 @@
});
};
+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.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
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 @@
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 onCompassError(compassError) {
- navigator.notification.alert("Compass error: " + compassError.code);
+ navigator.notification.alert("Compass error");// + compassError.code);
}
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 @@
/*
* The last known heading.
*/
- this.lastHeading = null;
+ this.lastHeading = null;//new CompassHeading;
};
/*
@@ -22,6 +22,8 @@
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 @@
//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 @@
});
};
+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();