avoid conflicts of event values
This commit is contained in:
parent
39b7f99741
commit
4ed41adb6a
@ -59,6 +59,10 @@ namespace sensors {
|
||||
this.thresholdDetector = new sensors.internal.ThresholdDetector(this.id());
|
||||
}
|
||||
|
||||
_colorEventValue(value: number) {
|
||||
return 0xff00 | value;
|
||||
}
|
||||
|
||||
_deviceType() {
|
||||
return DAL.DEVICE_TYPE_COLOR
|
||||
}
|
||||
@ -82,7 +86,7 @@ namespace sensors {
|
||||
|
||||
_update(prev: number, curr: number) {
|
||||
if (this.mode == ColorSensorMode.Color)
|
||||
control.raiseEvent(this._id, curr);
|
||||
control.raiseEvent(this._id, this._colorEventValue(curr));
|
||||
else
|
||||
this.thresholdDetector.setLevel(curr);
|
||||
}
|
||||
@ -100,10 +104,11 @@ namespace sensors {
|
||||
//% weight=100 blockGap=8
|
||||
//% group="Color Sensor"
|
||||
onColorDetected(color: ColorSensorColor, handler: () => void) {
|
||||
control.onEvent(this._id, <number>color, handler);
|
||||
const v = this._colorEventValue(<number>color);
|
||||
control.onEvent(this._id, v, handler);
|
||||
this.setMode(ColorSensorMode.Color)
|
||||
if (this.color() == color)
|
||||
control.raiseEvent(this._id, <number>color);
|
||||
control.raiseEvent(this._id, v);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user