adding waitUntil to buttons

This commit is contained in:
Peli de Halleux 2017-11-30 10:05:00 -08:00
parent 305a650125
commit a92edcffee
6 changed files with 34 additions and 0 deletions

View File

@ -18,6 +18,8 @@
"brick.Button.isPressed": "Check if button is currently pressed or not.", "brick.Button.isPressed": "Check if button is currently pressed or not.",
"brick.Button.onEvent": "Do something when a button or sensor is clicked, up or down.", "brick.Button.onEvent": "Do something when a button or sensor is clicked, up or down.",
"brick.Button.onEvent|param|body": "code to run when the event is raised", "brick.Button.onEvent|param|body": "code to run when the event is raised",
"brick.Button.waitUntil": "Waits until the event is raised",
"brick.Button.waitUntil|param|ev": "the event to wait for",
"brick.Button.wasPressed": "See if the button was pressed again since the last time you checked.", "brick.Button.wasPressed": "See if the button was pressed again since the last time you checked.",
"brick._imagePicker": "An image", "brick._imagePicker": "An image",
"brick._imagePicker|param|image": "the image", "brick._imagePicker|param|image": "the image",

View File

@ -19,6 +19,7 @@
"Output.D|block": "D", "Output.D|block": "D",
"brick.Button.isPressed|block": "`icons.brickButtons` %button|is pressed", "brick.Button.isPressed|block": "`icons.brickButtons` %button|is pressed",
"brick.Button.onEvent|block": "on `icons.brickButtons` %button|%event", "brick.Button.onEvent|block": "on `icons.brickButtons` %button|%event",
"brick.Button.waitUntil|block": "wait until `icons.brickButtons` %button|%event",
"brick.Button.wasPressed|block": "`icons.brickButtons` %button|was pressed", "brick.Button.wasPressed|block": "`icons.brickButtons` %button|was pressed",
"brick._imagePicker|block": "%image", "brick._imagePicker|block": "%image",
"brick.buttonDown|block": "down", "brick.buttonDown|block": "down",

View File

@ -127,6 +127,20 @@ namespace brick {
onEvent(ev: ButtonEvent, body: () => void) { onEvent(ev: ButtonEvent, body: () => void) {
control.onEvent(this._id, ev, body) control.onEvent(this._id, ev, body)
} }
/**
* Waits until the event is raised
* @param ev the event to wait for
*/
//% help=input/button/wait-until
//% blockId=buttonWaitUntil block="wait until `icons.brickButtons` %button|%event"
//% parts="brick"
//% blockNamespace=brick
//% weight=98 blockGap=8
//% group="Buttons"
waitUntil(ev: ButtonEvent) {
control.waitForEvent(this._id, ev);
}
} }
} }

View File

@ -3,5 +3,6 @@
"sensors.TouchSensor.isPressed": "Check if touch sensor is touched.", "sensors.TouchSensor.isPressed": "Check if touch sensor is touched.",
"sensors.TouchSensor.onEvent": "Do something when a touch sensor is touched...", "sensors.TouchSensor.onEvent": "Do something when a touch sensor is touched...",
"sensors.TouchSensor.onEvent|param|body": "code to run when the event is raised", "sensors.TouchSensor.onEvent|param|body": "code to run when the event is raised",
"sensors.TouchSensor.waitUntil": "Wait until the touch sensor is touched",
"sensors.TouchSensor.wasPressed": "Check if touch sensor is touched since it was last checked." "sensors.TouchSensor.wasPressed": "Check if touch sensor is touched since it was last checked."
} }

View File

@ -4,6 +4,7 @@
"TouchSensorEvent.Released|block": "released", "TouchSensorEvent.Released|block": "released",
"sensors.TouchSensor.isPressed|block": "`icons.touchSensor` %sensor|is pressed", "sensors.TouchSensor.isPressed|block": "`icons.touchSensor` %sensor|is pressed",
"sensors.TouchSensor.onEvent|block": "on `icons.touchSensor` %sensor|%event", "sensors.TouchSensor.onEvent|block": "on `icons.touchSensor` %sensor|%event",
"sensors.TouchSensor.waitUntil|block": "wait until `icons.touchSensor` %sensor|%event",
"sensors.TouchSensor.wasPressed|block": "`icons.touchSensor` %sensor|was pressed", "sensors.TouchSensor.wasPressed|block": "`icons.touchSensor` %sensor|was pressed",
"sensors.touchSensor1|block": "1", "sensors.touchSensor1|block": "1",
"sensors.touchSensor2|block": "2", "sensors.touchSensor2|block": "2",

View File

@ -51,6 +51,21 @@ namespace sensors {
this.button.onEvent(<ButtonEvent><number>ev, body) this.button.onEvent(<ButtonEvent><number>ev, body)
} }
/**
* Wait until the touch sensor is touched
* @param sensor the touch sensor that needs to be clicked or used
* @param event the kind of button gesture that needs to be detected
*/
//% help=input/touch-sensor/wait-until
//% blockId=touchWaitUntil block="wait until `icons.touchSensor` %sensor|%event"
//% parts="touch"
//% blockNamespace=sensors
//% weight=98 blockGap=8
//% group="Touch Sensor"
waitUntil(ev: TouchSensorEvent) {
this.button.waitUntil(<ButtonEvent><number>ev);
}
/** /**
* Check if touch sensor is touched. * Check if touch sensor is touched.
* @param sensor the port to query the request * @param sensor the port to query the request