Add delay to RGB block

This commit is contained in:
Tim Mickel 2016-05-03 17:20:10 -04:00
parent 659c9b274a
commit 85f8e99ca8
3 changed files with 16 additions and 6 deletions

View file

@ -177,11 +177,16 @@ WeDo2Blocks.prototype._getColor = function(colorName) {
}[colorName]; }[colorName];
}; };
WeDo2Blocks.prototype.setColor = function(argValues) { WeDo2Blocks.prototype.setColor = function(argValues, util) {
if (window.native) { if (window.native) {
var rgbColor = this._getColor(argValues[0]); var rgbColor = this._getColor(argValues[0]);
window.native.setLedColor(rgbColor[0], rgbColor[1], rgbColor[2]); window.native.setLedColor(rgbColor[0], rgbColor[1], rgbColor[2]);
} }
// Pause for quarter second
util.yield();
util.timeout(function() {
util.done();
}, 250);
}; };
WeDo2Blocks.prototype.whenDistanceClose = function() { WeDo2Blocks.prototype.whenDistanceClose = function() {

13
vm.js
View file

@ -1475,6 +1475,9 @@
this._removeThread(threadsCopy.pop()); this._removeThread(threadsCopy.pop());
} }
// @todo call stop function in all extensions/packages/WeDo stub // @todo call stop function in all extensions/packages/WeDo stub
if (window.native) {
window.native.motorStop();
}
}; };
/** /**
@ -1693,7 +1696,6 @@
thread.status = Thread.STATUS_DONE; thread.status = Thread.STATUS_DONE;
// Refresh nextBlock in case it has changed during a yield. // Refresh nextBlock in case it has changed during a yield.
thread.nextBlock = instance.runtime._getNextBlock(currentBlock); thread.nextBlock = instance.runtime._getNextBlock(currentBlock);
instance.runtime.glowBlock(currentBlock, false);
// Pop the stack and stack frame // Pop the stack and stack frame
thread.stack.pop(); thread.stack.pop();
thread.stackFrames.pop(); thread.stackFrames.pop();
@ -1743,7 +1745,6 @@
} else { } else {
thread.nextBlock = null; thread.nextBlock = null;
} }
instance.runtime.glowBlock(currentBlock, false);
switchedStack = true; switchedStack = true;
}; };
@ -1772,7 +1773,6 @@
} }
else { else {
try { try {
this.runtime.glowBlock(currentBlock, true);
// @todo deal with the return value // @todo deal with the return value
blockFunction(argValues, { blockFunction(argValues, {
yield: threadYieldCallback, yield: threadYieldCallback,
@ -2270,11 +2270,16 @@
}[colorName]; }[colorName];
}; };
WeDo2Blocks.prototype.setColor = function(argValues) { WeDo2Blocks.prototype.setColor = function(argValues, util) {
if (window.native) { if (window.native) {
var rgbColor = this._getColor(argValues[0]); var rgbColor = this._getColor(argValues[0]);
window.native.setLedColor(rgbColor[0], rgbColor[1], rgbColor[2]); window.native.setLedColor(rgbColor[0], rgbColor[1], rgbColor[2]);
} }
// Pause for quarter second
util.yield();
util.timeout(function() {
util.done();
}, 250);
}; };
WeDo2Blocks.prototype.whenDistanceClose = function() { WeDo2Blocks.prototype.whenDistanceClose = function() {

2
vm.min.js vendored

File diff suppressed because one or more lines are too long