moving color sensor to separate project
This commit is contained in:
parent
5676103052
commit
4d2b7ced71
3
libs/color-sensor/README.md
Normal file
3
libs/color-sensor/README.md
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# Color sensor
|
||||||
|
|
||||||
|
The library to interact with the Touch Sensor.
|
@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"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.colorMode": "Gets the current color mode",
|
||||||
|
"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|handler": "the code to run when detected",
|
||||||
|
"sensors.ColorSensor.reflectedLight": "Get current reflected light value from the color sensor."
|
||||||
|
}
|
20
libs/color-sensor/_locales/color-sensor-strings.json
Normal file
20
libs/color-sensor/_locales/color-sensor-strings.json
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
"ColorSensorColor.Black|block": "black",
|
||||||
|
"ColorSensorColor.Blue|block": "blue",
|
||||||
|
"ColorSensorColor.Brown|block": "brown",
|
||||||
|
"ColorSensorColor.Green|block": "green",
|
||||||
|
"ColorSensorColor.None|block": "none",
|
||||||
|
"ColorSensorColor.Red|block": "red",
|
||||||
|
"ColorSensorColor.White|block": "white",
|
||||||
|
"ColorSensorColor.Yellow|block": "yellow",
|
||||||
|
"sensors.ColorSensor.ambientLight|block": "`icons.colorSensor` %color| ambient light",
|
||||||
|
"sensors.ColorSensor.color|block": "`icons.colorSensor` %color| color",
|
||||||
|
"sensors.ColorSensor.onColorDetected|block": "on `icons.colorSensor` %sensor|detected color %color",
|
||||||
|
"sensors.ColorSensor.reflectedLight|block": "`icons.colorSensor` %color| reflected light",
|
||||||
|
"sensors.color1|block": "1",
|
||||||
|
"sensors.color2|block": "2",
|
||||||
|
"sensors.color3|block": "3",
|
||||||
|
"sensors.color4|block": "4",
|
||||||
|
"{id:category}Sensors": "Sensors",
|
||||||
|
"{id:group}Color Sensor": "Color Sensor"
|
||||||
|
}
|
@ -39,10 +39,17 @@ namespace sensors {
|
|||||||
return DAL.DEVICE_TYPE_COLOR
|
return DAL.DEVICE_TYPE_COLOR
|
||||||
}
|
}
|
||||||
|
|
||||||
setMode(m: ColorSensorMode) {
|
setColorMode(m: ColorSensorMode) {
|
||||||
this._setMode(m)
|
this._setMode(m)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the current color mode
|
||||||
|
*/
|
||||||
|
colorMode() {
|
||||||
|
return <ColorSensorMode>this.mode;
|
||||||
|
}
|
||||||
|
|
||||||
_query() {
|
_query() {
|
||||||
if (this.mode == ColorSensorMode.Color)
|
if (this.mode == ColorSensorMode.Color)
|
||||||
return this.getNumber(NumberFormat.UInt8LE, 0)
|
return this.getNumber(NumberFormat.UInt8LE, 0)
|
||||||
@ -50,16 +57,17 @@ namespace sensors {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_update(prev: number, curr: number) {
|
_update(prev: number, curr: number) {
|
||||||
|
if (this.mode == ColorSensorMode.Color)
|
||||||
control.raiseEvent(this._id, curr);
|
control.raiseEvent(this._id, curr);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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 dtect
|
* @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=input/color/on-color-detected
|
||||||
//% block="on `icons.colorSensor` %sensor|detected %color"
|
//% block="on `icons.colorSensor` %sensor|detected color %color"
|
||||||
//% blockId=colorOnColorDetected
|
//% blockId=colorOnColorDetected
|
||||||
//% parts="colorsensor"
|
//% parts="colorsensor"
|
||||||
//% blockNamespace=sensors
|
//% blockNamespace=sensors
|
||||||
@ -67,9 +75,9 @@ namespace sensors {
|
|||||||
//% group="Color Sensor"
|
//% group="Color Sensor"
|
||||||
onColorDetected(color: ColorSensorColor, handler: () => void) {
|
onColorDetected(color: ColorSensorColor, handler: () => void) {
|
||||||
control.onEvent(this._id, <number>color, handler);
|
control.onEvent(this._id, <number>color, handler);
|
||||||
this.setMode(ColorSensorMode.Color)
|
this.setColorMode(ColorSensorMode.Color)
|
||||||
if (this.color() == color)
|
if (this.color() == color)
|
||||||
control.runInBackground(handler)
|
control.raiseEvent(this._id, <number>color);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -84,7 +92,7 @@ namespace sensors {
|
|||||||
//% weight=65 blockGap=8
|
//% weight=65 blockGap=8
|
||||||
//% group="Color Sensor"
|
//% group="Color Sensor"
|
||||||
ambientLight() {
|
ambientLight() {
|
||||||
this.setMode(ColorSensorMode.Ambient)
|
this.setColorMode(ColorSensorMode.Ambient)
|
||||||
return this.getNumber(NumberFormat.UInt8LE, 0)
|
return this.getNumber(NumberFormat.UInt8LE, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,7 +108,7 @@ namespace sensors {
|
|||||||
//% weight=64 blockGap=8
|
//% weight=64 blockGap=8
|
||||||
//% group="Color Sensor"
|
//% group="Color Sensor"
|
||||||
reflectedLight(): number {
|
reflectedLight(): number {
|
||||||
this.setMode(ColorSensorMode.Reflect)
|
this.setColorMode(ColorSensorMode.Reflect)
|
||||||
return this.getNumber(NumberFormat.UInt8LE, 0)
|
return this.getNumber(NumberFormat.UInt8LE, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,7 +124,7 @@ namespace sensors {
|
|||||||
//% weight=66 blockGap=8
|
//% weight=66 blockGap=8
|
||||||
//% group="Color Sensor"
|
//% group="Color Sensor"
|
||||||
color(): ColorSensorColor {
|
color(): ColorSensorColor {
|
||||||
this.setMode(ColorSensorMode.Color)
|
this.setColorMode(ColorSensorMode.Color)
|
||||||
return this.getNumber(NumberFormat.UInt8LE, 0)
|
return this.getNumber(NumberFormat.UInt8LE, 0)
|
||||||
}
|
}
|
||||||
}
|
}
|
15
libs/color-sensor/pxt.json
Normal file
15
libs/color-sensor/pxt.json
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"name": "color-sensor",
|
||||||
|
"description": "Color Sensor support",
|
||||||
|
"files": [
|
||||||
|
"README.md",
|
||||||
|
"color.ts"
|
||||||
|
],
|
||||||
|
"testFiles": [
|
||||||
|
"test.ts"
|
||||||
|
],
|
||||||
|
"public": true,
|
||||||
|
"dependencies": {
|
||||||
|
"core": "file:../core"
|
||||||
|
}
|
||||||
|
}
|
0
libs/color-sensor/test.ts
Normal file
0
libs/color-sensor/test.ts
Normal file
@ -68,12 +68,6 @@
|
|||||||
"screen.clear": "Clear screen and reset font to normal.",
|
"screen.clear": "Clear screen and reset font to normal.",
|
||||||
"screen.imageOf": "Makes an image bound to a buffer.",
|
"screen.imageOf": "Makes an image bound to a buffer.",
|
||||||
"screen.unpackPNG": "Decompresses a 1-bit gray scale PNG image to image format.",
|
"screen.unpackPNG": "Decompresses a 1-bit gray scale PNG image to image format.",
|
||||||
"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.onColorDetected": "Registers code to run when the given color is detected",
|
|
||||||
"sensors.ColorSensor.onColorDetected|param|color": "the color to dtect",
|
|
||||||
"sensors.ColorSensor.onColorDetected|param|handler": "the code to run when detected",
|
|
||||||
"sensors.ColorSensor.reflectedLight": "Get current reflected light value from the color sensor.",
|
|
||||||
"sensors.GyroSensor.angle": "Get the current angle from the gyroscope.",
|
"sensors.GyroSensor.angle": "Get the current angle from the gyroscope.",
|
||||||
"sensors.GyroSensor.rate": "Get the current rotation rate from the gyroscope.",
|
"sensors.GyroSensor.rate": "Get the current rotation rate from the gyroscope.",
|
||||||
"sensors.InfraredSensor.on": "Registers code to run when an object is getting near.",
|
"sensors.InfraredSensor.on": "Registers code to run when an object is getting near.",
|
||||||
|
@ -2,14 +2,6 @@
|
|||||||
"ButtonEvent.Click|block": "click",
|
"ButtonEvent.Click|block": "click",
|
||||||
"ButtonEvent.Down|block": "down",
|
"ButtonEvent.Down|block": "down",
|
||||||
"ButtonEvent.Up|block": "up",
|
"ButtonEvent.Up|block": "up",
|
||||||
"ColorSensorColor.Black|block": "black",
|
|
||||||
"ColorSensorColor.Blue|block": "blue",
|
|
||||||
"ColorSensorColor.Brown|block": "brown",
|
|
||||||
"ColorSensorColor.Green|block": "green",
|
|
||||||
"ColorSensorColor.None|block": "none",
|
|
||||||
"ColorSensorColor.Red|block": "red",
|
|
||||||
"ColorSensorColor.White|block": "white",
|
|
||||||
"ColorSensorColor.Yellow|block": "yellow",
|
|
||||||
"InfraredSensorEvent.ObjectDetected|block": "object detected",
|
"InfraredSensorEvent.ObjectDetected|block": "object detected",
|
||||||
"InfraredSensorEvent.ObjectNear|block": "object near",
|
"InfraredSensorEvent.ObjectNear|block": "object near",
|
||||||
"LightsPattern.GreenFlash|block": "Flashing Green",
|
"LightsPattern.GreenFlash|block": "Flashing Green",
|
||||||
@ -66,10 +58,6 @@
|
|||||||
"motors|block": "motors",
|
"motors|block": "motors",
|
||||||
"output|block": "output",
|
"output|block": "output",
|
||||||
"screen|block": "screen",
|
"screen|block": "screen",
|
||||||
"sensors.ColorSensor.ambientLight|block": "`icons.colorSensor` %color| ambient light",
|
|
||||||
"sensors.ColorSensor.color|block": "`icons.colorSensor` %color| color",
|
|
||||||
"sensors.ColorSensor.onColorDetected|block": "on `icons.colorSensor` %sensor|detected %color",
|
|
||||||
"sensors.ColorSensor.reflectedLight|block": "`icons.colorSensor` %color| reflected light",
|
|
||||||
"sensors.GyroSensor.angle|block": "`icons.gyroSensor` %sensor|angle",
|
"sensors.GyroSensor.angle|block": "`icons.gyroSensor` %sensor|angle",
|
||||||
"sensors.GyroSensor.rate|block": "`icons.gyroSensor` %sensor|rotation rate",
|
"sensors.GyroSensor.rate|block": "`icons.gyroSensor` %sensor|rotation rate",
|
||||||
"sensors.InfraredSensor.on|block": "on `icons.infraredSensor` %sensor|%event",
|
"sensors.InfraredSensor.on|block": "on `icons.infraredSensor` %sensor|%event",
|
||||||
@ -82,10 +70,6 @@
|
|||||||
"sensors.UltraSonicSensor.distance|block": "`icons.ultrasonicSensor` %sensor|distance",
|
"sensors.UltraSonicSensor.distance|block": "`icons.ultrasonicSensor` %sensor|distance",
|
||||||
"sensors.UltraSonicSensor.on|block": "on `icons.ultrasonicSensor` %sensor|%event",
|
"sensors.UltraSonicSensor.on|block": "on `icons.ultrasonicSensor` %sensor|%event",
|
||||||
"sensors.UltraSonicSensor.wait|block": "wait `icons.ultrasonicSensor` %sensor|for %event",
|
"sensors.UltraSonicSensor.wait|block": "wait `icons.ultrasonicSensor` %sensor|for %event",
|
||||||
"sensors.color1|block": "1",
|
|
||||||
"sensors.color2|block": "2",
|
|
||||||
"sensors.color3|block": "3",
|
|
||||||
"sensors.color4|block": "4",
|
|
||||||
"sensors.gyro1|block": "1",
|
"sensors.gyro1|block": "1",
|
||||||
"sensors.gyro2|block": "2",
|
"sensors.gyro2|block": "2",
|
||||||
"sensors.gyro3|block": "3",
|
"sensors.gyro3|block": "3",
|
||||||
@ -116,7 +100,6 @@
|
|||||||
"{id:category}Sensors": "Sensors",
|
"{id:category}Sensors": "Sensors",
|
||||||
"{id:category}Serial": "Serial",
|
"{id:category}Serial": "Serial",
|
||||||
"{id:group}Buttons": "Buttons",
|
"{id:group}Buttons": "Buttons",
|
||||||
"{id:group}Color Sensor": "Color Sensor",
|
|
||||||
"{id:group}Gyro Sensor": "Gyro Sensor",
|
"{id:group}Gyro Sensor": "Gyro Sensor",
|
||||||
"{id:group}Infrared Sensor": "Infrared Sensor",
|
"{id:group}Infrared Sensor": "Infrared Sensor",
|
||||||
"{id:group}Light": "Light",
|
"{id:group}Light": "Light",
|
||||||
|
@ -19,7 +19,6 @@
|
|||||||
"core.ts",
|
"core.ts",
|
||||||
"input.ts",
|
"input.ts",
|
||||||
"ir.ts",
|
"ir.ts",
|
||||||
"color.ts",
|
|
||||||
"gyro.ts",
|
"gyro.ts",
|
||||||
"ultrasonic.ts",
|
"ultrasonic.ts",
|
||||||
"shims.d.ts",
|
"shims.d.ts",
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
"base": "file:../base",
|
"base": "file:../base",
|
||||||
"core": "file:../core",
|
"core": "file:../core",
|
||||||
"music": "file:../music",
|
"music": "file:../music",
|
||||||
|
"color-sensor": "file:../color-sensor",
|
||||||
"touch-sensor": "file:../touch-sensor"
|
"touch-sensor": "file:../touch-sensor"
|
||||||
},
|
},
|
||||||
"public": true
|
"public": true
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
"libs/base",
|
"libs/base",
|
||||||
"libs/core",
|
"libs/core",
|
||||||
"libs/music",
|
"libs/music",
|
||||||
|
"libs/color-sensor",
|
||||||
"libs/touch-sensor",
|
"libs/touch-sensor",
|
||||||
"libs/ev3"
|
"libs/ev3"
|
||||||
],
|
],
|
||||||
|
Loading…
Reference in New Issue
Block a user