Better fix for null dereferencing issue. Fix initial Color sensor mode (default).
This commit is contained in:
parent
02838e6c30
commit
955a2c9757
@ -56,6 +56,7 @@ namespace sensors {
|
|||||||
|
|
||||||
constructor(port: number) {
|
constructor(port: number) {
|
||||||
super(port)
|
super(port)
|
||||||
|
this._setMode(ColorSensorMode.None);
|
||||||
this.thresholdDetector = new sensors.internal.ThresholdDetector(this.id());
|
this.thresholdDetector = new sensors.internal.ThresholdDetector(this.id());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,7 +95,6 @@ namespace sensors {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_update(prev: number, curr: number) {
|
_update(prev: number, curr: number) {
|
||||||
if (curr == null) return;
|
|
||||||
if (this.mode == ColorSensorMode.Color)
|
if (this.mode == ColorSensorMode.Color)
|
||||||
control.raiseEvent(this._id, this._colorEventValue(curr));
|
control.raiseEvent(this._id, this._colorEventValue(curr));
|
||||||
else
|
else
|
||||||
|
@ -68,7 +68,7 @@ namespace sensors.internal {
|
|||||||
if (info.sensor) return info.sensor._query()
|
if (info.sensor) return info.sensor._query()
|
||||||
return 0
|
return 0
|
||||||
}, (prev, curr) => {
|
}, (prev, curr) => {
|
||||||
if (info.sensor) info.sensor._update(prev, curr)
|
if (info.sensor && curr !== null) info.sensor._update(prev, curr)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,12 +3,13 @@
|
|||||||
namespace pxsim {
|
namespace pxsim {
|
||||||
|
|
||||||
export enum ColorSensorMode {
|
export enum ColorSensorMode {
|
||||||
|
None = -1,
|
||||||
Reflected = 0,
|
Reflected = 0,
|
||||||
Ambient = 1,
|
Ambient = 1,
|
||||||
Colors = 2,
|
Colors = 2,
|
||||||
RefRaw = 3,
|
RefRaw = 3,
|
||||||
RgbRaw = 4,
|
RgbRaw = 4,
|
||||||
ColorCal = 5
|
ColorCal = 5,
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum ThresholdState {
|
export enum ThresholdState {
|
||||||
@ -24,6 +25,7 @@ namespace pxsim {
|
|||||||
|
|
||||||
constructor(port: number) {
|
constructor(port: number) {
|
||||||
super(port);
|
super(port);
|
||||||
|
this.mode = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
getDeviceType() {
|
getDeviceType() {
|
||||||
|
Loading…
Reference in New Issue
Block a user