Skip to content

Commit

Permalink
changed over CompassConstants -> CompassError, added a proper Compass…
Browse files Browse the repository at this point in the history
…Error obj, tweaking CompassHeading constructor, added fail wrappers to compass, set a default quality level for camera.getPicture.
  • Loading branch information
filmaj committed Mar 3, 2012
1 parent acef6ab commit d156df9
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 31 deletions.
9 changes: 1 addition & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,26 +212,19 @@ Use the cordova.proto platform in ripple.
However, Compass requires that JS initiates a `start`. This is dumb.
- Media (and other plugin) implementations across platforms need to use the established
cordova/exec callback method (instead of triggering globally-accessible functions to
dispatch listeners). On iOS and Android, grep for "cast" in the native
dispatch listeners). On iOS, grep for "cast" in the native
code - you'll see a bunch of invoked JavaScript from native, which
shouldn't be there.
- Media needs updates across all platforms. Methods need fixing with
respect to timing: some methods use milliseconds, some use seconds.
Some methods not documented (setVolume on Android). Consolidate /
implement properly across platforms.
- Storage shim on Android needs to change its win/fail callbacks to
`require('cordova/plugin/android/storage').failQuery / completeQuery`
(away from droiddb.fail / completeQuery)
- Normalize `Entry.toURL` return values. iOS returns `"file://localhost" +
fullPath`, Android returns `"file://" + fullPath`, BlackBerry returns just `fullPath`
- APIs that are not cross-platform - what
to do with these?
- Crypto on Android
- SMS, telephony, splashscreen on iOS
- Need to normalize native return values as much as possible across
platforms. For example, error objects. Should we return JSON objects
from native or minimal primitives (i.e. error codes as numbers)? Both
are in use today, we need to decide on a standard.
- Once-over all of the cordova-docs with the APIs defined in here to
make sure all is consistent. There were function signature tweaks,
undocumented procedures, etc.
Expand Down
2 changes: 1 addition & 1 deletion lib/platform/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ module.exports = {
path: 'cordova/plugin/CompassHeading'
},
CompassError:{
path: 'cordova/plugin/CompassConstants'
path: 'cordova/plugin/CompassError'
},
ConfigurationData: {
path: 'cordova/plugin/ConfigurationData'
Expand Down
4 changes: 3 additions & 1 deletion lib/plugin/Camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ cameraExport.getPicture = function(successCallback, errorCallback, options) {
return;
}


var quality = 50;
if (options && typeof options.quality == "number") {
quality = options.quality;
} else if (options && typeof options.quality == "string") {
Expand Down Expand Up @@ -75,6 +75,8 @@ cameraExport.getPicture = function(successCallback, errorCallback, options) {
if (typeof options.encodingType == "number") {
encodingType = options.encodingType;
}
// TODO: parse MediaType
// TODO: enable allow edit?

exec(successCallback, errorCallback, "Camera", "takePicture", [quality, destinationType, sourceType, targetWidth, targetHeight, encodingType]);
}
Expand Down
4 changes: 0 additions & 4 deletions lib/plugin/CompassConstants.js

This file was deleted.

17 changes: 17 additions & 0 deletions lib/plugin/CompassError.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* CompassError.
* An error code assigned by an implementation when an error has occured
* @constructor
*/
var CompassError = function(err) {
this.code = (typeof err != 'undefined' ? err : null);
};

/**
* Error codes
*/
CompassError.COMPASS_INTERNAL_ERR = 0;
CompassError.COMPASS_NOT_SUPPORTED = 20;

module.exports = CompassError;

10 changes: 5 additions & 5 deletions lib/plugin/CompassHeading.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
var CompassHeading = function() {
this.magneticHeading = null;
this.trueHeading = null;
this.headingAccuracy = null;
this.timestamp = new Date();
var CompassHeading = function(magneticHeading, trueHeading, headingAccuracy, timestamp) {
this.magneticHeading = magneticHeading || null;
this.trueHeading = trueHeading || null;
this.headingAccuracy = headingAccuracy || null;
this.timestamp = (timestamp ? new Date(timestamp) : new Date());
};

module.exports = CompassHeading;
30 changes: 18 additions & 12 deletions lib/plugin/compass.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
var exec = require('cordova/exec'),
utils = require('cordova/utils'),
CompassHeading = require('cordova/plugin/CompassHeading'),
CompassError = require('cordova/plugin/CompassError'),
timers = {},
compass = {
/**
Expand All @@ -24,15 +26,16 @@ var exec = require('cordova/exec'),
}

var win = function(result) {
if (result.timestamp) {
var timestamp = new Date(result.timestamp);
result.timestamp = timestamp;
}
successCallback(result);
var ch = new CompassHeading(result.magneticHeading, result.trueHeading, result.headingAccuracy, result.timestamp);
successCallback(ch);
};
var fail = function(code) {
var ce = new CompassError(code);
errorCallback(ce);
}

// Get heading
exec(win, errorCallback, "Compass", "getHeading", []);
exec(win, fail, "Compass", "getHeading", []);
},

/**
Expand Down Expand Up @@ -63,14 +66,16 @@ var exec = require('cordova/exec'),
// Start watch timer to get headings
var id = utils.createUUID();
var win = function(result) {
if (result.timestamp) {
var timestamp = new Date(result.timestamp);
result.timestamp = timestamp;
}
successCallback(result);
var ch = new CompassHeading(result.magneticHeading, result.trueHeading, result.headingAccuracy, result.timestamp);
successCallback(ch);
};
var fail = function(code) {
var ce = new CompassError(code);
errorCallback(ce);
};

timers[id] = window.setInterval(function() {
exec(win, errorCallback, "Compass", "getHeading", []);
exec(win, fail, "Compass", "getHeading", []);
}, frequency);

return id;
Expand All @@ -87,6 +92,7 @@ var exec = require('cordova/exec'),
delete timers[id];
}
}
// TODO: add the filter-based iOS-only methods
};

module.exports = compass;

0 comments on commit d156df9

Please sign in to comment.