From f51173060257160f4bb98b157d4945ef9bd7d3a0 Mon Sep 17 00:00:00 2001 From: Evelyn Eastmond Date: Tue, 3 Jul 2018 14:38:17 -0400 Subject: [PATCH] Fix motor turn for ports C/D. Zero out sensors and motor values on disconnect. --- src/extensions/scratch3_ev3/index.js | 38 +++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/src/extensions/scratch3_ev3/index.js b/src/extensions/scratch3_ev3/index.js index f4ab5b4f8..875ef1f9a 100644 --- a/src/extensions/scratch3_ev3/index.js +++ b/src/extensions/scratch3_ev3/index.js @@ -171,8 +171,16 @@ class EV3 { disconnectSession () { this._bt.disconnectSession(); window.clearInterval(this._pollingIntervalID); // TODO: window? + this.speed = 50; + this._sensors = { + distance: 0, + brightness: 0, + buttons: [0, 0, 0, 0] + }; + this._motorPositions = [0, 0, 0, 0]; this._sensorPorts = []; this._motorPorts = []; + this._pollingIntervalID = null; } /** @@ -885,17 +893,39 @@ class Scratch3Ev3Blocks { } motorTurnClockwise (args) { - const port = Cast.toNumber(args.PORT); + const port = Cast.toNumber(args.PORT); // TODO: fix const time = Cast.toNumber(args.TIME) * 1000; - return this._device.motorTurnClockwise(port, time); + let p = null; + if (port === 1) { + p = 1; + } else if (port === 2) { + p = 2; + } else if (port === 3) { + p = 4; + } else if (port === 4) { + p = 8; + } + + return this._device.motorTurnClockwise(p, time); } motorTurnCounterClockwise (args) { - const port = Cast.toNumber(args.PORT); + const port = Cast.toNumber(args.PORT); // TODO: fix const time = Cast.toNumber(args.TIME) * 1000; - return this._device.motorTurnCounterClockwise(port, time); + let p = null; + if (port === 1) { + p = 1; + } else if (port === 2) { + p = 2; + } else if (port === 3) { + p = 4; + } else if (port === 4) { + p = 8; + } + + return this._device.motorTurnCounterClockwise(p, time); } motorRotate (args) {