Convert motor duration: seconds -> milliseconds

The block takes seconds, whereas the device takes milliseconds. Turning
on a motor for 1 millisecond isn't very dramatic.
This commit is contained in:
Christopher Willis-Ford 2017-05-11 22:39:24 -07:00
parent 06fe701624
commit cbfbc5d600

View file

@ -456,13 +456,14 @@ class Scratch3WeDo2Blocks {
* @return {Promise} - a promise which will resolve at the end of the duration.
*/
motorOnFor (args) {
const durationMS = args.DURATION * 1000;
return new Promise(resolve => {
this._forEachMotor(args.MOTOR_ID, motorIndex => {
this._device.motor(motorIndex).setMotorOnFor(args.DURATION);
this._device.motor(motorIndex).setMotorOnFor(durationMS);
});
// Ensure this block runs for a fixed amount of time even when no device is connected.
setTimeout(resolve, args.DURATION);
setTimeout(resolve, durationMS);
});
}