Merge uuid options with defaults

Move UuidOptions interface into secure-dfu.ts
This commit is contained in:
eric
2019-05-15 07:05:33 -05:00
parent 4d7b9fc295
commit c45f6f8b8d
2 changed files with 15 additions and 7 deletions

View File

@@ -24,7 +24,6 @@
*/
import { EventDispatcher } from "./dispatcher";
import { UuidOptions } from "./uuid-options";
const CONTROL_UUID = "8ec90001-f315-4f60-9fb8-838830daea50";
const PACKET_UUID = "8ec90002-f315-4f60-9fb8-838830daea50";
@@ -119,6 +118,13 @@ export interface BluetoothLEScanFilterInit {
namePrefix?: string;
}
export interface UuidOptions {
service?: number | string;
button?: number | string;
control?: number | string;
packet?: number | string;
}
/**
* Secure Device Firmware Update class
*/
@@ -409,6 +415,10 @@ export class SecureDfu extends EventDispatcher {
filters: Array<BluetoothLEScanFilterInit>,
uuids: UuidOptions = this.DEFAULT_UUIDS
): Promise<BluetoothDevice> {
uuids = {
...this.DEFAULT_UUIDS,
...uuids
};
if (!buttonLess && !filters) {
filters = [ { services: [ uuids.service ] } ];
}
@@ -436,6 +446,10 @@ export class SecureDfu extends EventDispatcher {
* @returns Promise containing the device if it is still on a valid state
*/
public setDfuMode(device: BluetoothDevice, uuids: UuidOptions = this.DEFAULT_UUIDS): Promise<BluetoothDevice> {
uuids = {
...this.DEFAULT_UUIDS,
...uuids
};
return this.gattConnect(device, uuids.service)
.then(characteristics => {
this.log(`found ${characteristics.length} characteristic(s)`);

View File

@@ -1,6 +0,0 @@
export interface UuidOptions {
service?: number | string;
button?: number | string;
control?: number | string;
packet?: number | string;
}