Skip to content

Commit

Permalink
Merge pull request #133 from pokornyib/CreateAdapterWithCustomPort
Browse files Browse the repository at this point in the history
Create adapter with custom port
  • Loading branch information
bihanssen authored Feb 12, 2018
2 parents 259b31e + ac7b4d3 commit 6194a45
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
25 changes: 25 additions & 0 deletions api/adapterFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,31 @@ class AdapterFactory extends EventEmitter {
}
});
}

/**
* Create Adapter with custom serialport
*
* @param sdVersion {string} Softdevice API version: 'v2' or 'v3'.
* @param comName {string} Serialport name (eg. 'COM7' on windows).
* @param instanceId {string} The unique Id that identifies this Adapter instance.
* @returns {Adapter} Created adapter.
*/
createAdapter(sdVersion, comName, instanceId) {
if (sdVersion !== 'v2' && sdVersion !== 'v3') {
throw new Error('Unsupported soft-device version!');
}
if (typeof comName === 'undefined') {
throw new Error('Missing parameter: comName!');
}
if (typeof instanceId === 'undefined') {
throw new Error('Missing parameter: instanceId!');
}

const selectedDriver = this._bleDrivers[sdVersion];
const addOnAdapter = new selectedDriver.Adapter();

return new Adapter(selectedDriver, addOnAdapter, instanceId, comName);
}
}

module.exports = AdapterFactory;
3 changes: 2 additions & 1 deletion typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export declare interface ConnectionParameters {
max_conn_interval?: number; // FIXME: https://github.com/NordicSemiconductor/pc-ble-driver-js/issues/76
slaveLatency?: number;
slave_latency?: number; // FIXME: https://github.com/NordicSemiconductor/pc-ble-driver-js/issues/76
connectionSupervisionTimeout?: number;
connectionSupervisionTimeout?: number;
conn_sup_timeout?: number; // FIXME: https://github.com/NordicSemiconductor/pc-ble-driver-js/issues/76
}

Expand Down Expand Up @@ -271,6 +271,7 @@ declare class Adapter extends EventEmitter {
export declare class AdapterFactory extends EventEmitter {
static getInstance(): AdapterFactory;
getAdapters(callback?: (err: any, adapters: Adapter[]) => void);
createAdapter(sdVersion: 'v2' | 'v3', comName: string, instanceId: string): Adapter;
}

export declare class ServiceFactory {
Expand Down

0 comments on commit 6194a45

Please sign in to comment.