GarminDeviceControl.js
Summary
Garmin.DeviceControl A high-level JavaScript API which supports listener and callback functionality.
Version: 1.0
Author: Diana Chow diana.chow[at]garmin.com, Carlo Latasa carlo.latasa@garmin.com
|
Class Summary
|
| Garmin.DeviceControl |
Garmin.DeviceControl
The controller must be unlocked before anything can be done with it. |
if (Garmin == undefined) var Garmin = {};
Garmin.DeviceControl = function(){};
Garmin.DeviceControl = Class.create();
Garmin.DeviceControl.prototype = {
initialize: function() {
this.pluginUnlocked = false;
try {
if (typeof(Garmin.DevicePlugin) == 'undefined') throw '';
} catch(e) {
throw new Error(Garmin.DeviceControl.MESSAGES.deviceControlMissing);
};
if(!BrowserSupport.isBrowserSupported()) {
var notSupported = new Error(Garmin.DeviceControl.MESSAGES.browserNotSupported);
notSupported.name = "BrowserNotSupportedException";
throw notSupported;
}
if (!PluginDetect.detectGarminCommunicatorPlugin()) {
var notInstalled = new Error(Garmin.DeviceControl.MESSAGES.pluginNotInstalled);
notInstalled.name = "PluginNotInstalledException";
throw notInstalled;
}
var pluginElement;
if( window.ActiveXObject ) {
pluginElement = $("GarminActiveXControl");
} else {
pluginElement = $("GarminNetscapePlugin");
}
if (pluginElement == null) {
var error = new Error(Garmin.DeviceControl.MESSAGES.missingPluginTag);
error.name = "HtmlTagNotFoundException";
throw error;
}
this.garminPlugin = new Garmin.DevicePlugin(pluginElement);
this.validatePlugin();
this._broadcaster = new Garmin.Broadcaster();
this.getDetailedDeviceData = true;
this.devices = new Array();
this.deviceNumber = null;
this.numDevices = 0;
this.gpsData = null;
this.gpsDataType = null;
this.gpsDataString = "";
this.gpsDataStringCompressed = "";
},
validatePlugin: function() {
if (!this.isPluginInstalled()) {
var notInstalled = new Error(Garmin.DeviceControl.MESSAGES.pluginNotInstalled);
notInstalled.name = "PluginNotInstalledException";
throw notInstalled;
}
if(this.garminPlugin.isPluginOutOfDate()) {
var outOfDate = new Error(Garmin.DeviceControl.MESSAGES.outOfDatePlugin1+Garmin.DevicePlugin.REQUIRED_VERSION.toString()+Garmin.DeviceControl.MESSAGES.outOfDatePlugin2+this.getPluginVersionString());
outOfDate.name = "OutOfDatePluginException";
outOfDate.version = this.getPluginVersionString();
throw outOfDate;
}
},
checkForUpdates: function() {
if(this.garminPlugin.isUpdateAvailable()) {
var notLatest = new Error(Garmin.DeviceControl.MESSAGES.updatePlugin1+Garmin.DevicePlugin.LATEST_VERSION.toString()+Garmin.DeviceControl.MESSAGES.updatePlugin2+this.getPluginVersionString());
notLatest.name = "UpdatePluginException";
notLatest.version = this.getPluginVersionString();
throw notLatest;
}
},
findDevices: function() {
if (!this.isUnlocked())
throw new Error(Garmin.DeviceControl.MESSAGES.pluginNotUnlocked);
this.garminPlugin.startFindDevices();
this._broadcaster.dispatch("onStartFindDevices", {controller: this});
setTimeout(function() { this._finishFindDevices() }.bind(this), 1000);
},
cancelFindDevices: function() {
this.garminPlugin.cancelFindDevices();
this._broadcaster.dispatch("onCancelFindDevices", {controller: this});
},
_finishFindDevices: function() {
if(this.garminPlugin.finishFindDevices()) {
this.devices = Garmin.PluginUtils.parseDeviceXml(this.garminPlugin, this.getDetailedDeviceData);
this.numDevices = this.devices.length;
this.deviceNumber = 0;
this._broadcaster.dispatch("onFinishFindDevices", {controller: this});
} else {
setTimeout(function() { this._finishFindDevices() }.bind(this), 500);
}
},
setDeviceNumber: function(deviceNumber) {
this.deviceNumber = deviceNumber;
},
getDevices: function() {
return this.devices;
},
getCurrentDeviceXml: function() {
return this.garminPlugin.getDeviceDescriptionXml(this.deviceNumber);
},
readDataFromDevice: function(fileType) {
if (!this.isUnlocked())
throw new Error(Garmin.DeviceControl.MESSAGES.pluginNotUnlocked);
if (this.numDevices == 0)
throw new Error(Garmin.DeviceControl.MESSAGES.noDevicesConnected);
if ( ! this._isAMember(fileType, [Garmin.DeviceControl.FILE_TYPES.gpx, Garmin.DeviceControl.FILE_TYPES.tcx, Garmin.DeviceControl.FILE_TYPES.crs,
Garmin.DeviceControl.FILE_TYPES.tcxDir, Garmin.DeviceControl.FILE_TYPES.crsDir, Garmin.DeviceControl.FILE_TYPES.wkt, Garmin.DeviceControl.FILE_TYPES.tcxProfile])) {
var error = new Error(Garmin.DeviceControl.MESSAGES.invalidFileType + fileType);
error.name = "InvalidTypeException";
throw error;
}
this.gpsDataType = fileType;
this.gpsData = null;
this.gpsDataString = null;
this.idle = false;
try {
this._broadcaster.dispatch("onStartReadFromDevice", {controller: this});
switch(this.gpsDataType) {
case Garmin.DeviceControl.FILE_TYPES.gpx:
this.garminPlugin.startReadFromGps( this.deviceNumber );
break;
case Garmin.DeviceControl.FILE_TYPES.tcx:
case Garmin.DeviceControl.FILE_TYPES.crs:
case Garmin.DeviceControl.FILE_TYPES.wkt:
case Garmin.DeviceControl.FILE_TYPES.tcxProfile:
this.garminPlugin.startReadFitnessData( this.deviceNumber, this.gpsDataType );
break;
case Garmin.DeviceControl.FILE_TYPES.tcxDir:
this.garminPlugin.startReadFitnessDirectory(this.deviceNumber, Garmin.DeviceControl.FILE_TYPES.tcx);
break;
case Garmin.DeviceControl.FILE_TYPES.crsDir:
this.garminPlugin.startReadFitnessDirectory(this.deviceNumber, Garmin.DeviceControl.FILE_TYPES.crs);
break;
case Garmin.DeviceControl.FILE_TYPES.deviceXml:
this.gpsDataString = this.getCurrentDeviceXml();
break;
}
this._progressRead();
} catch(e) {
this._reportException(e);
}
},
readDetailFromDevice: function(fileType, dataId) {
if (!this.isUnlocked())
throw new Error(Garmin.DeviceControl.MESSAGES.pluginNotUnlocked);
if (this.numDevices == 0)
throw new Error(Garmin.DeviceControl.MESSAGES.noDevicesConnected);
if ( ! this._isAMember(fileType, [Garmin.DeviceControl.FILE_TYPES.tcxDetail, Garmin.DeviceControl.FILE_TYPES.crsDetail])) {
var error = new Error(Garmin.DeviceControl.MESSAGES.invalidFileType + fileType);
error.name = "InvalidTypeException";
throw error;
}
this.gpsDataType = fileType;
this.gpsData = null;
this.gpsDataString = null;
this.idle = false;
try {
this._broadcaster.dispatch("onStartReadFromDevice", {controller: this});
switch(this.gpsDataType) {
case Garmin.DeviceControl.FILE_TYPES.tcxDetail:
this.garminPlugin.startReadFitnessDetail(this.deviceNumber, Garmin.DeviceControl.FILE_TYPES.tcx, dataId);
break;
case Garmin.DeviceControl.FILE_TYPES.crsDetail:
this.garminPlugin.startReadFitnessDetail(this.deviceNumber, Garmin.DeviceControl.FILE_TYPES.crs, dataId);
break;
}
this._progressRead();
} catch(e) {
this._reportException(e);
}
},
readFromDevice: function() {
this.readDataFromDevice(Garmin.DeviceControl.FILE_TYPES.gpx);
},
readHistoryDetailFromFitnessDevice: function(historyId) {
this.readDetailFromDevice(Garmin.DeviceControl.FILE_TYPES.tcx, historyId)
},
readCourseDetailFromFitnessDevice: function(courseId){
this.readDetailFromDevice(Garmin.DeviceControl.FILE_TYPES.crs, courseId)
},
readHistoryFromFitnessDevice: function() {
this.readDataFromDevice(Garmin.DeviceControl.FILE_TYPES.tcx);
},
readCoursesFromFitnessDevice: function() {
this.readDataFromDevice(Garmin.DeviceControl.FILE_TYPES.crs);
},
readWorkoutsFromFitnessDevice: function() {
this.readDataFromDevice(Garmin.DeviceControl.FILE_TYPES.wkt);
},
readUserProfileFromFitnessDevice: function() {
this.readDataFromDevice(Garmin.DeviceControl.FILE_TYPES.tcxProfile);
},
getGpsData: function() {
if (!this.isUnlocked())
throw new Error(Garmin.DeviceControl.MESSAGES.pluginNotUnlocked);
if (this.numDevices == 0)
throw new Error(Garmin.DeviceControl.MESSAGES.noDevicesConnected);
if( getReadCompletionState != Garmin.DeviceControl.FINISH_STATES.finished ) {
throw new Error(Garmin.DeviceControl.MESSAGES.incompleteRead);
}
return this.gpsData;
},
getGpsDataString: function() {
if (!this.isUnlocked())
throw new Error(Garmin.DeviceControl.MESSAGES.pluginNotUnlocked);
if (this.numDevices == 0)
throw new Error(Garmin.DeviceControl.MESSAGES.noDevicesConnected);
if( getReadCompletionState != Garmin.DeviceControl.FINISH_STATES.finished ) {
throw new Error(Garmin.DeviceControl.MESSAGES.incompleteRead);
}
return this.gpsDataString;
},
getCompressedFitnessData: function() {
if (!this.isUnlocked())
throw new Error(Garmin.DeviceControl.MESSAGES.pluginNotUnlocked);
if (this.numDevices == 0)
throw new Error(Garmin.DeviceControl.MESSAGES.noDevicesConnected);
if( getReadCompletionState != Garmin.DeviceControl.FINISH_STATES.finished ) {
throw new Error(Garmin.DeviceControl.MESSAGES.incompleteRead);
}
try{
this.garminPlugin.getTcdXmlz();
}
catch( aException ) {
this._reportException( aException );
}
},
getReadCompletionState: function() {
switch(this.gpsDataType) {
case Garmin.DeviceControl.FILE_TYPES.gpx:
return this.garminPlugin.finishReadFromGps();
case Garmin.DeviceControl.FILE_TYPES.tcx:
case Garmin.DeviceControl.FILE_TYPES.crs:
case Garmin.DeviceControl.FILE_TYPES.wkt:
case Garmin.DeviceControl.FILE_TYPES.tcxProfile:
return this.garminPlugin.finishReadFitnessData();
case Garmin.DeviceControl.FILE_TYPES.tcxDir:
case Garmin.DeviceControl.FILE_TYPES.crsDir:
return this.garminPlugin.finishReadFitnessDirectory();
case Garmin.DeviceControl.FILE_TYPES.tcxDetail:
case Garmin.DeviceControl.FILE_TYPES.crsDetail:
return this.garminPlugin.finishReadFitnessDetail();
}
},
_progressRead: function() {
this._broadcaster.dispatch("onProgressReadFromDevice", {progress: this.getDeviceStatus(), controller: this});
setTimeout(function() { this._finishReadFromDevice() }.bind(this), 200);
},
_finishReadFromDevice: function() {
var completionState = this.getReadCompletionState();
try {
if( completionState == Garmin.DeviceControl.FINISH_STATES.finished ) {
switch( this.gpsDataType ) {
case Garmin.DeviceControl.FILE_TYPES.gpx:
if (this.garminPlugin.gpsTransferSucceeded()) {
this.gpsDataString = this.garminPlugin.getGpsXml();
this.gpsData = Garmin.XmlConverter.toDocument(this.gpsDataString);
this._broadcaster.dispatch("onFinishReadFromDevice", {success: this.garminPlugin.gpsTransferSucceeded(), controller: this});
}
break;
case Garmin.DeviceControl.FILE_TYPES.tcx:
case Garmin.DeviceControl.FILE_TYPES.crs:
case Garmin.DeviceControl.FILE_TYPES.tcxDir:
case Garmin.DeviceControl.FILE_TYPES.crsDir:
case Garmin.DeviceControl.FILE_TYPES.tcxDetail:
case Garmin.DeviceControl.FILE_TYPES.crsDetail:
case Garmin.DeviceControl.FILE_TYPES.wkt:
case Garmin.DeviceControl.FILE_TYPES.tcxProfile:
if (this.garminPlugin.fitnessTransferSucceeded()) {
this.gpsDataString = this.garminPlugin.getTcdXml();
this.gpsDataStringCompressed = this.garminPlugin.getTcdXmlz();
this.gpsData = Garmin.XmlConverter.toDocument(this.gpsDataString);
this._broadcaster.dispatch("onFinishReadFromDevice", {success: this.garminPlugin.fitnessTransferSucceeded(), controller: this});
}
break;
}
} else if( completionState == Garmin.DeviceControl.FINISH_STATES.messageWaiting ) {
var msg = this._messageWaiting();
this._broadcaster.dispatch("onWaitingReadFromDevice", {message: msg, controller: this});
} else {
this._progressRead();
}
} catch( aException ) {
this._reportException( aException );
}
},
cancelReadFromDevice: function() {
if (this.gpsDataType == Garmin.DeviceControl.FILE_TYPES.gpx) {
this.garminPlugin.cancelReadFromGps();
} else {
this.garminPlugin.cancelReadFitnessData();
}
this._broadcaster.dispatch("onCancelReadFromDevice", {controller: this});
},
writeAddressToDevice: function(address) {
if (!this.isUnlocked())
throw new Error(Garmin.DeviceControl.MESSAGES.pluginNotUnlocked);
if (!this.geocoder) {
this.geocoder = new Garmin.Geocode();
this.geocoder.register(this);
}
this.geocoder.findLatLng(address);
},
onException: function(json) {
this._reportException(json.msg);
},
onFinishedFindLatLon: function(json) {
json.fileName = "address.gpx";
json.controller = this;
this._broadcaster.dispatch("onFinishedFindLatLon", json);
var factory = new Garmin.GpsDataFactory();
var gpxStr = factory.produceGpxString(null, [json.waypoint]);
this.writeToDevice(gpxStr, json.fileName);
},
writeToDevice: function(gpxString, fileName) {
if (!this.isUnlocked())
throw new Error(Garmin.DeviceControl.MESSAGES.pluginNotUnlocked);
if(this.numDevices == 0)
throw new Error(Garmin.DeviceControl.MESSAGES.noDevicesConnected);
this.gpsDataType = Garmin.DeviceControl.FILE_TYPES.gpx;
try {
this._broadcaster.dispatch("onStartWriteToDevice", {controller: this});
this.garminPlugin.startWriteToGps(gpxString, fileName, this.deviceNumber);
this._progressWrite();
} catch(e) {
this._reportException(e);
}
},
downloadToDevice: function(xmlDownloadDescription, filename) {
if (!this.isUnlocked())
throw new Error(Garmin.DeviceControl.MESSAGES.pluginNotUnlocked);
if(this.numDevices == 0)
throw new Error(Garmin.DeviceControl.MESSAGES.noDevicesConnected);
this.gpsDataType = Garmin.DeviceControl.FILE_TYPES.binary;
try {
this.garminPlugin.startDownloadData(xmlDownloadDescription, filename, this.deviceNumber );
this._progressWrite();
} catch(e) {
this._reportException(e);
}
},
writeFitnessToDevice: function(tcxString, fileName) {
if (!this.isUnlocked())
throw new Error(Garmin.DeviceControl.MESSAGES.pluginNotUnlocked);
if(this.numDevices == 0)
throw new Error(Garmin.DeviceControl.MESSAGES.noDevicesConnected);
this.gpsDataType = Garmin.DeviceControl.FILE_TYPES.crs;
try {
this._broadcaster.dispatch("onStartWriteToDevice", {controller: this});
this.garminPlugin.startWriteFitnessData(tcxString, this.deviceNumber, fileName, this.gpsDataType);
this._progressWrite();
} catch(e) {
this._reportException(e);
}
},
writeWorkoutsToFitnessDevice: function(tcxString, fileName) {
if (!this.isUnlocked())
throw new Error(Garmin.DeviceControl.MESSAGES.pluginNotUnlocked);
if(this.numDevices == 0)
throw new Error(Garmin.DeviceControl.MESSAGES.noDevicesConnected);
this.gpsDataType = Garmin.DeviceControl.FILE_TYPES.wkt;
try {
this._broadcaster.dispatch("onStartWriteToDevice", {controller: this});
this.garminPlugin.startWriteFitnessData(tcxString, this.deviceNumber, fileName, this.gpsDataType);
this._progressWrite();
} catch(e) {
this._reportException(e);
}
},
writeUserProfileToFitnessDevice: function(tcxString, fileName) {
if (!this.isUnlocked())
throw new Error(Garmin.DeviceControl.MESSAGES.pluginNotUnlocked);
if(this.numDevices == 0)
throw new Error(Garmin.DeviceControl.MESSAGES.noDevicesConnected);
this.gpsDataType = Garmin.DeviceControl.FILE_TYPES.tcxProfile;
try {
this._broadcaster.dispatch("onStartWriteToDevice", {controller: this});
this.garminPlugin.startWriteFitnessData(tcxString, this.deviceNumber, fileName, this.gpsDataType);
this._progressWrite();
} catch(e) {
this._reportException(e);
}
},
_progressWrite: function() {
this._broadcaster.dispatch("onProgressWriteToDevice", {progress: this.getDeviceStatus(), controller: this});
setTimeout(function() { this._finishWriteToDevice() }.bind(this), 200);
},
_finishWriteToDevice: function() {
try {
var completionState;
var success;
switch( this.gpsDataType ) {
case Garmin.DeviceControl.FILE_TYPES.gpx :
completionState = this.garminPlugin.finishWriteToGps();
success = this.garminPlugin.gpsTransferSucceeded();
break;
case Garmin.DeviceControl.FILE_TYPES.crs :
case Garmin.DeviceControl.FILE_TYPES.wkt :
case Garmin.DeviceControl.FILE_TYPES.tcxProfile :
completionState = this.garminPlugin.finishWriteFitnessData();
success = this.garminPlugin.fitnessTransferSucceeded();
break;
case Garmin.DeviceControl.FILE_TYPES.gpi :
completionState = this.garminPlugin.finishDownloadData();
success = this.garminPlugin.downloadDataSucceeded();
break;
}
if( completionState == Garmin.DeviceControl.FINISH_STATES.finished ) {
this._broadcaster.dispatch("onFinishWriteToDevice", {success: success, controller: this});
} else if( completionState == Garmin.DeviceControl.FINISH_STATES.messageWaiting ) {
var msg = this._messageWaiting();
this._broadcaster.dispatch("onWaitingWriteToDevice", {message: msg, controller: this});
} else {
this._progressWrite();
}
} catch( aException ) {
this._reportException( aException );
}
},
cancelWriteToDevice: function() {
var isGPX = (Garmin.DeviceControl.FILE_TYPES.gpx == this.gpsDataType);
if (isGPX) {
this.garminPlugin.cancelWriteToGps();
} else {
this.garminPlugin.cancelDownloadData();
}
this._broadcaster.dispatch("onCancelWriteToDevice", {controller: this});
},
unlock: function(pathKeyPairsArray) {
this.pluginUnlocked = this.garminPlugin.unlock(pathKeyPairsArray);
return this.pluginUnlocked;
},
register: function(listener) {
this._broadcaster.register(listener);
},
isUnlocked: function() {
return this.pluginUnlocked;
},
respondToMessageBox: function(response) {
this.garminPlugin.respondToMessageBox(response ? 1 : 2);
this._progressWrite();
},
_messageWaiting: function() {
var messageDoc = Garmin.XmlConverter.toDocument(this.garminPlugin.getMessageBoxXml());
var text = messageDoc.getElementsByTagName("Text")[0].childNodes[0].nodeValue;
var message = new Garmin.MessageBox("Question",text);
var buttonNodes = messageDoc.getElementsByTagName("Button");
for(var i=0; i<buttonNodes.length; i++) {
var caption = buttonNodes[i].getAttribute("Caption");
var value = buttonNodes[i].getAttribute("Value");
message.addButton(caption, value);
}
return message;
},
getDeviceStatus: function() {
var aProgressXml = this.garminPlugin.getProgressXml();
var theProgressDoc = Garmin.XmlConverter.toDocument(aProgressXml);
var title = "";
if(theProgressDoc.getElementsByTagName("Title").length > 0) {
title = theProgressDoc.getElementsByTagName("Title")[0].childNodes[0].nodeValue;
}
var progress = new Garmin.TransferProgress(title);
var textNodes = theProgressDoc.getElementsByTagName("Text");
for( var i=0; i < textNodes.length; i++ ) {
if(textNodes[i].childNodes.length > 0) {
var text = textNodes[i].childNodes[0].nodeValue;
if(text != "") progress.addText(text);
}
}
var percentageNode = theProgressDoc.getElementsByTagName("ProgressBar")[0];
if(percentageNode != undefined) {
if(percentageNode.getAttribute("Type") == "Percentage") {
progress.setPercentage(percentageNode.getAttribute("Value"));
} else if (percentageNode.getAttribute("Type") == "Indefinite") {
progress.setPercentage(100);
}
}
return progress;
},
_isAMember: function(element, array) {
return array.any( function(str){ return str==element; } );
},
getPluginVersion: function() {
return this.garminPlugin.getPluginVersion();
},
getPluginVersionString: function() {
return this.garminPlugin.getPluginVersionString();
},
setPluginRequiredVersion: function(reqVersionArray) {
if( reqVersionArray != null ) {
this.garminPlugin.setPluginRequiredVersion(reqVersionArray);
}
},
isPluginInitialized: function() {
return (this.garminPlugin != null);
},
isPluginInstalled: function() {
return (this.garminPlugin.getVersionXml() != undefined);
},
_reportException: function(exception) {
this._broadcaster.dispatch("onException", {msg: exception, controller: this});
},
getDevicesCount: function() {
return this.numDevices;
},
_getDeviceByNumber: function(deviceNum) {
for( var index in this.devices) {
if( this.devices[index].getNumber() == deviceNum)
return this.devices[index];
}
},
toString: function() {
return "Garmin Javascript GPS Controller managing " + this.numDevices + " device(s)";
}
};
var BrowserSupport = {
isBrowserSupported: function() {
return ( (BrowserDetect.OS == "Windows" && (BrowserDetect.browser == "Firefox" || BrowserDetect.browser == "Mozilla" || BrowserDetect.browser == "Explorer"))
|| (BrowserDetect.OS == "Mac" && (BrowserDetect.browser == "Firefox" || BrowserDetect.browser == "Safari")) );
}
};
Garmin.DeviceControl.MESSAGES = {
deviceControlMissing: "Garmin.DeviceControl depends on the Garmin.DevicePlugin framework.",
missingPluginTag: "Plug-In HTML tag not found.",
browserNotSupported: "Your browser is not supported to use the Garmin Communicator Plug-In.",
pluginNotInstalled: "Garmin Communicator Plugin NOT detected.",
outOfDatePlugin1: "Your version of the Garmin Communicator Plug-In is out of date, required: ",
outOfDatePlugin2: ", current: ",
updatePlugin1: "Your version of the Garmin Communicator Plug-In is not the latest version. Latest version: ",
updatePlugin2: ", current: ",
pluginNotUnlocked: "Garmin Plugin has not been unlocked",
noDevicesConnected: "No device connected, can't communicate with device.",
invalidFileType: "Cannot process the device file type: ",
incompleteRead: "Incomplete read, cannot get compressed format.",
unsupportedDataType: "Type of data being transferred is unsupported by your device or plugin version."
};
Garmin.DeviceControl.FINISH_STATES = {
idle: 0,
working: 1,
messageWaiting: 2,
finished: 3
};
Garmin.DeviceControl.FILE_TYPES = {
gpx: "GPSData",
tcx: "FitnessHistory",
gpi: "gpi",
crs: "FitnessCourses",
wkt: "FitnessWorkouts",
tcxProfile: "FitnessUserProfile",
binary: "BinaryData",
tcxDir: "FitnessHistoryDirectory",
crsDir: "FitnessCoursesDirectory",
tcxDetail: "FitnessHistoryDetail",
crsDetail: "FitnessCoursesDetail",
deviceXml: "DeviceXml"
};
Garmin.DeviceControl.TRANSFER_DIRECTIONS = {
read: "OutputFromUnit",
write: "InputToUnit",
both: "InputOutput"
};
Garmin.TransferProgress = Class.create();
Garmin.TransferProgress.prototype = {
initialize: function(title) {
this.title = title;
this.text = new Array();
this.percentage = null;
},
addText: function(textString) {
this.text.push(textString);
},
getText: function() {
return this.text;
},
getTitle: function() {
return this.title;
},
setPercentage: function(percentage) {
this.percentage = percentage;
},
getPercentage: function() {
return this.percentage;
},
toString: function() {
var progressString = "";
if(this.getTitle() != null) {
progressString += this.getTitle();
}
if(this.getPercentage() != null) {
progressString += ": " + this.getPercentage() + "%";
}
return progressString;
}
};
Garmin.MessageBox = Class.create();
Garmin.MessageBox.prototype = {
initialize: function(type, text) {
this.type = type;
this.text = text;
this.buttons = new Array();
},
getType: function() {
return this.type;
},
getText: function() {
return this.text;
},
addButton: function(caption, value) {
this.buttons.push({caption: caption, value: value});
},
getButtons: function() {
return this.buttons;
},
getButtonValue: function(caption) {
for(var i=0; i< this.buttons.length; i++) {
if(this.buttons[i].caption == caption) {
return this.buttons[i].value;
}
}
return null;
},
toString: function() {
return this.getText();
}
};
Documentation generated by
JSDoc on Wed Feb 27 11:54:53 2008