Skip to content

Commit

Permalink
Merge pull request #7 from randdusing/location-services
Browse files Browse the repository at this point in the history
support for enabling location
  • Loading branch information
randdusing committed Feb 24, 2016
2 parents f9000bb + 7121e74 commit 433df58
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 59 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Change Log

## 3.1.0 - 2016-02-23
- Add support for isLocationEnabled

## 3.0.0 - 2016-01-25
- Sync Angular wrapper's and Cordova plugin's version numbers
- Timeouts available on most functions
Expand Down
69 changes: 35 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,40 +87,41 @@ Connect uses the notify callback as well since the connection state may change.
## Available Functions
For details on each function, please visit https://github.com/randdusing/cordova-plugin-bluetoothle. A few methods require you wait for notify rather than resolve since the callback may be called multiple times: intialize, startScan, connect, reconnect, disconnect, subscribe. Enable and disable only wait for error since the "success" is returned to the initialize

$cordovaBluetoothLE.initialize(params).then(null, error, success);
$cordovaBluetoothLE.enable().then(null, error); **Android**
$cordovaBluetoothLE.disable().then(null, error); **Android**
$cordovaBluetoothLE.startScan(params).then(null, error, success);
$cordovaBluetoothLE.stopScan().then(success, error);
$cordovaBluetoothLE.retrieveConnected(params).then(success, error);
$cordovaBluetoothLE.connect(params).then(null, error, success);
$cordovaBluetoothLE.reconnect(params).then(null, error, success);
$cordovaBluetoothLE.disconnect(params).then(null, error, success);
$cordovaBluetoothLE.close(params).then(success, error);
$cordovaBluetoothLE.discover(params).then(success, error);
$cordovaBluetoothLE.services(params).then(success, error); **iOS**
$cordovaBluetoothLE.characteristics(params).then(success, error); **iOS**
$cordovaBluetoothLE.descriptors(params).then(success, error); **iOS**
$cordovaBluetoothLE.read(params).then(success, error);
$cordovaBluetoothLE.subscribe(params).then(null, error, success);
$cordovaBluetoothLE.unsubscribe(params).then(success, error);
$cordovaBluetoothLE.write(params).then(success, error);
$cordovaBluetoothLE.readDescriptor(params).then(success, error);
$cordovaBluetoothLE.writeDescriptor(params).then(success, error);
$cordovaBluetoothLE.rssi(params).then(success, error);
$cordovaBluetoothLE.mtu(params).then(success, error); **Android**
$cordovaBluetoothLE.requestConnectionPriority(params).then(success, error); **Android**
$cordovaBluetoothLE.isInitialized(params).then(success);
$cordovaBluetoothLE.isEnabled(params).then(success);
$cordovaBluetoothLE.isScanning(params).then(success);
$cordovaBluetoothLE.isConnected(params).then(success, error);
$cordovaBluetoothLE.isDiscovered(params).then(success, error);
$cordovaBluetoothLE.hasPermission().then(success, error); **Android 6.0+**
$cordovaBluetoothLE.requestPermission().then(success, error); **Android 6.0+**
$cordovaBluetoothLE.encodedStringToBytes(encodedString);
$cordovaBluetoothLE.bytesToEncodedString(bytes);
$cordovaBluetoothLE.stringToBytes(string);
$cordovaBluetoothLE.bytesToString(bytes);
* $cordovaBluetoothLE.initialize(params).then(null, error, success);
* $cordovaBluetoothLE.enable().then(null, error); **Android**
* $cordovaBluetoothLE.disable().then(null, error); **Android**
* $cordovaBluetoothLE.startScan(params).then(null, error, success);
* $cordovaBluetoothLE.stopScan().then(success, error);
* $cordovaBluetoothLE.retrieveConnected(params).then(success, error);
* $cordovaBluetoothLE.connect(params).then(null, error, success);
* $cordovaBluetoothLE.reconnect(params).then(null, error, success);
* $cordovaBluetoothLE.disconnect(params).then(null, error, success);
* $cordovaBluetoothLE.close(params).then(success, error);
* $cordovaBluetoothLE.discover(params).then(success, error);
* $cordovaBluetoothLE.services(params).then(success, error); **iOS**
* $cordovaBluetoothLE.characteristics(params).then(success, error); **iOS**
* $cordovaBluetoothLE.descriptors(params).then(success, error); **iOS**
* $cordovaBluetoothLE.read(params).then(success, error);
* $cordovaBluetoothLE.subscribe(params).then(null, error, success);
* $cordovaBluetoothLE.unsubscribe(params).then(success, error);
* $cordovaBluetoothLE.write(params).then(success, error);
* $cordovaBluetoothLE.readDescriptor(params).then(success, error);
* $cordovaBluetoothLE.writeDescriptor(params).then(success, error);
* $cordovaBluetoothLE.rssi(params).then(success, error);
* $cordovaBluetoothLE.mtu(params).then(success, error); **Android**
* $cordovaBluetoothLE.requestConnectionPriority(params).then(success, error); **Android**
* $cordovaBluetoothLE.isInitialized(params).then(success);
* $cordovaBluetoothLE.isEnabled(params).then(success);
* $cordovaBluetoothLE.isScanning(params).then(success);
* $cordovaBluetoothLE.isConnected(params).then(success, error);
* $cordovaBluetoothLE.isDiscovered(params).then(success, error);
* $cordovaBluetoothLE.hasPermission().then(success, error); **Android 6.0+**
* $cordovaBluetoothLE.requestPermission().then(success, error); **Android 6.0+**
* $cordovaBluetoothLE.isLocationEnabled().then(success, error); **Android 6.0+**
* $cordovaBluetoothLE.encodedStringToBytes(encodedString);
* $cordovaBluetoothLE.bytesToEncodedString(bytes);
* $cordovaBluetoothLE.stringToBytes(string);
* $cordovaBluetoothLE.bytesToString(bytes);

