You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by sh...@apache.org on 2016/12/08 00:56:42 UTC
[3/4] cordova-plugin-device-orientation git commit: CB-9179 (ios)
Fixed trueHeading being always 0
CB-9179 (ios) Fixed trueHeading being always 0
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-device-orientation/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-device-orientation/commit/c5b4d7da
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-device-orientation/tree/c5b4d7da
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-device-orientation/diff/c5b4d7da
Branch: refs/heads/1.0.x
Commit: c5b4d7da064301e31582dac31f844e04aaa673a4
Parents: f4cfb73
Author: Alexander Sorokin <al...@akvelon.com>
Authored: Thu Nov 3 13:39:18 2016 +0300
Committer: Alexander Sorokin <al...@akvelon.com>
Committed: Thu Nov 3 13:39:18 2016 +0300
----------------------------------------------------------------------
src/ios/CDVCompass.m | 1 +
tests/tests.js | 96 +++++++++++++++++++++++++++++++++++++++--------
2 files changed, 82 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-device-orientation/blob/c5b4d7da/src/ios/CDVCompass.m
----------------------------------------------------------------------
diff --git a/src/ios/CDVCompass.m b/src/ios/CDVCompass.m
index 86c4ed7..192264b 100644
--- a/src/ios/CDVCompass.m
+++ b/src/ios/CDVCompass.m
@@ -243,6 +243,7 @@
[self stopHeading:nil];
}
hData.headingStatus = HEADINGRUNNING; // to clear any error
+ __locationStarted = YES;
}
- (void)locationManager:(CLLocationManager*)manager didFailWithError:(NSError*)error
http://git-wip-us.apache.org/repos/asf/cordova-plugin-device-orientation/blob/c5b4d7da/tests/tests.js
----------------------------------------------------------------------
diff --git a/tests/tests.js b/tests/tests.js
index 6fd5bf3..7d56214 100644
--- a/tests/tests.js
+++ b/tests/tests.js
@@ -134,6 +134,66 @@ exports.defineAutoTests = function () {
expect(typeof h.timestamp == 'number').toBe(true);
});
});
+
+ describe("Compass watch heading", function() {
+ it("compass.spec.10 watchCurrentHeading called with a Heading object", function (done) {
+ if (!isCompassAvailable) {
+ pending();
+ }
+
+ var calledOnce = false;
+
+ var watchId = navigator.compass.watchHeading(
+ function (a){
+ expect(a instanceof CompassHeading).toBe(true);
+ expect(a.magneticHeading).toBeDefined();
+ expect(typeof a.magneticHeading == 'number').toBe(true);
+ expect(a.trueHeading).not.toBe(undefined);
+ expect(typeof a.trueHeading == 'number' || a.trueHeading === null).toBe(true);
+ expect(a.headingAccuracy).not.toBe(undefined);
+ expect(typeof a.headingAccuracy == 'number' || a.headingAccuracy === null).toBe(true);
+ expect(typeof a.timestamp == 'number').toBe(true);
+
+ if (calledOnce) {
+ navigator.compass.clearWatch(watchId);
+ done();
+ }
+
+ calledOnce = true;
+ },
+ function (compassError){},
+ { frequency: 50 }
+ );
+ });
+
+ it("compass.spec.11 the watch success callback should not be called once the watch is cleared", function (done) {
+ if (!isCompassAvailable) {
+ pending();
+ }
+
+ var calledOnce = false;
+ var watchCleared = false;
+
+ var watchId = navigator.compass.watchHeading(
+ function (a){
+ // Don't invoke this function if we have cleared the watch
+ expect(watchCleared).toBe(false);
+
+ if (calledOnce) {
+ navigator.compass.clearWatch(watchId);
+ watchCleared = true;
+ setInterval(function(){
+ done();
+ }, 100);
+ }
+
+ calledOnce = true;
+ },
+ function (compassError){},
+ { frequency: 50 }
+ );
+ });
+ });
});
};
@@ -157,6 +217,19 @@ exports.defineManualTests = function (contentEl, createActionButton) {
document.getElementById('compass_status').innerHTML = status;
}
+ // Success callback for both watchHeading and getCurrentHeading
+ function success(a) {
+ var magneticHeading = document.getElementById('magneticHeading');
+ var trueHeading = document.getElementById("trueHeading");
+ var headingAccuracy = document.getElementById("headingAccuracy");
+ var timestamp = document.getElementById("timestamp");
+
+ magneticHeading.innerHTML = roundNumber(a.magneticHeading);
+ trueHeading.innerHTML = roundNumber(a.trueHeading);
+ headingAccuracy.innerHTML = a.headingAccuracy;
+ timestamp.innerHTML = a.timestamp;
+ }
+
/**
* Stop watching the acceleration
*/
@@ -174,14 +247,9 @@ exports.defineManualTests = function (contentEl, createActionButton) {
var watchCompass = function () {
console.log("watchCompass()");
- // Success callback
- var success = function (a) {
- document.getElementById('compassHeading').innerHTML = roundNumber(a.magneticHeading);
- };
-
// Fail callback
var fail = function (e) {
- console.log("watchCompass fail callback with error code " + e);
+ console.log("watchCompass fail callback with error: " + JSON.stringify(e));
stopCompass();
setCompassStatus(e);
};
@@ -206,14 +274,9 @@ exports.defineManualTests = function (contentEl, createActionButton) {
// Stop compass if running
stopCompass();
- // Success callback
- var success = function (a) {
- document.getElementById('compassHeading').innerHTML = roundNumber(a.magneticHeading);
- };
-
// Fail callback
var fail = function (e) {
- console.log("getCompass fail callback with error code " + e.toString);
+ console.log("getCompass fail callback with error: " + JSON.stringify(e));
setCompassStatus(e);
};
@@ -234,9 +297,12 @@ exports.defineManualTests = function (contentEl, createActionButton) {
contentEl.innerHTML = '<div id="info"><b>Status: </b>' +
'<span id="compass_status">Stopped</span>' +
- '<table width="100%"><tr>' +
- '<td width="33%">Heading: <span id="compassHeading"></span>' +
- '</td></tr></table></div>' +
+ '<table width="100%">' +
+ '<tr><td width="33%">Magnetic heading: <span id="magneticHeading"></span></td></tr>' +
+ '<tr><td width="33%">True heading: <span id="trueHeading"></span></td></tr>' +
+ '<tr><td width="33%">Heading accuracy: <span id="headingAccuracy"></span></td></tr>' +
+ '<tr><td width="33%">Timestamp: <span id="timestamp"></span></td></tr>' +
+ '</table></div>' +
orientation_tests;
createActionButton('Get Compass', function () {
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org