awesome-cordova-plugins/src/plugins/bluetoothserial.ts

234 lines
6.3 KiB
TypeScript
Raw Normal View History

2016-07-08 06:39:05 +08:00
import { Cordova, Plugin } from './plugin';
2016-09-22 04:04:46 +08:00
import { Observable } from 'rxjs/Observable';
/**
* @name Bluetooth Serial
* @description This plugin enables serial communication over Bluetooth. It was written for communicating between Android or iOS and an Arduino.
* @usage
* ```typescript
* import { BluetoothSerial } from 'ionic-native';
*
*
2016-07-06 06:09:08 +08:00
* // Write a string
* BluetoothSerial.write("hello world").then(success, failure);
2016-07-06 06:09:08 +08:00
*
* // Array of int or bytes
* BluetoothSerial.write([186, 220, 222]).then(success, failure);
2016-07-06 06:09:08 +08:00
*
* // Typed Array
* var data = new Uint8Array(4);
* data[0] = 0x41;
* data[1] = 0x42;
* data[2] = 0x43;
* data[3] = 0x44;
* BluetoothSerial.write(data).then(success, failure);
2016-07-06 06:09:08 +08:00
*
* // Array Buffer
* BluetoothSerial.write(data.buffer).then(success, failure);
2016-07-06 06:09:08 +08:00
* ```
*/
@Plugin({
pluginName: 'BluetoothSerial',
repo: 'https://github.com/don/BluetoothSerial',
plugin: 'cordova-plugin-bluetooth-serial',
pluginRef: 'bluetoothSerial',
platforms: ['Android', 'iOS', 'Windows Phone', 'Browser']
})
export class BluetoothSerial {
/**
* Connect to a Bluetooth device
2016-07-06 06:09:08 +08:00
* @param {string} macAddress_or_uuid Identifier of the remote device
* @returns {Observable<any>} Subscribe to connect, unsubscribe to disconnect.
*/
@Cordova({
platforms: ['Android', 'iOS', 'Windows Phone'],
observable: true,
clearFunction: 'disconnect'
})
2016-07-08 06:39:05 +08:00
static connect(macAddress_or_uuid: string): Observable<any> { return; }
/**
* Connect insecurely to a Bluetooth device
2016-07-06 06:09:08 +08:00
* @param {string} macAddress Identifier of the remote device
* @returns {Observable<any>} Subscribe to connect, unsubscribe to disconnect.
*/
@Cordova({
platforms: ['Android'],
observable: true,
clearFunction: 'disconnect'
})
2016-07-08 06:39:05 +08:00
static connectInsecure(macAddress: string): Observable<any> { return; }
/**
* Disconnect from the connected device
* @returns {Promise<any>}
*/
@Cordova()
static disconnect(): Promise<any> { return; }
/**
* Writes data to the serial port
2016-07-06 06:09:08 +08:00
* @param {any} data ArrayBuffer of data
* @returns {Promise<any>} returns a promise when data has been written
*/
@Cordova({
platforms: ['Android', 'iOS', 'Windows Phone']
})
2016-07-08 06:39:05 +08:00
static write(data: any): Promise<any> { return; }
/**
* Gets the number of bytes of data available
* @returns {Promise<any>} returns a promise that contains the available bytes
*/
@Cordova({
platforms: ['Android', 'iOS', 'Windows Phone']
2016-07-08 06:39:05 +08:00
}) static available(): Promise<any> { return; }
/**
* Reads data from the buffer
* @returns {Promise<any>} returns a promise with data from the buffer
*/
@Cordova({
platforms: ['Android', 'iOS', 'Windows Phone']
})
2016-07-08 06:39:05 +08:00
static read(): Promise<any> { return; }
/**
* Reads data from the buffer until it reaches a delimiter
2016-07-06 06:09:08 +08:00
* @param {string} delimiter string that you want to search until
* @returns {Promise<any>} returns a promise
*/
@Cordova({
platforms: ['Android', 'iOS', 'Windows Phone']
})
2016-07-08 06:39:05 +08:00
static readUntil(delimiter: string): Promise<any> { return; }
/**
* Subscribe to be notified when data is received
2016-07-06 06:09:08 +08:00
* @param {string} delimiter the string you want to watch for
* @returns {Observable<any>} returns an observable.
*/
@Cordova({
platforms: ['Android', 'iOS', 'Windows Phone'],
observable: true,
clearFunction: 'unsubscribe'
})
2016-07-08 06:39:05 +08:00
static subscribe(delimiter: string): Observable<any> { return; }
/**
* Subscribe to be notified when data is received
* @returns {Observable<any>} returns an observable
*/
@Cordova({
platforms: ['Android', 'iOS', 'Windows Phone'],
observable: true,
clearFunction: 'unsubscribeRawData'
})
2016-07-08 06:39:05 +08:00
static subscribeRawData(): Observable<any> { return; }
/**
* Clears data in buffer
* @returns {Promise<any>} returns a promise when completed
*/
@Cordova({
platforms: ['Android', 'iOS', 'Windows Phone']
})
2016-07-08 06:39:05 +08:00
static clear(): Promise<any> { return; }
/**
* Lists bonded devices
* @returns {Promise<any>} returns a promise
*/
@Cordova({
platforms: ['Android', 'iOS', 'Windows Phone']
})
2016-07-08 06:39:05 +08:00
static list(): Promise<any> { return; }
/**
* Reports if bluetooth is enabled
* @returns {Promise<any>} returns a promise
*/
@Cordova({
platforms: ['Android', 'iOS', 'Windows Phone']
})
2016-07-08 06:39:05 +08:00
static isEnabled(): Promise<any> { return; }
/**
* Reports the connection status
* @returns {Promise<any>} returns a promise
*/
@Cordova({
platforms: ['Android', 'iOS', 'Windows Phone']
})
2016-07-08 06:39:05 +08:00
static isConnected(): Promise<any> { return; }
/**
* Reads the RSSI from the connected peripheral
* @returns {Promise<any>} returns a promise
*/
@Cordova({
platforms: ['Android', 'iOS', 'Windows Phone']
})
2016-07-08 06:39:05 +08:00
static readRSSI(): Promise<any> { return; }
/**
* Show the Bluetooth settings on the device
* @returns {Promise<any>} returns a promise
*/
@Cordova({
platforms: ['Android', 'iOS', 'Windows Phone']
})
2016-07-08 06:39:05 +08:00
static showBluetoothSettings(): Promise<any> { return; }
/**
* Enable Bluetooth on the device
* @returns {Promise<any>} returns a promise
*/
@Cordova({
platforms: ['Android', 'iOS', 'Windows Phone']
})
2016-07-08 06:39:05 +08:00
static enable(): Promise<any> { return; }
/**
* Discover unpaired devices
* @returns {Promise<any>} returns a promise
*/
@Cordova({
platforms: ['Android', 'iOS', 'Windows Phone']
})
2016-07-08 06:39:05 +08:00
static discoverUnpaired(): Promise<any> { return; }
/**
* Subscribe to be notified on Bluetooth device discovery. Discovery process must be initiated with the `discoverUnpaired` function.
* @returns {Observable<any>} Returns an observable
*/
@Cordova({
platforms: ['Android', 'iOS', 'Windows Phone'],
observable: true,
clearFunction: 'clearDeviceDiscoveredListener'
})
2016-07-08 06:39:05 +08:00
static setDeviceDiscoveredListener(): Observable<any> { return; }
/**
* Sets the human readable device name that is broadcasted to other devices
2016-07-06 06:09:08 +08:00
* @param {string} newName Desired name of device
*/
@Cordova({
platforms: ['Android'],
sync: true
})
2016-07-08 06:39:05 +08:00
static setName(newName: string): void { }
/**
* Makes the device discoverable by other devices
2016-07-06 06:09:08 +08:00
* @param {number} discoverableDuration Desired number of seconds device should be discoverable for
*/
@Cordova({
platforms: ['Android'],
sync: true
})
2016-07-08 06:39:05 +08:00
static setDiscoverable(discoverableDuration: number): void { }
2016-05-21 04:59:18 +08:00
}