### Options ###
* useResolve - If true, forces connect and reconnect to resolve the promise rather than using notify.
Expand Down
1 change: 1 addition & 0 deletions example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ <h4>Central</h4>
<div class="row text-center">
<div class="col"><a class="button button-balanced button-small" ng-click="hasPermission()">Has Permission</a></div>
<div class="col"><a class="button button-balanced button-small" ng-click="requestPermission()">Request Permission</a></div>
<div class="col"><a class="button button-balanced button-small" ng-click="isLocationEnabled()">Is Location Enabled</a></div>
</div>
<div ng-hide="isEmpty(devices)" ng-cloak>
<h4>Devices</h4>
Expand Down
18 changes: 14 additions & 4 deletions example/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ angular.module('myApp', ['ionic', 'ngCordovaBluetoothLE'])
if (obj.status == "scanStarted") {
return;
}

if ($rootScope.devices[obj.address] !== undefined) {
return;
}
Expand Down Expand Up @@ -188,6 +188,16 @@ angular.module('myApp', ['ionic', 'ngCordovaBluetoothLE'])
console.log("Request Permission Error : " + JSON.stringify(obj));
});
};

$rootScope.isLocationEnabled = function() {
console.log("Is Location Enabled");

$cordovaBluetoothLE.isLocationEnabled().then(function(obj) {
console.log("Is Location Enabled Success : " + JSON.stringify(obj));
}, function(obj) {
console.log("Is Location Enabled Error : " + JSON.stringify(obj));
});
};
})

.controller('DeviceCtrl', function($scope, $rootScope, $state, $stateParams, $ionicHistory, $cordovaBluetoothLE) {
Expand Down Expand Up @@ -472,7 +482,7 @@ angular.module('myApp', ['ionic', 'ngCordovaBluetoothLE'])
console.log("Write Descriptor Error : " + JSON.stringify(obj));
});
};

