Better fix for null dereferencing issue. Fix initial Color sensor mode (default).

This commit is contained in:
Sam El-Husseini
2018-01-02 22:51:12 -08:00
parent 02838e6c30
commit 955a2c9757
3 changed files with 5 additions and 3 deletions

View File

@ -56,6 +56,7 @@ namespace sensors {
constructor(port: number) {
super(port)
this._setMode(ColorSensorMode.None);
this.thresholdDetector = new sensors.internal.ThresholdDetector(this.id());
}
@ -94,7 +95,6 @@ namespace sensors {
}
_update(prev: number, curr: number) {
if (curr == null) return;
if (this.mode == ColorSensorMode.Color)
control.raiseEvent(this._id, this._colorEventValue(curr));
else

View File

@ -68,7 +68,7 @@ namespace sensors.internal {
if (info.sensor) return info.sensor._query()
return 0
}, (prev, curr) => {
if (info.sensor) info.sensor._update(prev, curr)
if (info.sensor && curr !== null) info.sensor._update(prev, curr)
})
}