updated naming

This commit is contained in:
Peli de Halleux 2017-11-29 21:57:05 -08:00
parent 4d2b7ced71
commit 97663d2b83
3 changed files with 58 additions and 46 deletions

View File

@ -1,8 +1,9 @@
{ {
"sensors.ColorSensor": "The color sensor is a digital sensor that can detect the color or intensity\nof light that enters the small window on the face of the sensor.",
"sensors.ColorSensor.ambientLight": "Get current ambient light value from the color sensor.", "sensors.ColorSensor.ambientLight": "Get current ambient light value from the color sensor.",
"sensors.ColorSensor.color": "Get the current color from the color sensor.", "sensors.ColorSensor.color": "Get the current color from the color sensor.",
"sensors.ColorSensor.colorMode": "Gets the current color mode", "sensors.ColorSensor.colorMode": "Gets the current color mode",
"sensors.ColorSensor.onColorDetected": "Registers code to run when the given color is detected", "sensors.ColorSensor.onColorDetected": "Registers code to run when the given color is detected.",
"sensors.ColorSensor.onColorDetected|param|color": "the color to detect, eg: ColorSensorColor.Blue", "sensors.ColorSensor.onColorDetected|param|color": "the color to detect, eg: ColorSensorColor.Blue",
"sensors.ColorSensor.onColorDetected|param|handler": "the code to run when detected", "sensors.ColorSensor.onColorDetected|param|handler": "the code to run when detected",
"sensors.ColorSensor.reflectedLight": "Get current reflected light value from the color sensor." "sensors.ColorSensor.reflectedLight": "Get current reflected light value from the color sensor."

View File

@ -7,14 +7,18 @@
"ColorSensorColor.Red|block": "red", "ColorSensorColor.Red|block": "red",
"ColorSensorColor.White|block": "white", "ColorSensorColor.White|block": "white",
"ColorSensorColor.Yellow|block": "yellow", "ColorSensorColor.Yellow|block": "yellow",
"ColorSensorMode.AmbientLightIntensity|block": "ambient light intensity",
"ColorSensorMode.Color|block": "color",
"ColorSensorMode.ReflectedLightIntensity|block": "reflected light intensity",
"sensors.ColorSensor.ambientLight|block": "`icons.colorSensor` %color| ambient light", "sensors.ColorSensor.ambientLight|block": "`icons.colorSensor` %color| ambient light",
"sensors.ColorSensor.color|block": "`icons.colorSensor` %color| color", "sensors.ColorSensor.color|block": "`icons.colorSensor` %color| color",
"sensors.ColorSensor.onColorDetected|block": "on `icons.colorSensor` %sensor|detected color %color", "sensors.ColorSensor.onColorDetected|block": "on `icons.colorSensor` %sensor|detected color %color",
"sensors.ColorSensor.reflectedLight|block": "`icons.colorSensor` %color| reflected light", "sensors.ColorSensor.reflectedLight|block": "`icons.colorSensor` %color| reflected light",
"sensors.color1|block": "1", "sensors.colorSensor1|block": "1",
"sensors.color2|block": "2", "sensors.colorSensor2|block": "2",
"sensors.color3|block": "3", "sensors.colorSensor3|block": "3",
"sensors.color4|block": "4", "sensors.colorSensor4|block": "4",
"sensors|block": "sensors",
"{id:category}Sensors": "Sensors", "{id:category}Sensors": "Sensors",
"{id:group}Color Sensor": "Color Sensor" "{id:group}Color Sensor": "Color Sensor"
} }

View File

