mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-12-04 20:21:46 +00:00
Add cordova-plugin-ble-central and jquery.rateit (#12127)
* Add cordova-plugin-ble-central * Added jquery.rateit definitions
This commit is contained in:
@@ -0,0 +1,121 @@
|
||||
/// <reference path='./cordova-plugin-ble-central.d.ts' />
|
||||
|
||||
var log = (msg : string) => {};
|
||||
var devices: BLECentralPlugin.PeripheralData[] = [];
|
||||
var demoDevice :BLECentralPlugin.PeripheralData = {
|
||||
"name": "Battery Demo",
|
||||
"id": "20:FF:D0:FF:D1:C0",
|
||||
"advertising": [2,1,6,3,3,15,24,8,9,66,97,116,116,101,114,121],
|
||||
"rssi": -55
|
||||
};
|
||||
|
||||
devices.push(demoDevice);
|
||||
var demoExtendedData : BLECentralPlugin.PeripheralDataExtended = {
|
||||
"name": "Battery Demo",
|
||||
"id": "20:FF:D0:FF:D1:C0",
|
||||
"advertising": [2,1,6,3,3,15,24,8,9,66,97,116,116,101,114,121],
|
||||
"rssi": -55,
|
||||
"services": [
|
||||
"1800",
|
||||
"1801",
|
||||
"180f"
|
||||
],
|
||||
"characteristics": [
|
||||
{
|
||||
"service": "1800",
|
||||
"characteristic": "2a00",
|
||||
"properties": [
|
||||
"Read"
|
||||
]
|
||||
},
|
||||
{
|
||||
"service": "1800",
|
||||
"characteristic": "2a01",
|
||||
"properties": [
|
||||
"Read"
|
||||
]
|
||||
},
|
||||
{
|
||||
"service": "1801",
|
||||
"characteristic": "2a05",
|
||||
"properties": [
|
||||
"Read"
|
||||
]
|
||||
},
|
||||
{
|
||||
"service": "180f",
|
||||
"characteristic": "2a19",
|
||||
"properties": [
|
||||
"Read"
|
||||
],
|
||||
"descriptors": [
|
||||
{
|
||||
"uuid": "2901"
|
||||
},
|
||||
{
|
||||
"uuid": "2904"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
|
||||
//get updates about the bluethooth states
|
||||
ble.startStateNotifications((state) => log(`BLE state ${state}`));
|
||||
|
||||
ble.isEnabled(()=> log(`bluetooth is enabled`), ()=>log(`bluetooth is not enabled`));
|
||||
|
||||
//here we try to enable bluetooth
|
||||
ble.enable(() => log(`yes it worked, or it was already enabled `), () => log(`nope it didn't work, the user pressed cancel, or we are in iOS`));
|
||||
|
||||
ble.showBluetoothSettings(() => log(`yes it worked`), () => log(`nope it didn't work`))
|
||||
|
||||
//stop getting updates about the bluethooth states
|
||||
ble.stopStateNotifications()
|
||||
|
||||
//scan 5 seconds
|
||||
ble.scan([], 5000, (data) => { devices.push(data); }, ()=> log('couldn\'t connect') );
|
||||
|
||||
//scan continously
|
||||
ble.startScan([], (data) => { devices.push(data); }, ()=> log('couldn\'t connect') )
|
||||
|
||||
////scan continously
|
||||
ble.startScanWithOptions([], {reportDuplicates:false }, (data) => { devices.push(data); }, ()=> log('couldn\'t connect') )
|
||||
|
||||
//stop scanning
|
||||
ble.stopScan(()=> log('all good'), ()=> log('couldn\'t stop scanning'));
|
||||
|
||||
//are we conenected to that device?
|
||||
ble.isConnected(demoDevice.id, () => log(`already connected to this device`), ()=> log(`not yet connected to that device`));
|
||||
|
||||
//connect to a specific device
|
||||
var extendedData : BLECentralPlugin.PeripheralDataExtended;
|
||||
ble.connect(demoDevice.id, (data)=> extendedData = data, () => log(`couldn't connect to the device`) );
|
||||
|
||||
//read some data from a characteristic
|
||||
var charsOfOneOfItsServices = demoExtendedData.characteristics.filter((value) => value.service == demoExtendedData.services[0]);
|
||||
ble.read(demoDevice.id, charsOfOneOfItsServices[0].service, charsOfOneOfItsServices[0].characteristic, (data) => log(`we've received some data`), ()=> log(`couldn't read any data`));
|
||||
|
||||
//read the rssi
|
||||
ble.readRSSI(demoDevice.id, (rssi)=>log(`Device ${demoDevice.name} has an RSSI of ${rssi}`));
|
||||
|
||||
var notificationsReceived : number = 0;
|
||||
//get notified of changes for that characteristic
|
||||
ble.startNotification(demoDevice.id, charsOfOneOfItsServices[0].service, charsOfOneOfItsServices[0].characteristic, (data)=> notificationsReceived++, ()=> log(`darn`));
|
||||
|
||||
//write some data
|
||||
ble.write(demoDevice.id, charsOfOneOfItsServices[0].service, charsOfOneOfItsServices[0].characteristic, new ArrayBuffer(40), ()=> log(`all good`), ()=> log(`could't write`));
|
||||
//write some data without getting notified
|
||||
ble.writeWithoutResponse(demoDevice.id, charsOfOneOfItsServices[0].service, charsOfOneOfItsServices[0].characteristic, new ArrayBuffer(40), ()=> log(`all good`), ()=> log(`could't write`));
|
||||
|
||||
//stop getting notified of changes.
|
||||
ble.stopNotification(demoDevice.id, charsOfOneOfItsServices[0].service, charsOfOneOfItsServices[0].characteristic);
|
||||
|
||||
//notificationsReceived == 1
|
||||
|
||||
//just disconnect
|
||||
ble.disconnect(demoDevice.id);
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
// Type definitions for cordova-plugin-ble-central 1.1.2
|
||||
// Project: https://github.com/don/cordova-plugin-ble-central
|
||||
// Definitions by: Gidon Junge <https://github.com/gjunge>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
|
||||
declare namespace BLECentralPlugin {
|
||||
|
||||
interface PeripheralCharacteristic {
|
||||
service: string;
|
||||
characteristic: string;
|
||||
properties: string[];
|
||||
descriptors?: any[];
|
||||
}
|
||||
|
||||
interface PeripheralData {
|
||||
name: string;
|
||||
id: string;
|
||||
rssi: number
|
||||
advertising: ArrayBuffer|any;
|
||||
}
|
||||
|
||||
|
||||
interface PeripheralDataExtended extends PeripheralData{
|
||||
services: string[];
|
||||
characteristics: PeripheralCharacteristic[]
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
interface StartScanOptions {
|
||||
reportDuplicates?: boolean;
|
||||
}
|
||||
|
||||
export interface BLECentralPluginStatic {
|
||||
scan(services: string[], seconds: number, success : (data: PeripheralData) => any): void;
|
||||
scan(services: string[], seconds: number, success : (data: PeripheralData) => any, failure : () => any): void;
|
||||
|
||||
startScan(services: string[], success: (data: PeripheralData) => any): void;
|
||||
startScan(services: string[], success: (data: PeripheralData) => any, failure: () => any): void;
|
||||
|
||||
startScanWithOptions(services: string[], options: StartScanOptions, success: (data: PeripheralData) => any): void;
|
||||
startScanWithOptions(services: string[], options: StartScanOptions, success: (data: PeripheralData) => any, failure: () => any): void;
|
||||
|
||||
stopScan(): void;
|
||||
stopScan(success: () => any): void;
|
||||
stopScan(success: () => any, failure: () => any): void;
|
||||
|
||||
connect(device_id:string, success: (data: PeripheralDataExtended) => any, failure: () => any): void;
|
||||
|
||||
disconnect(device_id:string): void;
|
||||
disconnect(device_id:string, success: () => any): void;
|
||||
disconnect(device_id:string, success: () => any, failure: () => any): void;
|
||||
|
||||
read(device_id: string, service_uuid:string, characteristic_uuid:string): void;
|
||||
read(device_id: string, service_uuid:string, characteristic_uuid:string, success: (rawData: ArrayBuffer) => any): void;
|
||||
read(device_id: string, service_uuid:string, characteristic_uuid:string, success: (rawData: ArrayBuffer) => any, failure: () => any): void;
|
||||
|
||||
write(device_id: string, service_uuid:string, characteristic_uuid:string, data: ArrayBuffer): void;
|
||||
write(device_id: string, service_uuid:string, characteristic_uuid:string, data: ArrayBuffer, success : () => any): void;
|
||||
write(device_id: string, service_uuid:string, characteristic_uuid:string, data: ArrayBuffer, success : () => any, failure: () => any): void;
|
||||
|
||||
/* Writes data to a characteristic without a response from the peripheral. You are not notified if the write fails in the BLE stack.
|
||||
The success callback is be called when the characteristic is written.*/
|
||||
writeWithoutResponse(device_id: string, service_uuid:string, characteristic_uuid:string, data: ArrayBuffer): void;
|
||||
writeWithoutResponse(device_id: string, service_uuid:string, characteristic_uuid:string, data: ArrayBuffer, success : () => any): void;
|
||||
writeWithoutResponse(device_id: string, service_uuid:string, characteristic_uuid:string, data: ArrayBuffer, success : () => any, failure: () => any): void;
|
||||
|
||||
/* Register to be notified when the value of a characteristic changes. */
|
||||
startNotification(device_id: string, service_uuid:string, characteristic_uuid:string, success: (rawData: ArrayBuffer) => any): void;
|
||||
startNotification(device_id: string, service_uuid:string, characteristic_uuid:string, success: (rawData: ArrayBuffer) => any, failure: () => any): void;
|
||||
|
||||
stopNotification(device_id: string, service_uuid:string, characteristic_uuid:string): void;
|
||||
stopNotification(device_id: string, service_uuid:string, characteristic_uuid:string, success: () => any): void;
|
||||
stopNotification(device_id: string, service_uuid:string, characteristic_uuid:string, success: () => any, failure: () => any): void;
|
||||
|
||||
/* Reports if bluetooth is enabled. */
|
||||
isEnabled(success: () => any , failure: () => any): void;
|
||||
|
||||
/* Calls the success callback when the peripheral is connected and the failure callback when not connected. */
|
||||
isConnected(device_id: string, success: () => any): void;
|
||||
isConnected(device_id: string, success: () => any, failure: () => any): void;
|
||||
|
||||
startStateNotifications(success: (state: string) => any): void;
|
||||
startStateNotifications(success: (state: string) => any, failure: () => any): void;
|
||||
|
||||
stopStateNotifications(): void;
|
||||
stopStateNotifications(success: () => any): void;
|
||||
stopStateNotifications(success: () => any, failure: () => any): void;
|
||||
|
||||
/* Opens the Bluetooth settings for the operating systems.
|
||||
[iOS] showBluetoothSettings is not supported on iOS. */
|
||||
showBluetoothSettings(): void;
|
||||
showBluetoothSettings(success: () => any): void;
|
||||
showBluetoothSettings(success: () => any, failure: () => any): void;
|
||||
|
||||
/* Enable Bluetooth on the device.
|
||||
[iOS] enable is not supported on iOS. */
|
||||
enable(success: () => any, failure: () => any): void;
|
||||
|
||||
|
||||
readRSSI(device_id:string, success: (rssi: number) => any): void;
|
||||
readRSSI(device_id:string, success: (rssi: number) => any, failure: () => any): void;
|
||||
}
|
||||
}
|
||||
|
||||
declare var ble: BLECentralPlugin.BLECentralPluginStatic;
|
||||
@@ -0,0 +1,48 @@
|
||||
/// <reference path="jquery.rateit.d.ts"/>
|
||||
|
||||
var rateit_simple = $('.rateit').rateit();
|
||||
|
||||
var rateit_properties_font = $('.rateit').rateit({
|
||||
backingfld: '#backingfield',
|
||||
icon: '@',
|
||||
mode: 'font',
|
||||
ispreset: false,
|
||||
max: 5,
|
||||
min: 0,
|
||||
readonly: false,
|
||||
resetable: false,
|
||||
step: 0.5,
|
||||
value: 2
|
||||
});
|
||||
|
||||
var rateit_properties_bg = $('.rateit').rateit({
|
||||
backingfld: '#backingfield',
|
||||
mode: 'bg',
|
||||
ispreset: false,
|
||||
max: 5,
|
||||
min: 0,
|
||||
readonly: false,
|
||||
resetable: false,
|
||||
step: 0.5,
|
||||
value: 2,
|
||||
starheight: 16,
|
||||
starwidth: 16
|
||||
});
|
||||
|
||||
//getters
|
||||
var val : number = rateit_properties_bg.rateit('value');
|
||||
var min : number = rateit_properties_bg.rateit('min');
|
||||
var max : number = rateit_properties_bg.rateit('max');
|
||||
var readonly :boolean = rateit_properties_bg.rateit('readonly');
|
||||
var ispreset :boolean = rateit_properties_bg.rateit('ispreset');
|
||||
|
||||
|
||||
//setters
|
||||
rateit_properties_bg.rateit('value',4);
|
||||
rateit_properties_bg.rateit('min',0);
|
||||
rateit_properties_bg.rateit('max',6);
|
||||
rateit_properties_bg.rateit('readonly',true);
|
||||
rateit_properties_bg.rateit('ispreset',false);
|
||||
|
||||
//reset it
|
||||
rateit_properties_bg.rateit('reset');
|
||||
Vendored
+45
@@ -0,0 +1,45 @@
|
||||
// Type definitions for jquery.rateit.js 1.1.1
|
||||
// Project: https://github.com/gjunge/rateit.js
|
||||
// Definitions by: Gidon Junge <https://github.com/gjunge>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/// <reference path="../jquery/jquery.d.ts"/>
|
||||
type RateItMode = "bg" | "font";
|
||||
interface RateItOptions {
|
||||
value? : number;
|
||||
min?: number;
|
||||
max?: number;
|
||||
step?:number;
|
||||
backingfld?:string;
|
||||
readonly?:boolean;
|
||||
ispreset? : boolean;
|
||||
resetable? : boolean;
|
||||
starwidth?: number;
|
||||
starheight?: number;
|
||||
mode?: RateItMode;
|
||||
icon?: string;
|
||||
}
|
||||
|
||||
interface JQuery {
|
||||
rateit() : JQuery;
|
||||
rateit(options: RateItOptions) : JQuery;
|
||||
|
||||
rateit(method: 'value') : number;
|
||||
rateit(method: 'value', param: number) : JQuery;
|
||||
|
||||
rateit(method: 'max') : number;
|
||||
rateit(method: 'max', param: number) : JQuery;
|
||||
|
||||
rateit(method: 'min') : number;
|
||||
rateit(method: 'min', param: number) : JQuery;
|
||||
|
||||
rateit(method: 'readonly') : boolean;
|
||||
rateit(method: 'readonly', param: boolean) : JQuery;
|
||||
|
||||
rateit(method: 'ispreset') : boolean;
|
||||
rateit(method: 'ispreset', param: boolean) : JQuery;
|
||||
|
||||
rateit(method: 'reset') : JQuery;
|
||||
|
||||
rateit(method: string, param: any) : any;
|
||||
}
|
||||
Reference in New Issue
Block a user