Merge pull request from tmickel/feature/wedo-fixes

A few WeDo fixes
This commit is contained in:
Tim Mickel 2016-05-03 17:40:47 -04:00
commit c7a7e47cd4
5 changed files with 63 additions and 11 deletions

View file

@ -177,11 +177,16 @@ WeDo2Blocks.prototype._getColor = function(colorName) {
}[colorName];
};
WeDo2Blocks.prototype.setColor = function(argValues) {
WeDo2Blocks.prototype.setColor = function(argValues, util) {
if (window.native) {
var rgbColor = this._getColor(argValues[0]);
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() {

View file

@ -288,6 +288,27 @@ Runtime.prototype.greenFlag = function () {
}
};
/**
* Distance sensor hack
*/
Runtime.prototype.startDistanceSensors = function () {
// Add all top stacks with distance sensor
for (var j = 0; j < this.stacks.length; j++) {
var topBlock = this.stacks[j];
if (this.blocks[topBlock].opcode === 'wedo_whendistanceclose') {
var alreadyRunning = false;
for (var k = 0; k < this.threads.length; k++) {
if (this.threads[k].topBlock === topBlock) {
alreadyRunning = true;
}
}
if (!alreadyRunning) {
this._pushThread(this.stacks[j]);
}
}
}
};
/**
* Stop "everything"
*/
@ -297,6 +318,9 @@ Runtime.prototype.stopAll = function () {
this._removeThread(threadsCopy.pop());
}
// @todo call stop function in all extensions/packages/WeDo stub
if (window.native) {
window.native.motorStop();
}
};
/**

View file

@ -131,7 +131,6 @@ Sequencer.prototype.stepThread = function (thread) {
thread.status = Thread.STATUS_DONE;
// Refresh nextBlock in case it has changed during a yield.
thread.nextBlock = instance.runtime._getNextBlock(currentBlock);
instance.runtime.glowBlock(currentBlock, false);
// Pop the stack and stack frame
thread.stack.pop();
thread.stackFrames.pop();
@ -181,7 +180,6 @@ Sequencer.prototype.stepThread = function (thread) {
} else {
thread.nextBlock = null;
}
instance.runtime.glowBlock(currentBlock, false);
switchedStack = true;
};
@ -210,7 +208,6 @@ Sequencer.prototype.stepThread = function (thread) {
}
else {
try {
this.runtime.glowBlock(currentBlock, true);
// @todo deal with the return value
blockFunction(argValues, {
yield: threadYieldCallback,

34
vm.js
View file

@ -1466,6 +1466,27 @@
}
};
/**
* Distance sensor hack
*/
Runtime.prototype.startDistanceSensors = function () {
// Add all top stacks with distance sensor
for (var j = 0; j < this.stacks.length; j++) {
var topBlock = this.stacks[j];
if (this.blocks[topBlock].opcode === 'wedo_whendistanceclose') {
var alreadyRunning = false;
for (var k = 0; k < this.threads.length; k++) {
if (this.threads[k].topBlock === topBlock) {
alreadyRunning = true;
}
}
if (!alreadyRunning) {
this._pushThread(this.stacks[j]);
}
}
}
};
/**
* Stop "everything"
*/
@ -1475,6 +1496,9 @@
this._removeThread(threadsCopy.pop());
}
// @todo call stop function in all extensions/packages/WeDo stub
if (window.native) {
window.native.motorStop();
}
};
/**
@ -1693,7 +1717,6 @@
thread.status = Thread.STATUS_DONE;
// Refresh nextBlock in case it has changed during a yield.
thread.nextBlock = instance.runtime._getNextBlock(currentBlock);
instance.runtime.glowBlock(currentBlock, false);
// Pop the stack and stack frame
thread.stack.pop();
thread.stackFrames.pop();
@ -1743,7 +1766,6 @@
} else {
thread.nextBlock = null;
}
instance.runtime.glowBlock(currentBlock, false);
switchedStack = true;
};
@ -1772,7 +1794,6 @@
}
else {
try {
this.runtime.glowBlock(currentBlock, true);
// @todo deal with the return value
blockFunction(argValues, {
yield: threadYieldCallback,
@ -2270,11 +2291,16 @@
}[colorName];
};
WeDo2Blocks.prototype.setColor = function(argValues) {
WeDo2Blocks.prototype.setColor = function(argValues, util) {
if (window.native) {
var rgbColor = this._getColor(argValues[0]);
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() {

6
vm.min.js vendored

File diff suppressed because one or more lines are too long