@ -1,7 +1,10 @@
const enum ColorSensorMode { const enum ColorSensorMode {
None = -1, None = -1,
Reflect = 0, //% block="reflected light intensity"
Ambient = 1, ReflectedLightIntensity = 0,
//% block="ambient light intensity"
AmbientLightIntensity = 1,
//% block="color"
Color = 2, Color = 2,
RefRaw = 3, RefRaw = 3,
RgbRaw = 4, RgbRaw = 4,
@ -29,6 +32,10 @@ const enum ColorSensorColor {
namespace sensors { namespace sensors {
/**
* The color sensor is a digital sensor that can detect the color or intensity
* of light that enters the small window on the face of the sensor.
*/
//% fixedInstances //% fixedInstances
export class ColorSensor extends internal.UartSensor { export class ColorSensor extends internal.UartSensor {
constructor(port: number) { constructor(port: number) {
@ -62,11 +69,11 @@ namespace sensors {
} }
/** /**
* Registers code to run when the given color is detected * Registers code to run when the given color is detected.
* @param color the color to detect, eg: ColorSensorColor.Blue * @param color the color to detect, eg: ColorSensorColor.Blue
* @param handler the code to run when detected * @param handler the code to run when detected
*/ */
//% help=input/color/on-color-detected //% help=sensors/color-sensor/on-color-detected
//% block="on `icons.colorSensor` %sensor|detected color %color" //% block="on `icons.colorSensor` %sensor|detected color %color"
//% blockId=colorOnColorDetected //% blockId=colorOnColorDetected
//% parts="colorsensor" //% parts="colorsensor"
@ -80,43 +87,11 @@ namespace sensors {
control.raiseEvent(this._id, <number>color); control.raiseEvent(this._id, <number>color);
} }
/**
* Get current ambient light value from the color sensor.
* @param color the color sensor to query the request
*/
//% help=input/color/ambient-light
//% block="`icons.colorSensor` %color| ambient light"
//% blockId=colorGetAmbient
//% parts="colorsensor"
//% blockNamespace=sensors
//% weight=65 blockGap=8
//% group="Color Sensor"
ambientLight() {
this.setColorMode(ColorSensorMode.Ambient)
return this.getNumber(NumberFormat.UInt8LE, 0)
}
/**
* Get current reflected light value from the color sensor.
* @param color the color sensor to query the request
*/
//% help=input/color/refelected-light
//% block="`icons.colorSensor` %color| reflected light"
//% blockId=colorGetReflected
//% parts="colorsensor"
//% blockNamespace=sensors
//% weight=64 blockGap=8
//% group="Color Sensor"
reflectedLight(): number {
this.setColorMode(ColorSensorMode.Reflect)
return this.getNumber(NumberFormat.UInt8LE, 0)
}
/** /**
* Get the current color from the color sensor. * Get the current color from the color sensor.
* @param color the color sensor to query the request * @param color the color sensor to query the request
*/ */
//% help=input/color/color //% help=sensors/color-sensor/color
//% block="`icons.colorSensor` %color| color" //% block="`icons.colorSensor` %color| color"
//% blockId=colorGetColor //% blockId=colorGetColor
//% parts="colorsensor" //% parts="colorsensor"
@ -127,17 +102,49 @@ namespace sensors {
this.setColorMode(ColorSensorMode.Color) this.setColorMode(ColorSensorMode.Color)
return this.getNumber(NumberFormat.UInt8LE, 0) return this.getNumber(NumberFormat.UInt8LE, 0)
} }
/**
* Get current ambient light value from the color sensor.
* @param color the color sensor to query the request
*/
//% help=sensors/color-sensor/ambient-light
//% block="`icons.colorSensor` %color| ambient light"
//% blockId=colorGetAmbient
//% parts="colorsensor"
//% blockNamespace=sensors
//% weight=65 blockGap=8
//% group="Color Sensor"
ambientLight() {
this.setColorMode(ColorSensorMode.AmbientLightIntensity)
return this.getNumber(NumberFormat.UInt8LE, 0)
}
/**
* Get current reflected light value from the color sensor.
* @param color the color sensor to query the request
*/
//% help=sensors/color-sensor/reflected-light
//% block="`icons.colorSensor` %color| reflected light"
//% blockId=colorGetReflected
//% parts="colorsensor"
//% blockNamespace=sensors
//% weight=64 blockGap=8
//% group="Color Sensor"
reflectedLight(): number {
this.setColorMode(ColorSensorMode.ReflectedLightIntensity)
return this.getNumber(NumberFormat.UInt8LE, 0)
}
} }
//% whenUsed block="1" weight=95 fixedInstance //% whenUsed block="1" weight=95 fixedInstance
export const color1: ColorSensor = new ColorSensor(1) export const colorSensor1: ColorSensor = new ColorSensor(1)
//% whenUsed block="3" weight=90 fixedInstance //% whenUsed block="3" weight=90 fixedInstance
export const color3: ColorSensor = new ColorSensor(3) export const colorSensor3: ColorSensor = new ColorSensor(3)
//% whenUsed block="2" weight=90 fixedInstance //% whenUsed block="2" weight=90 fixedInstance
export const color2: ColorSensor = new ColorSensor(2) export const colorSensor2: ColorSensor = new ColorSensor(2)
//% whenUsed block="4" weight=90 fixedInstance //% whenUsed block="4" weight=90 fixedInstance
export const color4: ColorSensor = new ColorSensor(4) export const colorSensor4: ColorSensor = new ColorSensor(4)
} }