simplified events

This commit is contained in:
Peli de Halleux 2017-10-26 20:57:18 -07:00
parent 282134f5dc
commit 21b34cb459
4 changed files with 15 additions and 15 deletions

View File

@ -32,8 +32,7 @@
"input.ColorSensor.reflectedLight": "Get current reflected light value from the color sensor.", "input.ColorSensor.reflectedLight": "Get current reflected light value from the color sensor.",
"input.GyroSensor.angle": "Get the current angle from the gyroscope.", "input.GyroSensor.angle": "Get the current angle from the gyroscope.",
"input.GyroSensor.rate": "Get the current rotation rate 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": "Registers code to run when an object is getting near.",
"input.InfraredSensor.onObjectNear|param|distance": "the proximity, eg: 10",
"input.InfraredSensor.onObjectNear|param|handler": "the code to run when detected", "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.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.", "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.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.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": "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.UltraSonicSensor.onObjectNear|param|handler": "the code to run when detected",
"input.buttonDown": "Down button on the EV3 Brick.", "input.buttonDown": "Down button on the EV3 Brick.",
"input.buttonEnter": "Enter button on the EV3 Brick.", "input.buttonEnter": "Enter button on the EV3 Brick.",

View File

@ -41,13 +41,13 @@
"input.ColorSensor.reflectedLight|block": "%color| reflected light", "input.ColorSensor.reflectedLight|block": "%color| reflected light",
"input.GyroSensor.angle|block": "%sensor|angle", "input.GyroSensor.angle|block": "%sensor|angle",
"input.GyroSensor.rate|block": "%sensor|rotation rate", "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.proximity|block": "%infrared|proximity",
"input.InfraredSensor.remoteCommand|block": "%infrared|remote command", "input.InfraredSensor.remoteCommand|block": "%infrared|remote command",
"input.TouchSensor.isTouched|block": "%sensor|is touched", "input.TouchSensor.isTouched|block": "%sensor|is touched",
"input.TouchSensor.onEvent|block": "on %sensor|%event", "input.TouchSensor.onEvent|block": "on %sensor|%event",
"input.UltraSonicSensor.distance|block": "%sensor|distance", "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.buttonDown|block": "brick button down",
"input.buttonEnter|block": "brick button enter", "input.buttonEnter|block": "brick button enter",
"input.buttonLeft|block": "brick button left", "input.buttonLeft|block": "brick button left",

View File

@ -123,24 +123,25 @@ namespace input {
} }
/** /**
* Registers code to run when an object is getting near * Registers code to run when an object is getting near.
* @param distance the proximity, eg: 10
* @param handler the code to run when detected * @param handler the code to run when detected
*/ */
//% help=input/infrared/on-object-near //% help=input/infrared/on-object-near
//% block="on %sensor|object within %distance" //% block="on %sensor|object near"
//% blockId=infraredOnObjectNear //% blockId=infraredOnObjectNear
//% parts="infraredsensor" //% parts="infraredsensor"
//% blockNamespace=input //% blockNamespace=input
//% weight=100 blockGap=8 //% weight=100 blockGap=8
//% distance.min=1 distance.max=95
//% group="Infrared Sensor" //% group="Infrared Sensor"
onObjectNear(distance: number, handler: () => void) { onObjectNear(handler: () => void) {
this.proximityThreshold = Math.max(1, Math.min(95, distance));
control.onEvent(this._id, PromixityEvent.ObjectNear, handler); control.onEvent(this._id, PromixityEvent.ObjectNear, handler);
if (this.proximity() == PromixityEvent.ObjectNear) if (this.proximity() == PromixityEvent.ObjectNear)
control.runInBackground(handler); 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) * Get the promixity measured by the infrared sensor, from ``0`` (close) to ``100`` (far)

View File

@ -34,24 +34,25 @@ namespace input {
/** /**
* Registers code to run when the given color is close * 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 * @param handler the code to run when detected
*/ */
//% help=input/ultrasonic/on-object-near //% help=input/ultrasonic/on-object-near
//% block="on %sensor|object within %distance|cm" //% block="on %sensor|object near"
//% blockId=ultrasonicOnObjectClose //% blockId=ultrasonicOnObjectClose
//% parts="infraredsensor" //% parts="infraredsensor"
//% blockNamespace=input //% blockNamespace=input
//% weight=100 blockGap=8 //% weight=100 blockGap=8
//% group="Ultrasonic Sensor" //% group="Ultrasonic Sensor"
//% distance.min=1 distance.max=250
onObjectNear(distance: number, handler: () => void) { onObjectNear(distance: number, handler: () => void) {
this.promixityThreshold = Math.max(1, Math.min(95, distance));
control.onEvent(this._id, PromixityEvent.ObjectNear, handler); control.onEvent(this._id, PromixityEvent.ObjectNear, handler);
if (this.distance() == PromixityEvent.ObjectNear) if (this.distance() == PromixityEvent.ObjectNear)
control.runInBackground(handler); control.runInBackground(handler);
} }
setObjectNearThreshold(distance: number) {
this.promixityThreshold = Math.max(1, Math.min(250, distance));
}
/** /**
* Gets the distance from the sonar in millimeters * Gets the distance from the sonar in millimeters
* @param sensor the ultrasonic sensor port * @param sensor the ultrasonic sensor port