Close Scratch Link web socket on every new peripheral scan attempt (#1696)

* Progress towards: #1671: Close web socket before making a new one for hardware extensions.

* Always disconnect before scanning for new peripheral.  Removing console logs.

* Removing unused test code.
This commit is contained in:
Evelyn Eastmond 2018-11-08 15:21:28 -05:00 committed by Eric Rosenbaum
parent fe186913ac
commit 53c165c2f6
5 changed files with 33 additions and 9 deletions

View file

@ -346,7 +346,7 @@ class EV3Motor {
*/
coast () {
if (this._power === 0) return;
const cmd = this._parent.generateCommand(
Ev3Command.DIRECT_COMMAND_NO_REPLY,
[
@ -555,6 +555,9 @@ class EV3 {
* Called by the runtime when user wants to scan for an EV3 peripheral.
*/
scan () {
if (this._bt) {
this._bt.disconnect();
}
this._bt = new BT(this._runtime, this._extensionId, {
majorDeviceClass: 8,
minorDeviceClass: 1
@ -566,17 +569,22 @@ class EV3 {
* @param {number} id - the id of the peripheral to connect to.
*/
connect (id) {
this._bt.connectPeripheral(id);
if (this._bt) {
this._bt.connectPeripheral(id);
}
}
/**
* Called by the runtime when user wants to disconnect from the EV3 peripheral.
*/
disconnect () {
this._bt.disconnect();
this._clearSensorsAndMotors();
window.clearInterval(this._pollingIntervalID);
this._pollingIntervalID = null;
if (this._bt) {
this._bt.disconnect();
}
}
/**