Merge pull request #127 from DanielTizon/master

works with PhoneGap 1.0.0 - recoded to bring it in line with other plugins
This commit is contained in:
macdonst
2011-09-01 10:09:34 -07:00
2 changed files with 205 additions and 204 deletions

View File

@@ -1,129 +1,130 @@
/* Copyright (c) 2011 - Andago
*
* author: Daniel Tizón
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
*
* author: Daniel Tizón
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
var Bluetooth = {
var Bluetooth = function() {
};
/**
* @param argument Argument that we are going to pass to the plugin - for this method no arguments are needed
* @param successCallback The callback which will be called when listDevices is successful
* @param failureCallback The callback which will be called when listDevices encouters an error
*/
listDevices : function(argument,successCallback, failureCallback) {
return PhoneGap.exec(successCallback, failureCallback, 'BluetoothPlugin', 'listDevices', [argument]);
},
/**
* @param argument Argument that we are going to pass to the plugin - for this method no arguments are needed
* @param successCallback The callback which will be called when listDevices is successful
* @param failureCallback The callback which will be called when listDevices encouters an error
*/
isBTEnabled : function(argument,successCallback, failureCallback) {
return PhoneGap.exec(successCallback, failureCallback, 'BluetoothPlugin', 'isBTEnabled', [argument]);
},
* @param argument Argument that we are going to pass to the plugin - for this method no arguments are needed
* @param successCallback The callback which will be called when listDevices is successful
* @param failureCallback The callback which will be called when listDevices encouters an error
*/
Bluetooth.prototype.listDevices = function(argument,successCallback, failureCallback) {
return PhoneGap.exec(successCallback, failureCallback, 'BluetoothPlugin', 'listDevices', [argument]);
};
/**
* @param argument Argument that we are going to pass to the plugin - for this method no arguments are needed
* @param successCallback The callback which will be called when listDevices is successful
* @param failureCallback The callback which will be called when listDevices encouters an error
*/
enableBT : function(argument,successCallback, failureCallback) {
return PhoneGap.exec(successCallback, failureCallback, 'BluetoothPlugin', 'enableBT', [argument]);
},
* @param argument Argument that we are going to pass to the plugin - for this method no arguments are needed
* @param successCallback The callback which will be called when listDevices is successful
* @param failureCallback The callback which will be called when listDevices encouters an error
*/
Bluetooth.prototype.isBTEnabled = function(argument,successCallback, failureCallback) {
return PhoneGap.exec(successCallback, failureCallback, 'BluetoothPlugin', 'isBTEnabled', [argument]);
};
/**
* @param argument Argument that we are going to pass to the plugin - for this method no arguments are needed
* @param successCallback The callback which will be called when listDevices is successful
* @param failureCallback The callback which will be called when listDevices encouters an error
*/
disableBT : function(argument,successCallback, failureCallback) {
* @param argument Argument that we are going to pass to the plugin - for this method no arguments are needed
* @param successCallback The callback which will be called when listDevices is successful
* @param failureCallback The callback which will be called when listDevices encouters an error
*/
Bluetooth.prototype.enableBT = function(argument,successCallback, failureCallback) {
return PhoneGap.exec(successCallback, failureCallback, 'BluetoothPlugin', 'disableBT', [argument]);
},
/**
* @param argument Argument that we are going to pass to the plugin, you need pass the MAC address of the bluetooth device with wich you want to pair
* @param successCallback The callback which will be called when listDevices is successful
* @param failureCallback The callback which will be called when listDevices encouters an error
*/
pairBT : function(argument,successCallback, failureCallback) {
return PhoneGap.exec(successCallback, failureCallback, 'BluetoothPlugin', 'pairBT', [argument]);
},
/**
* @param argument Argument that we are going to pass to the plugin, you need pass the MAC address of the bluetooth device that you want unpair
* @param successCallback The callback which will be called when listDevices is successful
* @param failureCallback The callback which will be called when listDevices encouters an error
*/
unPairBT : function(argument,successCallback, failureCallback) {
return PhoneGap.exec(successCallback, failureCallback, 'BluetoothPlugin', 'unPairBT', [argument]);
},
/**
* @param argument Argument that we are going to pass to the plugin - for this method no arguments are needed
* @param successCallback The callback which will be called when listDevices is successful
* @param failureCallback The callback which will be called when listDevices encouters an error
*/
listBoundDevices : function(argument,successCallback, failureCallback) {
return PhoneGap.exec(successCallback, failureCallback, 'BluetoothPlugin', 'listBoundDevices', [argument]);
},
return PhoneGap.exec(successCallback, failureCallback, 'BluetoothPlugin', 'enableBT', [argument]);
};
/**
* @param argument Argument that we are going to pass to the plugin - for this method no arguments are needed
* @param successCallback The callback which will be called when listDevices is successful
* @param failureCallback The callback which will be called when listDevices encouters an error
*/
stopDiscovering : function(argument,successCallback, failureCallback) {
* @param argument Argument that we are going to pass to the plugin - for this method no arguments are needed
* @param successCallback The callback which will be called when listDevices is successful
* @param failureCallback The callback which will be called when listDevices encouters an error
*/
Bluetooth.prototype.disableBT = function(argument,successCallback, failureCallback) {
return PhoneGap.exec(successCallback, failureCallback, 'BluetoothPlugin', 'stopDiscovering', [argument]);
},
return PhoneGap.exec(successCallback, failureCallback, 'BluetoothPlugin', 'disableBT', [argument]);
};
/**
* @param argument Argument that we are going to pass to the plugin, you need pass the MAC address of the mobile that you want to know if it is bound
* @param successCallback The callback which will be called when listDevices is successful
* @param failureCallback The callback which will be called when listDevices encouters an error
*/
isBound : function(argument,successCallback, failureCallback) {
return PhoneGap.exec(successCallback, failureCallback, 'BluetoothPlugin', 'isBound', [argument]);
}
* @param argument Argument that we are going to pass to the plugin, you need pass the MAC address of the bluetooth device with wich you want to pair
* @param successCallback The callback which will be called when listDevices is successful
* @param failureCallback The callback which will be called when listDevices encouters an error
*/
Bluetooth.prototype.pairBT = function(argument,successCallback, failureCallback) {
return PhoneGap.exec(successCallback, failureCallback, 'BluetoothPlugin', 'pairBT', [argument]);
};
/**
* @param argument Argument that we are going to pass to the plugin, you need pass the MAC address of the bluetooth device that you want unpair
* @param successCallback The callback which will be called when listDevices is successful
* @param failureCallback The callback which will be called when listDevices encouters an error
*/
Bluetooth.prototype.unPairBT = function(argument,successCallback, failureCallback) {
return PhoneGap.exec(successCallback, failureCallback, 'BluetoothPlugin', 'unPairBT', [argument]);
};
/**
* @param argument Argument that we are going to pass to the plugin - for this method no arguments are needed
* @param successCallback The callback which will be called when listDevices is successful
* @param failureCallback The callback which will be called when listDevices encouters an error
*/
Bluetooth.prototype.listBoundDevices = function(argument,successCallback, failureCallback) {
return PhoneGap.exec(successCallback, failureCallback, 'BluetoothPlugin', 'listBoundDevices', [argument]);
};
/**
* @param argument Argument that we are going to pass to the plugin - for this method no arguments are needed
* @param successCallback The callback which will be called when listDevices is successful
* @param failureCallback The callback which will be called when listDevices encouters an error
*/
Bluetooth.prototype.stopDiscovering = function(argument,successCallback, failureCallback) {
return PhoneGap.exec(successCallback, failureCallback, 'BluetoothPlugin', 'stopDiscovering', [argument]);
};
/**
* @param argument Argument that we are going to pass to the plugin, you need pass the MAC address of the mobile that you want to know if it is bound
* @param successCallback The callback which will be called when listDevices is successful
* @param failureCallback The callback which will be called when listDevices encouters an error
*/
Bluetooth.prototype.isBound = function(argument,successCallback, failureCallback) {
return PhoneGap.exec(successCallback, failureCallback, 'BluetoothPlugin', 'isBound', [argument]);
};
PhoneGap.addConstructor(function() {
PhoneGap.addPlugin('Bluetooth', new Bluetooth());
PhoneGap.addPlugin("bluetooth", new Bluetooth());
});

