replacing loops.pause -> pause, loops.forever -> forever

This commit is contained in:
Peli de Halleux
2018-02-14 16:05:31 -08:00
parent 0384eb4d9d
commit daa88b299d
62 changed files with 151 additions and 151 deletions

View File

@ -70,17 +70,17 @@ declare namespace loops {
* Repeats the code forever in the background. On each iteration, allows other codes to run.
* @param body code to execute
*/
//% help=loops/forever weight=100 afterOnStart=true
//% blockId=forever block="forever" blockAllowMultiple=1 shim=loops::forever
//% help=loops/forever weight=100 afterOnStart=true deprecated=true
//% blockId=forever_deprecated block="forever" blockAllowMultiple=1 shim=loops::forever
function forever(a: () => void): void;
/**
* Pause for the specified time in milliseconds
* @param ms how long to pause for, eg: 100, 200, 500, 1000, 2000
*/
//% help=loops/pause weight=99
//% help=loops/pause weight=99 deprecated=true
//% async block="pause %pause=timePicker|ms"
//% blockId=device_pause shim=loops::pause
//% blockId=device_pause_deprecated shim=loops::pause
function pause(ms: int32): void;
}
declare namespace control {

View File

@ -294,7 +294,7 @@ namespace sensors {
}
// wait a bit
loops.pause(50);
pause(50);
}
// apply tolerance

View File

@ -1,7 +1,7 @@
# Ambient Light
```blocks
loops.forever(function () {
forever(function () {
if (sensors.color1.ambientLight() > 20) {
brick.setStatusLight(StatusLight.Green)
} else {

View File

@ -1,7 +1,7 @@
# color
```blocks
loops.forever(function () {
forever(function () {
if (sensors.color1.color() == ColorSensorColor.Green) {
brick.setStatusLight(StatusLight.Green)
} else {

View File

@ -1,7 +1,7 @@
# Reflected Light
```blocks
loops.forever(function () {
forever(function () {
if (sensors.color1.reflectedLight() > 20) {
brick.setStatusLight(StatusLight.Green)
} else {

View File

@ -15,7 +15,7 @@ namespace sensors.internal {
let prev = query()
changeHandler(prev, prev)
while (true) {
loops.pause(periodMs)
pause(periodMs)
let curr = query()
if (prev !== curr) {
changeHandler(prev, curr)
@ -57,9 +57,9 @@ namespace sensors.internal {
uartMM = control.mmap("/dev/lms_uart", UartOff.Size, 0)
if (!uartMM) control.fail("no uart sensor")
loops.forever(() => {
forever(() => {
detectDevices()
loops.pause(500)
pause(500)
})
for (let info_ of sensorInfos) {
@ -258,7 +258,7 @@ namespace sensors.internal {
if (port < 0) return 0
let s = getUartStatus(port)
if (s) return s
loops.pause(25)
pause(25)
}
}
@ -280,7 +280,7 @@ namespace sensors.internal {
uartMM.setNumber(NumberFormat.Int8LE, UartOff.Status + port,
getUartStatus(port) & 0xfffe)
loops.pause(10)
pause(10)
}
}
@ -299,7 +299,7 @@ namespace sensors.internal {
} else {
break
}
loops.pause(10)
pause(10)
}
}

View File

@ -202,7 +202,7 @@ namespace motors {
// if we've recently completed a motor command with brake
// allow 500ms for robot to settle
if(this._brake)
loops.pause(500);
pause(500);
}
/**

View File

@ -31,15 +31,15 @@ brick.buttonUp.onEvent(ButtonEvent.Bumped, () => {
let num = 0
loops.forever(() => {
forever(() => {
serial.writeDmesg()
loops.pause(100)
pause(100)
})
/*
loops.forever(() => {
forever(() => {
let v = input.color.getColor()
screen.print(10, 60, v + " ")
loops.pause(200)
pause(200)
})
*/

View File

@ -41,7 +41,7 @@ namespace control {
//% blockId=timerPauseUntil block="%timer|pause until (ms) %ms"
pauseUntil(ms: number) {
const remaining = this.millis() - ms;
loops.pause(Math.max(0, remaining));
pause(Math.max(0, remaining));
}
}

View File

@ -1,4 +1,4 @@
// This is the last thing executed before user code
// We pause for 100ms to give time to read sensor values, so they work in on_start block
loops.pause(100)
pause(100)

View File

@ -18,7 +18,7 @@ When the brick is in motion, it moves in the direction of one of axes used to me
Flash the status light to red if the roll rate of `gyro 2` is more that `30` degrees per second.
```blocks
loops.forever(function () {
forever(function () {
if (sensors.gyro2.rate() > 30) {
brick.setStatusLight(StatusLight.RedFlash)
} else {

View File

@ -95,7 +95,7 @@ namespace sensors {
this.calibrating = true;
// may be triggered by a button click,
// give time for robot to settle
loops.pause(700);
pause(700);
// send a reset command
super.reset();
// switch back to the desired mode
@ -103,13 +103,13 @@ namespace sensors {
// wait till sensor is live
pauseUntil(() => this.isActive());
// give it a bit of time to init
loops.pause(1000)
pause(1000)
// compute drift
this._drift = 0;
if (this.mode == GyroSensorMode.Rate) {
for (let i = 0; i < 200; ++i) {
this._drift += this._query();
loops.pause(4);
pause(4);
}
this._drift /= 200;
}

View File

@ -33,7 +33,7 @@ namespace brick {
brick.setStatusLight(this.light);
brick.showImage(this.image);
music.playSoundEffectUntilDone(this.sound);
loops.pause(20);
pause(20);
}
}

View File

@ -1,7 +1,7 @@
music.setVolume(3)
music.playTone(440, 500)
loops.pause(500)
pause(500)
music.playTone(1440, 500)
loops.pause(500)
pause(500)
music.playTone(2440, 500)
loops.pause(500)
pause(500)

View File

@ -9,7 +9,7 @@ Tests are registered as event handlers. They will automatically run once ``on st
```blocks
tests.test("lgB set speed 10", () => {
motors.largeB.setSpeed(10);
loops.pause(100)
pause(100)
tests.assertClose("speedB", 10, motors.largeB.speed(), 2)
});
```

View File

@ -14,7 +14,7 @@ sensors.touch1.isPressed()
If the touch sensor ``touch 1`` is pressed, show a `green` status light. Otherwise, set the status light to `orange`.
```blocks
loops.forever(function () {
forever(function () {
if (sensors.touch1.isPressed()) {
brick.setStatusLight(StatusLight.Green)
} else {

View File

@ -17,13 +17,13 @@ If a touch sensor was pressed, then that event is remembered. Once you check if
If the touch sensor ``touch 1`` was pressed, show a `green` status light. Otherwise, set the status light to `orange`.
```blocks
loops.forever(function () {
forever(function () {
if (sensors.touch1.wasPressed()) {
brick.setStatusLight(StatusLight.Green)
} else {
brick.setStatusLight(StatusLight.Orange)
}
loops.pause(500)
pause(500)
})
```