diff --git a/libs/core/_locales/core-jsdoc-strings.json b/libs/core/_locales/core-jsdoc-strings.json index 7d672f03..e0872308 100644 --- a/libs/core/_locales/core-jsdoc-strings.json +++ b/libs/core/_locales/core-jsdoc-strings.json @@ -18,6 +18,8 @@ "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|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._imagePicker": "An image", "brick._imagePicker|param|image": "the image", diff --git a/libs/core/_locales/core-strings.json b/libs/core/_locales/core-strings.json index 3da8c2f7..531eeb01 100644 --- a/libs/core/_locales/core-strings.json +++ b/libs/core/_locales/core-strings.json @@ -19,6 +19,7 @@ "Output.D|block": "D", "brick.Button.isPressed|block": "`icons.brickButtons` %button|is pressed", "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._imagePicker|block": "%image", "brick.buttonDown|block": "down", diff --git a/libs/core/buttons.ts b/libs/core/buttons.ts index 348fdc13..de1e4cfa 100644 --- a/libs/core/buttons.ts +++ b/libs/core/buttons.ts @@ -127,6 +127,20 @@ namespace brick { onEvent(ev: ButtonEvent, body: () => void) { 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); + } } } diff --git a/libs/touch-sensor/_locales/touch-sensor-jsdoc-strings.json b/libs/touch-sensor/_locales/touch-sensor-jsdoc-strings.json index f9ab05fa..71f6c8bf 100644 --- a/libs/touch-sensor/_locales/touch-sensor-jsdoc-strings.json +++ b/libs/touch-sensor/_locales/touch-sensor-jsdoc-strings.json @@ -3,5 +3,6 @@ "sensors.TouchSensor.isPressed": "Check if 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.waitUntil": "Wait until the touch sensor is touched", "sensors.TouchSensor.wasPressed": "Check if touch sensor is touched since it was last checked." } \ No newline at end of file diff --git a/libs/touch-sensor/_locales/touch-sensor-strings.json b/libs/touch-sensor/_locales/touch-sensor-strings.json index 34887021..fbda688f 100644 --- a/libs/touch-sensor/_locales/touch-sensor-strings.json +++ b/libs/touch-sensor/_locales/touch-sensor-strings.json @@ -4,6 +4,7 @@ "TouchSensorEvent.Released|block": "released", "sensors.TouchSensor.isPressed|block": "`icons.touchSensor` %sensor|is pressed", "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.touchSensor1|block": "1", "sensors.touchSensor2|block": "2", diff --git a/libs/touch-sensor/touch.ts b/libs/touch-sensor/touch.ts index bf1a0858..645d69ba 100644 --- a/libs/touch-sensor/touch.ts +++ b/libs/touch-sensor/touch.ts @@ -51,6 +51,21 @@ namespace sensors { this.button.onEvent(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(ev); + } + /** * Check if touch sensor is touched. * @param sensor the port to query the request