View File

@@ -10,7 +10,7 @@
function onBodyLoad()
{
{
document.addEventListener("deviceready",onDeviceReady,false);
}
@@ -24,64 +24,64 @@ function onDeviceReady()
var btnListDevices = document.getElementById("list-devices");
btnListDevices.onclick = function() {
Bluetooth.listDevices(null,
function(r){printResult(r)},
function(e){log(e)}
);
}
window.plugins.bluetooth.listDevices(null,
function(r){printResult(r)},
function(e){log(e)}
);
}
//------------------------------------------------------ isBTEnabled example ------------------------------------------------------
var btnIsBTEnabled = document.getElementById("isBTEnabled");
btnIsBTEnabled.onclick = function() {
Bluetooth.isBTEnabled(null,
function(r){printResult2(r)},
function(e){log(e)}
);
}
var btnIsBTEnabled = document.getElementById("isBTEnabled");
btnIsBTEnabled.onclick = function() {
window.plugins.bluetooth.isBTEnabled(null,
function(r){printResult2(r)},
function(e){log(e)}
);
}
//------------------------------------------------------ enableBT example ------------------------------------------------------
var btnEnableBT = document.getElementById("enableBT");
btnEnableBT.onclick = function() {
Bluetooth.enableBT(null,
function(r){printResult3(r)},
function(e){log(e)}
);
}
var btnEnableBT = document.getElementById("enableBT");
btnEnableBT.onclick = function() {
window.plugins.bluetooth.enableBT(null,
function(r){printResult3(r)},
function(e){log(e)}
);
}
//------------------------------------------------------ disableBT example ------------------------------------------------------
var btnDisableBT = document.getElementById("disableBT");
btnDisableBT.onclick = function() {
Bluetooth.disableBT(null,
function(r){printResult4(r)},
function(e){log(e)}
);
}
var btnDisableBT = document.getElementById("disableBT");
btnDisableBT.onclick = function() {
window.plugins.bluetooth.disableBT(null,
function(r){printResult4(r)},
function(e){log(e)}
);
}
//------------------------------------------------------ pairBT example ------------------------------------------------------
var btnPairBT = document.getElementById("pairBT");
btnPairBT.onclick = function() {
Bluetooth.pairBT("6C:9B:02:44:FA:BF",
function(r){printResult5(r)},
function(e){log(e)}
);
}
var btnPairBT = document.getElementById("pairBT");
btnPairBT.onclick = function() {
window.plugins.bluetooth.pairBT("6C:9B:02:44:FA:BF",
function(r){printResult5(r)},
function(e){log(e)}
);
}
@@ -89,71 +89,71 @@ function onDeviceReady()
//------------------------------------------------------ unPairBT example ------------------------------------------------------
var btnUnPairBT = document.getElementById("unPairBT");
btnUnPairBT.onclick = function() {
Bluetooth.unPairBT("6C:9B:02:44:FA:BF",
function(r){printResult6(r)},
function(e){log(e)}
);
}
var btnUnPairBT = document.getElementById("unPairBT");
btnUnPairBT.onclick = function() {
window.plugins.bluetooth.unPairBT("6C:9B:02:44:FA:BF",
function(r){printResult6(r)},
function(e){log(e)}
);
}
//------------------------------------------------------ listBoundDevices example ------------------------------------------------------
var btnListBoundDevices = document.getElementById("list-bound-devices");
btnListBoundDevices.onclick = function() {
Bluetooth.listBoundDevices(null,
function(r){printResult7(r)},
function(e){log(e)}
);
}
var btnListBoundDevices = document.getElementById("list-bound-devices");
btnListBoundDevices.onclick = function() {
window.plugins.bluetooth.listBoundDevices(null,
function(r){printResult7(r)},
function(e){log(e)}
);
}
//------------------------------------------------------ stopDiscovering example ------------------------------------------------------
var btnStopDiscovering = document.getElementById("stopDiscovering");
btnStopDiscovering.onclick = function() {
Bluetooth.stopDiscovering(null,
function(r){printResult8(r)},
function(e){log(e)}
);
}
var btnStopDiscovering = document.getElementById("stopDiscovering");
btnStopDiscovering.onclick = function() {
window.plugins.bluetooth.stopDiscovering(null,
function(r){printResult8(r)},
function(e){log(e)}
);
}
//------------------------------------------------------ isBound example ------------------------------------------------------
var btnIsBound = document.getElementById("isBound");
btnIsBound.onclick = function() {
Bluetooth.isBound("6C:9B:02:44:FA:BF",
function(r){printResult9(r)},
function(e){log(e)}
);
}
var btnIsBound = document.getElementById("isBound");
btnIsBound.onclick = function() {
window.plugins.bluetooth.isBound("6C:9B:02:44:FA:BF",
function(r){printResult9(r)},
function(e){log(e)}
);
}
}
function printResult(resultadoString){
var htmlText ="";
var i=0;
var htmlText ="";
var i=0;
var resultado = eval(resultadoString);
var resultado = eval(resultadoString);
for(i=0;i<resultado.length;i++)
{
htmlText=htmlText+"<ul><li>Name Device: "+resultado[i].name+"</li></ul>";
htmlText=htmlText+"<ul><li>Address Device: "+resultado[i].address+"</li></ul>";
}
for(i=0;i<resultado.length;i++)
{
htmlText=htmlText+"<ul><li>Name Device: "+resultado[i].name+"</li></ul>";
htmlText=htmlText+"<ul><li>Address Device: "+resultado[i].address+"</li></ul>";
}
document.getElementById("result").innerHTML=htmlText;
}
@@ -161,7 +161,7 @@ function printResult(resultadoString){
function printResult2(resultado){
var htmlText="<ul><li>is Bluetooth Enabled?: "+resultado+"</li></ul>";
var htmlText="<ul><li>is Bluetooth Enabled?: "+resultado+"</li></ul>";
document.getElementById("result").innerHTML=htmlText;
}
@@ -169,7 +169,7 @@ function printResult2(resultado){
function printResult3(resultado){
var htmlText="<ul><li>Bluetooth Enabled?: "+resultado+"</li></ul>";
var htmlText="<ul><li>Bluetooth Enabled?: "+resultado+"</li></ul>";
document.getElementById("result").innerHTML=htmlText;
}
@@ -178,7 +178,7 @@ function printResult3(resultado){
function printResult4(resultado){
var htmlText="<ul><li>Bluetooth Disabled?: "+resultado+"</li></ul>";
var htmlText="<ul><li>Bluetooth Disabled?: "+resultado+"</li></ul>";
document.getElementById("result").innerHTML=htmlText;
}
@@ -186,7 +186,7 @@ function printResult4(resultado){
function printResult5(resultado){
var htmlText="<ul><li>Pairing with Bluetooth Device: "+resultado+"</li></ul>";
var htmlText="<ul><li>Pairing with Bluetooth Device: "+resultado+"</li></ul>";
document.getElementById("result").innerHTML=htmlText;
}
@@ -194,23 +194,23 @@ function printResult5(resultado){
function printResult6(resultado){
var htmlText="<ul><li>unPairing Bluetooth Device: "+resultado+"</li></ul>";
var htmlText="<ul><li>unPairing Bluetooth Device: "+resultado+"</li></ul>";
document.getElementById("result").innerHTML=htmlText;
}
function printResult7(resultadoString){
var htmlText ="";
var i=0;
var htmlText ="";
var i=0;
var resultado = eval(resultadoString);
var resultado = eval(resultadoString);
for(i=0;i<resultado.length;i++)
{
htmlText=htmlText+"<ul><li>Name Device: "+resultado[i].name+"</li></ul>";
htmlText=htmlText+"<ul><li>Address Device: "+resultado[i].address+"</li></ul>";
}
for(i=0;i<resultado.length;i++)
{
htmlText=htmlText+"<ul><li>Name Device: "+resultado[i].name+"</li></ul>";
htmlText=htmlText+"<ul><li>Address Device: "+resultado[i].address+"</li></ul>";
}
document.getElementById("result").innerHTML=htmlText;
}
@@ -218,7 +218,7 @@ function printResult7(resultadoString){
function printResult8(resultado){
var htmlText="<ul><li>Stopping Discovering Bluetooth Devices: "+resultado+"</li></ul>";
var htmlText="<ul><li>Stopping Discovering Bluetooth Devices: "+resultado+"</li></ul>";
document.getElementById("result").innerHTML=htmlText;
}
@@ -226,24 +226,24 @@ function printResult8(resultado){
function printResult9(resultado){
var htmlText="<ul><li>is Device bound with mobile address 6C:9B:02:44:FA:BF?: "+resultado+"</li></ul>";
var htmlText="<ul><li>is Device bound with mobile address 6C:9B:02:44:FA:BF?: "+resultado+"</li></ul>";
document.getElementById("result").innerHTML=htmlText;
}
</script>
</script>
</head>
<body onload="onBodyLoad()">
<input id="isBTEnabled" type="button" value="Is Bluetooth Enabled?" />
<input id="enableBT" type="button" value="Enable Bluetooth" />
<input id="disableBT" type="button" value="Disable Bluetooth" />
<input id="list-devices" type="button" value="List Bluetooth Devices" />
<input id="list-bound-devices" type="button" value="List Bluetooth Bound Devices" />
<input id="pairBT" type="button" value="Pair Device" />
<input id="unPairBT" type="button" value="Unpair Device" />
<input id="stopDiscovering" type="button" value="Stop Discovering" />
<input id="isBound" type="button" value="Is Device bound with mobile" />
<input id="isBTEnabled" type="button" value="Is Bluetooth Enabled?" />
<input id="enableBT" type="button" value="Enable Bluetooth" />
<input id="disableBT" type="button" value="Disable Bluetooth" />
<input id="list-devices" type="button" value="List Bluetooth Devices" />
<input id="list-bound-devices" type="button" value="List Bluetooth Bound Devices" />
<input id="pairBT" type="button" value="Pair Device" />
<input id="unPairBT" type="button" value="Unpair Device" />
<input id="stopDiscovering" type="button" value="Stop Discovering" />
<input id="isBound" type="button" value="Is Device bound with mobile" />
<hr>