Switch to reflected light when calling threshold (#489)

* fix typo

* fixing threshold functions

* switch to reflected mode when calling threshold
This commit is contained in:
Peli de Halleux 2018-04-11 09:58:34 -06:00 committed by GitHub
parent 6c253182e4
commit a4a9af28a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 4 deletions

View File

@ -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(<ThresholdState><number>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(<ThresholdState><number>condition);
}
/**

View File

@ -279,7 +279,7 @@ namespace sensors {
//% group="Threshold" blockGap=8 weight=49
//% this.fieldEditor="ports"
proximityThreshold(condition: InfraredSensorEvent): number {
return this._proximityThreshold.threshold(<ThresholdState><number>Light.Dark);
return this._proximityThreshold.threshold(<ThresholdState><number>condition);
}
// TODO

View File

@ -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;
}