$rootScope.isConnected = function(address) {
var params = {address:address};

Expand All @@ -496,7 +506,7 @@ angular.module('myApp', ['ionic', 'ngCordovaBluetoothLE'])
console.log("Is Discovered Error : " + JSON.stringify(obj));
});
};

$rootScope.rssi = function(address) {
var params = {address:address, timeout: 2000};

Expand All @@ -520,7 +530,7 @@ angular.module('myApp', ['ionic', 'ngCordovaBluetoothLE'])
console.log("MTU Error : " + JSON.stringify(obj));
});
};

$rootScope.requestConnectionPriority = function(address) {
var params = {address:address, connectionPriority:"high", timeout: 2000};

Expand Down
58 changes: 38 additions & 20 deletions ng-cordova-bluetoothle.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ angular.module('ngCordovaBluetoothLE', []).factory('$cordovaBluetoothLE', ['$q',
}
return q.promise;
};


var connect = function(params) {
var q = $q.defer();
Expand Down Expand Up @@ -215,7 +215,7 @@ angular.module('ngCordovaBluetoothLE', []).factory('$cordovaBluetoothLE', ['$q',
q.reject(errorUnsupported);
} else {
var timeout = createTimeout(params, q);

window.bluetoothle.discover(
function(obj) {
$timeout.cancel(timeout);
Expand All @@ -237,7 +237,7 @@ angular.module('ngCordovaBluetoothLE', []).factory('$cordovaBluetoothLE', ['$q',
q.reject(errorUnsupported);
} else {
var timeout = createTimeout(params, q);

window.bluetoothle.services(
function(obj) {
$timeout.cancel(timeout);
Expand All @@ -259,7 +259,7 @@ angular.module('ngCordovaBluetoothLE', []).factory('$cordovaBluetoothLE', ['$q',
q.reject(errorUnsupported);
} else {
var timeout = createTimeout(params, q);

window.bluetoothle.characteristics(
function(obj) {
$timeout.cancel(timeout);
Expand All @@ -281,7 +281,7 @@ angular.module('ngCordovaBluetoothLE', []).factory('$cordovaBluetoothLE', ['$q',
q.reject(errorUnsupported);
} else {
var timeout = createTimeout(params, q);

window.bluetoothle.descriptors(
function(obj) {
$timeout.cancel(timeout);
Expand All @@ -303,7 +303,7 @@ angular.module('ngCordovaBluetoothLE', []).factory('$cordovaBluetoothLE', ['$q',
q.reject(errorUnsupported);
} else {
var timeout = createTimeout(params, q);

window.bluetoothle.read(
function(obj) {
$timeout.cancel(timeout);
Expand All @@ -325,12 +325,12 @@ angular.module('ngCordovaBluetoothLE', []).factory('$cordovaBluetoothLE', ['$q',
q.reject(errorUnsupported);
} else {
var timeout = createTimeout(params, q);

window.bluetoothle.subscribe(
function(obj) {
$timeout.cancel(timeout);
q.notify(obj);

if (params.subscribeTimeout && obj.status == "subscribed") {
$timeout(function() {
window.bluetoothle.unsubscribe(
Expand Down Expand Up @@ -361,7 +361,7 @@ angular.module('ngCordovaBluetoothLE', []).factory('$cordovaBluetoothLE', ['$q',
q.reject(errorUnsupported);
} else {
var timeout = createTimeout(params, q);

window.bluetoothle.unsubscribe(
function(obj) {
$timeout.cancel(timeout);
Expand All @@ -383,7 +383,7 @@ angular.module('ngCordovaBluetoothLE', []).factory('$cordovaBluetoothLE', ['$q',
q.reject(errorUnsupported);
} else {
var timeout = createTimeout(params, q);

window.bluetoothle.write(
function(obj) {
$timeout.cancel(timeout);
Expand All @@ -405,7 +405,7 @@ angular.module('ngCordovaBluetoothLE', []).factory('$cordovaBluetoothLE', ['$q',
q.reject(errorUnsupported);
} else {
var timeout = createTimeout(params, q);

window.bluetoothle.readDescriptor(
function(obj) {
$timeout.cancel(timeout);
Expand All @@ -427,7 +427,7 @@ angular.module('ngCordovaBluetoothLE', []).factory('$cordovaBluetoothLE', ['$q',
q.reject(errorUnsupported);
} else {
var timeout = createTimeout(params, q);

window.bluetoothle.writeDescriptor(
function(obj) {
$timeout.cancel(timeout);
Expand All @@ -449,7 +449,7 @@ angular.module('ngCordovaBluetoothLE', []).factory('$cordovaBluetoothLE', ['$q',
q.reject(errorUnsupported);
} else {
var timeout = createTimeout(params, q);

window.bluetoothle.rssi(
function(obj) {
$timeout.cancel(timeout);
Expand All @@ -471,7 +471,7 @@ angular.module('ngCordovaBluetoothLE', []).factory('$cordovaBluetoothLE', ['$q',
q.reject(errorUnsupported);
} else {
var timeout = createTimeout(params, q);

window.bluetoothle.mtu(
function(obj) {
$timeout.cancel(timeout);
Expand All @@ -493,7 +493,7 @@ angular.module('ngCordovaBluetoothLE', []).factory('$cordovaBluetoothLE', ['$q',
q.reject(errorUnsupported);
} else {
var timeout = createTimeout(params, q);

window.bluetoothle.requestConnectionPriority(
function(obj) {
$timeout.cancel(timeout);
Expand Down Expand Up @@ -623,6 +623,23 @@ angular.module('ngCordovaBluetoothLE', []).factory('$cordovaBluetoothLE', ['$q',
return q.promise;
};

var isLocationEnabled = function() {
var q = $q.defer();
if (window.bluetoothle === undefined) {
q.reject(errorUnsupported);
} else {
window.bluetoothle.isLocationEnabled(
function(obj) {
q.resolve(obj);
},
function(obj) {
q.reject(obj);
}
);
}
return q.promise;
};


var encodedStringToBytes = function(value) {
if (window.bluetoothle === undefined) {
Expand Down Expand Up @@ -651,7 +668,7 @@ angular.module('ngCordovaBluetoothLE', []).factory('$cordovaBluetoothLE', ['$q',
}
return window.bluetoothle.bytesToString(value);
};

var createTimeout = function(params, q) {
if (params.timeout) {
return $timeout(function() {
Expand All @@ -669,7 +686,7 @@ angular.module('ngCordovaBluetoothLE', []).factory('$cordovaBluetoothLE', ['$q',
startScan: startScan,
stopScan: stopScan,
retrieveConnected: retrieveConnected,

connect: connect,
reconnect: reconnect,
disconnect: disconnect,
Expand All @@ -687,16 +704,17 @@ angular.module('ngCordovaBluetoothLE', []).factory('$cordovaBluetoothLE', ['$q',
rssi: rssi,
mtu: mtu,
requestConnectionPriority: requestConnectionPriority,

isInitialized: isInitialized,
isEnabled: isEnabled,
isScanning: isScanning,
isConnected: isConnected,
isDiscovered: isDiscovered,

hasPermission: hasPermission,
requestPermission: requestPermission,

isLocationEnabled: isLocationEnabled,

encodedStringToBytes: encodedStringToBytes,
bytesToEncodedString: bytesToEncodedString,
stringToBytes: stringToBytes,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ng-cordova-bluetoothle",
"version": "1.0.0",
"version": "3.1.0",
"description": "AngularJS Wrapper for Phonegap / Cordova Bluetooth LE Plugin",
"author": {
"name": "George Stocker",
Expand Down

0 comments on commit 433df58

Please sign in to comment.