diff --git a/CHANGELOG.md b/CHANGELOG.md index f6eb8e0..1ab8874 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/README.md b/README.md index 1dcb8ca..81c685d 100755 --- a/README.md +++ b/README.md @@ -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. diff --git a/example/index.html b/example/index.html index fb2020f..2e14123 100644 --- a/example/index.html +++ b/example/index.html @@ -46,6 +46,7 @@

Central

Has Permission
Request Permission
+
Is Location Enabled

Devices

diff --git a/example/index.js b/example/index.js index aef0dd9..c850419 100644 --- a/example/index.js +++ b/example/index.js @@ -160,7 +160,7 @@ angular.module('myApp', ['ionic', 'ngCordovaBluetoothLE']) if (obj.status == "scanStarted") { return; } - + if ($rootScope.devices[obj.address] !== undefined) { return; } @@ -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) { @@ -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}; @@ -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}; @@ -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}; diff --git a/ng-cordova-bluetoothle.js b/ng-cordova-bluetoothle.js index 83af76a..0f84392 100644 --- a/ng-cordova-bluetoothle.js +++ b/ng-cordova-bluetoothle.js @@ -119,7 +119,7 @@ angular.module('ngCordovaBluetoothLE', []).factory('$cordovaBluetoothLE', ['$q', } return q.promise; }; - + var connect = function(params) { var q = $q.defer(); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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( @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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) { @@ -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() { @@ -669,7 +686,7 @@ angular.module('ngCordovaBluetoothLE', []).factory('$cordovaBluetoothLE', ['$q', startScan: startScan, stopScan: stopScan, retrieveConnected: retrieveConnected, - + connect: connect, reconnect: reconnect, disconnect: disconnect, @@ -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, diff --git a/package.json b/package.json index 59fc3f4..0342f1c 100755 --- a/package.json +++ b/package.json @@ -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",