Add rgb and reflection raw mods for color sensor (#876)
* Add reflection raw value Add reflection raw value for color sensor * update * Combined rgbraw and refraw
This commit is contained in:
parent
312729142f
commit
79b5f8cc88
@ -93,6 +93,8 @@ namespace sensors {
|
|||||||
|| this.mode == ColorSensorMode.AmbientLightIntensity
|
|| this.mode == ColorSensorMode.AmbientLightIntensity
|
||||||
|| this.mode == ColorSensorMode.ReflectedLightIntensity)
|
|| this.mode == ColorSensorMode.ReflectedLightIntensity)
|
||||||
return this.getNumber(NumberFormat.UInt8LE, 0)
|
return this.getNumber(NumberFormat.UInt8LE, 0)
|
||||||
|
if (this.mode == ColorSensorMode.RefRaw || this.mode == ColorSensorMode.RgbRaw)
|
||||||
|
return this.getNumber(NumberFormat.UInt16LE, 0)
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,7 +116,7 @@ namespace sensors {
|
|||||||
|
|
||||||
_update(prev: number, curr: number) {
|
_update(prev: number, curr: number) {
|
||||||
if (this.calibrating) return; // simply ignore data updates while calibrating
|
if (this.calibrating) return; // simply ignore data updates while calibrating
|
||||||
if (this.mode == ColorSensorMode.Color)
|
if (this.mode == ColorSensorMode.Color || this.mode == ColorSensorMode.RgbRaw || this.mode == ColorSensorMode.RefRaw)
|
||||||
control.raiseEvent(this._id, this._colorEventValue(curr));
|
control.raiseEvent(this._id, this._colorEventValue(curr));
|
||||||
else
|
else
|
||||||
this.thresholdDetector.setLevel(curr);
|
this.thresholdDetector.setLevel(curr);
|
||||||
@ -179,6 +181,24 @@ namespace sensors {
|
|||||||
return this.getNumber(NumberFormat.UInt8LE, 0)
|
return this.getNumber(NumberFormat.UInt8LE, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the current raw rgb values from the color sensor.
|
||||||
|
* @param sensor the color sensor to query the request
|
||||||
|
*/
|
||||||
|
//% help=sensors/color-sensor/rgbraw
|
||||||
|
//% block="**color sensor** %this| rgbraw"
|
||||||
|
//% blockId=colorGetRgbRawColor
|
||||||
|
//% parts="colorsensor"
|
||||||
|
//% blockNamespace=sensors
|
||||||
|
//% this.fieldEditor="ports"
|
||||||
|
//% weight=98
|
||||||
|
//% group="Color Sensor"
|
||||||
|
//% blockGap=8
|
||||||
|
getRgbRaw() {
|
||||||
|
this.setMode(ColorSensorMode.RgbRaw);
|
||||||
|
return [this.getNumber(NumberFormat.UInt16LE, 0), this.getNumber(NumberFormat.UInt16LE, 2), this.getNumber(NumberFormat.UInt16LE, 4)];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers code to run when the ambient light changes.
|
* Registers code to run when the ambient light changes.
|
||||||
* @param condition the light condition
|
* @param condition the light condition
|
||||||
@ -248,6 +268,14 @@ namespace sensors {
|
|||||||
return this.light(LightIntensityMode.Reflected);
|
return this.light(LightIntensityMode.Reflected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the raw reflection light value
|
||||||
|
*/
|
||||||
|
getRefRaw() {
|
||||||
|
this.setMode(ColorSensorMode.RefRaw);
|
||||||
|
return this.getNumber(NumberFormat.UInt16LE, 0);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set a threshold value
|
* Set a threshold value
|
||||||
* @param condition the dark or bright light condition
|
* @param condition the dark or bright light condition
|
||||||
|
Loading…
Reference in New Issue
Block a user