threshold query api
This commit is contained in:
@ -5,5 +5,7 @@
|
||||
"sensors.UltraSonicSensor.pauseUntil": "Waits for the event to occur",
|
||||
"sensors.UltraSonicSensor.setThreshold": "Sets a threshold value",
|
||||
"sensors.UltraSonicSensor.setThreshold|param|condition": "the dark or bright light condition",
|
||||
"sensors.UltraSonicSensor.setThreshold|param|value": "the value threshold"
|
||||
"sensors.UltraSonicSensor.setThreshold|param|value": "the value threshold",
|
||||
"sensors.UltraSonicSensor.threshold": "Gets the threshold value",
|
||||
"sensors.UltraSonicSensor.threshold|param|condition": "the proximity condition"
|
||||
}
|
@ -6,6 +6,7 @@
|
||||
"sensors.UltraSonicSensor.onEvent|block": "on %sensor|%event",
|
||||
"sensors.UltraSonicSensor.pauseUntil|block": "pause until %sensor| %event",
|
||||
"sensors.UltraSonicSensor.setThreshold|block": "set %sensor|%condition|to %value",
|
||||
"sensors.UltraSonicSensor.threshold|block": "%sensor|%condition",
|
||||
"sensors.ultrasonic1|block": "ultrasonic 1",
|
||||
"sensors.ultrasonic2|block": "ultrasonic 2",
|
||||
"sensors.ultrasonic3|block": "ultrasonic 3",
|
||||
|
@ -93,20 +93,36 @@ namespace sensors {
|
||||
* @param value the value threshold
|
||||
*/
|
||||
//% blockId=ultrasonicSetThreshold block="set %sensor|%condition|to %value"
|
||||
//% group="Threshold" blockGap=8
|
||||
//% group="Threshold" blockGap=8 weight=80
|
||||
//% value.min=0 value.max=255
|
||||
setThreshold(condition: UltrasonicSensorEvent, value: number) {
|
||||
switch(condition) {
|
||||
setThreshold(condition: UltrasonicSensorEvent, value: number) {
|
||||
switch (condition) {
|
||||
case UltrasonicSensorEvent.ObjectNear: this.promixityThreshold.setLowThreshold(value); break;
|
||||
case UltrasonicSensorEvent.ObjectFar: this.promixityThreshold.setHighThreshold(value); break;
|
||||
case UltrasonicSensorEvent.ObjectDetected: this.movementThreshold = value; break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the threshold value
|
||||
* @param condition the proximity condition
|
||||
*/
|
||||
//% blockId=ultrasonicGetThreshold block="%sensor|%condition"
|
||||
//% group="Threshold" blockGap=8 weight=79
|
||||
//% sensor.fieldEditor="ports"
|
||||
threshold(condition: UltrasonicSensorEvent): number {
|
||||
switch (condition) {
|
||||
case UltrasonicSensorEvent.ObjectNear: this.promixityThreshold.threshold(ThresholdState.Low); break;
|
||||
case UltrasonicSensorEvent.ObjectFar: this.promixityThreshold.threshold(ThresholdState.Low); break;
|
||||
case UltrasonicSensorEvent.ObjectDetected: this.movementThreshold; break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//% fixedInstance whenUsed block="ultrasonic 4" jres=icons.port4
|
||||
export const ultrasonic4: UltraSonicSensor = new UltraSonicSensor(4)
|
||||
|
||||
|
||||
//% fixedInstance whenUsed block="ultrasonic 1" jres=icons.port1
|
||||
export const ultrasonic1: UltraSonicSensor = new UltraSonicSensor(1)
|
||||
|
||||
|
Reference in New Issue
Block a user