From d9e0267fa083ced3b297ede13f4f21b9edd0f9e8 Mon Sep 17 00:00:00 2001 From: Kevin Andersen Date: Fri, 5 Apr 2019 14:18:33 -0400 Subject: [PATCH 1/3] Resolves #2086. This issue was caused by turnOnForDegrees() not resolving a promise. Additionally, this promise can only be resolved if its assigned before turnOnDegrees() was called, so in motorOnForRotation() it is now switched around. --- src/extensions/scratch3_boost/index.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/extensions/scratch3_boost/index.js b/src/extensions/scratch3_boost/index.js index ccd7f6d5f..acaedd56d 100644 --- a/src/extensions/scratch3_boost/index.js +++ b/src/extensions/scratch3_boost/index.js @@ -471,7 +471,11 @@ class BoostMotor { * @param {number} direction - rotate in this direction */ turnOnForDegrees (degrees, direction) { - if (this._power === 0) return; + if (this._power === 0) { + this.pendingPromiseFunction(); + return; + } + degrees = Math.max(0, degrees); const cmd = this._parent.generateOutputCommand( @@ -1642,8 +1646,8 @@ class Scratch3BoostBlocks { const motor = this._peripheral.motor(portID); if (motor) { return new Promise(resolve => { - motor.turnOnForDegrees(degrees, sign); motor.pendingPromiseFunction = resolve; + motor.turnOnForDegrees(degrees, sign); }); } return null; From 41873bf7bfa9e2125eb2f09e90188129ce938f6d Mon Sep 17 00:00:00 2001 From: Kevin Andersen Date: Tue, 9 Apr 2019 14:52:41 -0400 Subject: [PATCH 2/3] Use the power-getter rather than accessing the property directly --- src/extensions/scratch3_boost/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/extensions/scratch3_boost/index.js b/src/extensions/scratch3_boost/index.js index acaedd56d..6d4b4080f 100644 --- a/src/extensions/scratch3_boost/index.js +++ b/src/extensions/scratch3_boost/index.js @@ -471,7 +471,7 @@ class BoostMotor { * @param {number} direction - rotate in this direction */ turnOnForDegrees (degrees, direction) { - if (this._power === 0) { + if (this.power === 0) { this.pendingPromiseFunction(); return; } From b2c18e9dcd5c7dad7ab8c8da99095050523699c9 Mon Sep 17 00:00:00 2001 From: Kevin Andersen Date: Tue, 9 Apr 2019 15:34:08 -0400 Subject: [PATCH 3/3] BoostMotor.power(value) now sets to 0 if value is 0 rather than scaling, to ensure that blocks skip immediately if speed set to 0 --- src/extensions/scratch3_boost/index.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/extensions/scratch3_boost/index.js b/src/extensions/scratch3_boost/index.js index 186377599..a519f8a05 100644 --- a/src/extensions/scratch3_boost/index.js +++ b/src/extensions/scratch3_boost/index.js @@ -372,9 +372,11 @@ class BoostMotor { * Scale the motor power to a range between 10 and 100, * to make sure the motors will run with something built onto them. */ - const p = MathUtil.scale(value, 0, 100, 10, 100); - - this._power = p; + if (value === 0) { + this._power = 0; + } else { + this._power = MathUtil.scale(value, 1, 100, 10, 100); + } } /**