Add optional pin parameter to peripheral connection.

This commit is contained in:
Evelyn Eastmond 2019-05-31 11:10:13 -04:00
parent 11b52c4e60
commit 8e302ac90c
2 changed files with 4 additions and 3 deletions

View file

@ -571,7 +571,7 @@ class EV3 {
*/ */
connect (id) { connect (id) {
if (this._bt) { if (this._bt) {
this._bt.connectPeripheral(id); this._bt.connectPeripheral(id, '1234');
} }
} }

View file

@ -58,9 +58,10 @@ class BT extends JSONRPCWebSocket {
* Try connecting to the input peripheral id, and then call the connect * Try connecting to the input peripheral id, and then call the connect
* callback if connection is successful. * callback if connection is successful.
* @param {number} id - the id of the peripheral to connect to * @param {number} id - the id of the peripheral to connect to
* @param {string} pin - an optional pin for pairing
*/ */
connectPeripheral (id) { connectPeripheral (id, pin = null) {
this.sendRemoteRequest('connect', {peripheralId: id}) this.sendRemoteRequest('connect', {peripheralId: id, pin: pin})
.then(() => { .then(() => {
this._connected = true; this._connected = true;
this._runtime.emit(this._runtime.constructor.PERIPHERAL_CONNECTED); this._runtime.emit(this._runtime.constructor.PERIPHERAL_CONNECTED);