Add color sensor

This commit is contained in:
Michal Moskal 2017-07-10 14:43:54 +01:00
parent df45cb98ef
commit babdf45fc3
5 changed files with 67 additions and 2 deletions

56
libs/core/color.ts Normal file
View File

@ -0,0 +1,56 @@
const enum ColorSensorMode {
None = -1,
Reflect = 0,
Ambient = 1,
Color = 2,
RefRaw = 3,
RgbRaw = 4,
ColorCal = 5,
}
const enum ColorSensorColor {
None,
Black,
Blue,
Green,
Yellow,
Red,
White,
Brown,
}
namespace input {
export class ColorSensor extends internal.UartSensor {
constructor() {
super()
this.mode = ColorSensorMode.Reflect
}
_deviceType() {
return LMS.DEVICE_TYPE_COLOR
}
setMode(m: ColorSensorMode) {
this._setMode(m)
}
getAmbientLight() {
this.setMode(ColorSensorMode.Ambient)
return this.getNumber(NumberFormat.UInt8LE, 0)
}
getReflectedLight() {
this.setMode(ColorSensorMode.Reflect)
return this.getNumber(NumberFormat.UInt8LE, 0)
}
getColor(): ColorSensorColor {
this.setMode(ColorSensorMode.Color)
return this.getNumber(NumberFormat.UInt8LE, 0)
}
}
//% whenUsed
export const color: ColorSensor = new ColorSensor()
}

View File

@ -28,6 +28,7 @@ const enum LMS {
DEVICE_TYPE_MINITACHO = 8,
DEVICE_TYPE_NEWTACHO = 9,
DEVICE_TYPE_TOUCH = 16,
DEVICE_TYPE_COLOR = 29,
DEVICE_TYPE_IR = 33,
DEVICE_TYPE_THIRD_PARTY_START = 50,
DEVICE_TYPE_THIRD_PARTY_END = 99,

View File

@ -42,7 +42,6 @@ namespace input {
export class IrSensor extends internal.UartSensor {
private channel: IrRemoteChannel
private pollRunning: boolean
private buttons: Button[];
constructor() {

View File

@ -17,6 +17,7 @@
"core.ts",
"input.ts",
"ir.ts",
"color.ts",
"touch.ts",
"shims.d.ts",
"enums.d.ts",

View File

@ -46,5 +46,13 @@ input.remoteTopRight.onEvent(ButtonEvent.Down, () => {
loops.forever(() => {
serial.writeDmesg()
loops.pause(400)
loops.pause(100)
})
/*
loops.forever(() => {
let v = input.color.getColor()
screen.drawText(10, 60, v + " ")
loops.pause(200)
})
*/