upgraded to run in parallel
This commit is contained in:
parent
18480080e7
commit
387effbdd0
@ -3,13 +3,13 @@
|
|||||||
```blocks
|
```blocks
|
||||||
let beep = false
|
let beep = false
|
||||||
beep = true
|
beep = true
|
||||||
control.runInBackground(function () {
|
control.runInParallel(function () {
|
||||||
motors.largeBC.setSpeed(-20)
|
motors.largeBC.setSpeed(-20)
|
||||||
sensors.ultrasonic4.pauseUntil(UltrasonicSensorEvent.ObjectNear)
|
sensors.ultrasonic4.pauseUntil(UltrasonicSensorEvent.ObjectNear)
|
||||||
motors.largeBC.stop()
|
motors.largeBC.stop()
|
||||||
beep = false
|
beep = false
|
||||||
})
|
})
|
||||||
control.runInBackground(function () {
|
control.runInParallel(function () {
|
||||||
while (beep) {
|
while (beep) {
|
||||||
if (sensors.ultrasonic4.distance() < 20) {
|
if (sensors.ultrasonic4.distance() < 20) {
|
||||||
music.playTone(440, sensors.ultrasonic4.distance())
|
music.playTone(440, sensors.ultrasonic4.distance())
|
||||||
|
@ -81,7 +81,7 @@ function IS(t: number) {
|
|||||||
|
|
||||||
function UP() {
|
function UP() {
|
||||||
if (motors.largeA.angle() > -50) {
|
if (motors.largeA.angle() > -50) {
|
||||||
control.runInBackground(function () {
|
control.runInParallel(function () {
|
||||||
motors.largeD.clearCounts()
|
motors.largeD.clearCounts()
|
||||||
motors.largeD.setSpeed(-35);
|
motors.largeD.setSpeed(-35);
|
||||||
pauseUntil(() => motors.largeD.angle() < -25);
|
pauseUntil(() => motors.largeD.angle() < -25);
|
||||||
|
@ -134,7 +134,7 @@
|
|||||||
"control.panic": "Display an error code and stop the program.",
|
"control.panic": "Display an error code and stop the program.",
|
||||||
"control.panic|param|code": "an error number to display. eg: 5",
|
"control.panic|param|code": "an error number to display. eg: 5",
|
||||||
"control.reset": "Reset the device.",
|
"control.reset": "Reset the device.",
|
||||||
"control.runInBackground": "Run other code in the background.",
|
"control.runInParallel": "Run other code in the parallel.",
|
||||||
"control.waitForEvent": "Blocks the calling thread until the specified event is raised.",
|
"control.waitForEvent": "Blocks the calling thread until the specified event is raised.",
|
||||||
"control.waitMicros": "Block the current fiber for the given microseconds",
|
"control.waitMicros": "Block the current fiber for the given microseconds",
|
||||||
"control.waitMicros|param|micros": "number of micro-seconds to wait. eg: 4",
|
"control.waitMicros|param|micros": "number of micro-seconds to wait. eg: 4",
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
"control.onEvent|block": "on event|from %src|with value %value",
|
"control.onEvent|block": "on event|from %src|with value %value",
|
||||||
"control.panic|block": "panic %code",
|
"control.panic|block": "panic %code",
|
||||||
"control.reset|block": "reset",
|
"control.reset|block": "reset",
|
||||||
"control.runInBackground|block": "run in background",
|
"control.runInParallel|block": "run in parallel",
|
||||||
"control.waitForEvent|block": "wait for event|from %src|with value %value",
|
"control.waitForEvent|block": "wait for event|from %src|with value %value",
|
||||||
"control.waitMicros|block": "wait (µs)%micros",
|
"control.waitMicros|block": "wait (µs)%micros",
|
||||||
"control|block": "control",
|
"control|block": "control",
|
||||||
|
8
libs/base/shims.d.ts
vendored
8
libs/base/shims.d.ts
vendored
@ -118,11 +118,11 @@ declare namespace control {
|
|||||||
function waitMicros(micros: int32): void;
|
function waitMicros(micros: int32): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Run other code in the background.
|
* Run other code in the parallel.
|
||||||
*/
|
*/
|
||||||
//% help=control/run-in-background blockAllowMultiple=1 afterOnStart=true
|
//% help=control/run-in-parallel handlerStatement=1
|
||||||
//% blockId="control_run_in_background" block="run in background" blockGap=8 shim=control::runInBackground
|
//% blockId="control_run_in_parallel" block="run in parallel" blockGap=8 shim=control::runInParallel
|
||||||
function runInBackground(a: () => void): void;
|
function runInParallel(a: () => void): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Blocks the calling thread until the specified event is raised.
|
* Blocks the calling thread until the specified event is raised.
|
||||||
|
@ -11,7 +11,7 @@ namespace sensors.internal {
|
|||||||
|
|
||||||
// This is implementation for the simulator.
|
// This is implementation for the simulator.
|
||||||
|
|
||||||
control.runInBackground(() => {
|
control.runInParallel(() => {
|
||||||
let prev = query()
|
let prev = query()
|
||||||
changeHandler(prev, prev)
|
changeHandler(prev, prev)
|
||||||
while (true) {
|
while (true) {
|
||||||
|
@ -271,7 +271,7 @@ void setupThread(Action a, TValue arg = 0, void (*runner)(Thread *) = NULL, TVal
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void runInBackground(Action a) {
|
void runInParallel(Action a) {
|
||||||
setupThread(a);
|
setupThread(a);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -291,7 +291,7 @@ namespace music {
|
|||||||
export function playSoundEffect(sound: Sound) {
|
export function playSoundEffect(sound: Sound) {
|
||||||
if (!sound || numSoundsPlaying >= soundsLimit) return;
|
if (!sound || numSoundsPlaying >= soundsLimit) return;
|
||||||
numSoundsPlaying++;
|
numSoundsPlaying++;
|
||||||
control.runInBackground(() => {
|
control.runInParallel(() => {
|
||||||
sound.play();
|
sound.play();
|
||||||
numSoundsPlaying--;
|
numSoundsPlaying--;
|
||||||
});
|
});
|
||||||
|
@ -44,8 +44,8 @@
|
|||||||
"webfonts-generator": "^0.4.0"
|
"webfonts-generator": "^0.4.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"pxt-common-packages": "0.15.7",
|
"pxt-common-packages": "0.17.1",
|
||||||
"pxt-core": "3.0.12"
|
"pxt-core": "3.0.14"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "node node_modules/pxt-core/built/pxt.js travis"
|
"test": "node node_modules/pxt-core/built/pxt.js travis"
|
||||||
|
Loading…
Reference in New Issue
Block a user