diff --git a/libs/color-sensor/color.ts b/libs/color-sensor/color.ts index c1c624c1..391f7c52 100644 --- a/libs/color-sensor/color.ts +++ b/libs/color-sensor/color.ts @@ -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 diff --git a/libs/core/input.ts b/libs/core/input.ts index 896c8a3c..440dfbe8 100644 --- a/libs/core/input.ts +++ b/libs/core/input.ts @@ -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) }) } diff --git a/sim/state/color.ts b/sim/state/color.ts index ad5f7ac5..47392084 100644 --- a/sim/state/color.ts +++ b/sim/state/color.ts @@ -3,12 +3,13 @@ namespace pxsim { export enum ColorSensorMode { + None = -1, Reflected = 0, Ambient = 1, Colors = 2, RefRaw = 3, RgbRaw = 4, - ColorCal = 5 + ColorCal = 5, } export enum ThresholdState { @@ -24,6 +25,7 @@ namespace pxsim { constructor(port: number) { super(port); + this.mode = -1; } getDeviceType() {