diff --git a/libs/core/_locales/core-jsdoc-strings.json b/libs/core/_locales/core-jsdoc-strings.json index 40c39a29..8ce7b254 100644 --- a/libs/core/_locales/core-jsdoc-strings.json +++ b/libs/core/_locales/core-jsdoc-strings.json @@ -32,8 +32,7 @@ "input.ColorSensor.reflectedLight": "Get current reflected light value from the color sensor.", "input.GyroSensor.angle": "Get the current angle from the gyroscope.", "input.GyroSensor.rate": "Get the current rotation rate from the gyroscope.", - "input.InfraredSensor.onObjectNear": "Registers code to run when an object is getting near", - "input.InfraredSensor.onObjectNear|param|distance": "the proximity, eg: 10", + "input.InfraredSensor.onObjectNear": "Registers code to run when an object is getting near.", "input.InfraredSensor.onObjectNear|param|handler": "the code to run when detected", "input.InfraredSensor.proximity": "Get the promixity measured by the infrared sensor, from ``0`` (close) to ``100`` (far)", "input.InfraredSensor.remoteCommand": "Get the remote commandreceived the infrared sensor.", @@ -42,7 +41,6 @@ "input.TouchSensor.onEvent|param|body": "code to run when the event is raised", "input.UltraSonicSensor.distance": "Gets the distance from the sonar in millimeters", "input.UltraSonicSensor.onObjectNear": "Registers code to run when the given color is close", - "input.UltraSonicSensor.onObjectNear|param|distance": "the distance in centimeters when an object is close, eg: 10", "input.UltraSonicSensor.onObjectNear|param|handler": "the code to run when detected", "input.buttonDown": "Down button on the EV3 Brick.", "input.buttonEnter": "Enter button on the EV3 Brick.", diff --git a/libs/core/_locales/core-strings.json b/libs/core/_locales/core-strings.json index 89226773..363812af 100644 --- a/libs/core/_locales/core-strings.json +++ b/libs/core/_locales/core-strings.json @@ -41,13 +41,13 @@ "input.ColorSensor.reflectedLight|block": "%color| reflected light", "input.GyroSensor.angle|block": "%sensor|angle", "input.GyroSensor.rate|block": "%sensor|rotation rate", - "input.InfraredSensor.onObjectNear|block": "on %sensor|object within %distance", + "input.InfraredSensor.onObjectNear|block": "on %sensor|object near", "input.InfraredSensor.proximity|block": "%infrared|proximity", "input.InfraredSensor.remoteCommand|block": "%infrared|remote command", "input.TouchSensor.isTouched|block": "%sensor|is touched", "input.TouchSensor.onEvent|block": "on %sensor|%event", "input.UltraSonicSensor.distance|block": "%sensor|distance", - "input.UltraSonicSensor.onObjectNear|block": "on %sensor|object within %distance|cm", + "input.UltraSonicSensor.onObjectNear|block": "on %sensor|object near", "input.buttonDown|block": "brick button down", "input.buttonEnter|block": "brick button enter", "input.buttonLeft|block": "brick button left", diff --git a/libs/core/ir.ts b/libs/core/ir.ts index ff5fb7bd..08624987 100644 --- a/libs/core/ir.ts +++ b/libs/core/ir.ts @@ -123,24 +123,25 @@ namespace input { } /** - * Registers code to run when an object is getting near - * @param distance the proximity, eg: 10 + * Registers code to run when an object is getting near. * @param handler the code to run when detected */ //% help=input/infrared/on-object-near - //% block="on %sensor|object within %distance" + //% block="on %sensor|object near" //% blockId=infraredOnObjectNear //% parts="infraredsensor" //% blockNamespace=input //% weight=100 blockGap=8 - //% distance.min=1 distance.max=95 //% group="Infrared Sensor" - onObjectNear(distance: number, handler: () => void) { - this.proximityThreshold = Math.max(1, Math.min(95, distance)); + onObjectNear(handler: () => void) { control.onEvent(this._id, PromixityEvent.ObjectNear, handler); if (this.proximity() == PromixityEvent.ObjectNear) control.runInBackground(handler); } + + setObjectNearThreshold(distance: number) { + this.proximityThreshold = Math.max(1, Math.min(95, distance)); + } /** * Get the promixity measured by the infrared sensor, from ``0`` (close) to ``100`` (far) diff --git a/libs/core/ultrasonic.ts b/libs/core/ultrasonic.ts index 008be83d..5674ad98 100644 --- a/libs/core/ultrasonic.ts +++ b/libs/core/ultrasonic.ts @@ -34,24 +34,25 @@ namespace input { /** * Registers code to run when the given color is close - * @param distance the distance in centimeters when an object is close, eg: 10 * @param handler the code to run when detected */ //% help=input/ultrasonic/on-object-near - //% block="on %sensor|object within %distance|cm" + //% block="on %sensor|object near" //% blockId=ultrasonicOnObjectClose //% parts="infraredsensor" //% blockNamespace=input //% weight=100 blockGap=8 //% group="Ultrasonic Sensor" - //% distance.min=1 distance.max=250 onObjectNear(distance: number, handler: () => void) { - this.promixityThreshold = Math.max(1, Math.min(95, distance)); control.onEvent(this._id, PromixityEvent.ObjectNear, handler); if (this.distance() == PromixityEvent.ObjectNear) control.runInBackground(handler); } + setObjectNearThreshold(distance: number) { + this.promixityThreshold = Math.max(1, Math.min(250, distance)); + } + /** * Gets the distance from the sonar in millimeters * @param sensor the ultrasonic sensor port