From 0137b2c093560468128b31ec4d538f7b9d0c28ea Mon Sep 17 00:00:00 2001 From: tpsnt <4048510+tpsnt@users.noreply.github.com> Date: Wed, 28 Feb 2024 18:28:33 +0800 Subject: [PATCH 1/2] Update index.js --- src/extensions/scratch3_wedo2/index.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/extensions/scratch3_wedo2/index.js b/src/extensions/scratch3_wedo2/index.js index 6806e4f3cac..cda8fd51fd1 100644 --- a/src/extensions/scratch3_wedo2/index.js +++ b/src/extensions/scratch3_wedo2/index.js @@ -1375,7 +1375,11 @@ class Scratch3WeDo2Blocks { this._forEachMotor(args.MOTOR_ID, motorIndex => { const motor = this._peripheral.motor(motorIndex); if (motor) { - motor.power = MathUtil.clamp(Cast.toNumber(args.POWER), 0, 100); + const power = MathUtil.clamp(Cast.toNumber(args.POWER), 0, 100); + if (power === 0) { + motor.turnOff(); + } + motor.power = power; motor.turnOn(); } }); From 6594a11202c1d9e0b0daac123ef1487ee0e4f9be Mon Sep 17 00:00:00 2001 From: tpsnt <4048510+tpsnt@users.noreply.github.com> Date: Thu, 29 Feb 2024 09:17:24 +0800 Subject: [PATCH 2/2] Correcting for PR comments --- src/extensions/scratch3_wedo2/index.js | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/extensions/scratch3_wedo2/index.js b/src/extensions/scratch3_wedo2/index.js index cda8fd51fd1..64a6ee46171 100644 --- a/src/extensions/scratch3_wedo2/index.js +++ b/src/extensions/scratch3_wedo2/index.js @@ -269,8 +269,6 @@ class WeDo2Motor { * Turn this motor on indefinitely. */ turnOn () { - if (this._power === 0) return; - const cmd = this._parent.generateOutputCommand( this._index + 1, WeDo2Command.MOTOR_POWER, @@ -1375,11 +1373,7 @@ class Scratch3WeDo2Blocks { this._forEachMotor(args.MOTOR_ID, motorIndex => { const motor = this._peripheral.motor(motorIndex); if (motor) { - const power = MathUtil.clamp(Cast.toNumber(args.POWER), 0, 100); - if (power === 0) { - motor.turnOff(); - } - motor.power = power; + motor.power = MathUtil.clamp(Cast.toNumber(args.POWER), 0, 100); motor.turnOn(); } });