From a4a9af28a4e97dafa425122318f2e6e2930a184b Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Wed, 11 Apr 2018 09:58:34 -0600 Subject: [PATCH] Switch to reflected light when calling threshold (#489) * fix typo * fixing threshold functions * switch to reflected mode when calling threshold --- libs/color-sensor/color.ts | 12 +++++++++++- libs/infrared-sensor/ir.ts | 2 +- libs/ultrasonic-sensor/ultrasonic.ts | 4 ++-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/libs/color-sensor/color.ts b/libs/color-sensor/color.ts index 63fcd37f..33f61a2b 100644 --- a/libs/color-sensor/color.ts +++ b/libs/color-sensor/color.ts @@ -253,6 +253,11 @@ namespace sensors { //% this.fieldEditor="ports" //% help=sensors/color-sensor/set-threshold setThreshold(condition: Light, value: number) { + // threshold is used in ambient or reflected modes + if (this.mode != LightIntensityMode.Ambient && + this.mode != LightIntensityMode.Reflected) + this.setMode(ColorSensorMode.ReflectedLightIntensity); + if (condition == Light.Dark) this.thresholdDetector.setLowThreshold(value) else @@ -268,7 +273,12 @@ namespace sensors { //% this.fieldEditor="ports" //% help=sensors/color-sensor/threshold threshold(condition: Light): number { - return this.thresholdDetector.threshold(Light.Dark); + // threshold is used in ambient or reflected modes + if (this.mode != LightIntensityMode.Ambient && + this.mode != LightIntensityMode.Reflected) + this.setMode(ColorSensorMode.ReflectedLightIntensity); + + return this.thresholdDetector.threshold(condition); } /** diff --git a/libs/infrared-sensor/ir.ts b/libs/infrared-sensor/ir.ts index bdfbf321..1a11b2eb 100644 --- a/libs/infrared-sensor/ir.ts +++ b/libs/infrared-sensor/ir.ts @@ -279,7 +279,7 @@ namespace sensors { //% group="Threshold" blockGap=8 weight=49 //% this.fieldEditor="ports" proximityThreshold(condition: InfraredSensorEvent): number { - return this._proximityThreshold.threshold(Light.Dark); + return this._proximityThreshold.threshold(condition); } // TODO diff --git a/libs/ultrasonic-sensor/ultrasonic.ts b/libs/ultrasonic-sensor/ultrasonic.ts index 42d4e05c..f0a1c13b 100644 --- a/libs/ultrasonic-sensor/ultrasonic.ts +++ b/libs/ultrasonic-sensor/ultrasonic.ts @@ -115,8 +115,8 @@ namespace sensors { //% this.fieldEditor="ports" threshold(condition: UltrasonicSensorEvent): number { switch (condition) { - case UltrasonicSensorEvent.ObjectNear: this.promixityThreshold.threshold(ThresholdState.Low); break; - case UltrasonicSensorEvent.ObjectDetected: this.movementThreshold; break; + case UltrasonicSensorEvent.ObjectNear: return this.promixityThreshold.threshold(ThresholdState.Low); + case UltrasonicSensorEvent.ObjectDetected: return this.movementThreshold; } return 0; }