set mode then poke
This commit is contained in:
parent
f1d9075c9d
commit
1bbf8a4473
@ -59,9 +59,9 @@ namespace sensors {
|
|||||||
|
|
||||||
constructor(port: number) {
|
constructor(port: number) {
|
||||||
super(port)
|
super(port)
|
||||||
this._setMode(ColorSensorMode.None);
|
|
||||||
this.thresholdDetector = new sensors.ThresholdDetector(this.id());
|
this.thresholdDetector = new sensors.ThresholdDetector(this.id());
|
||||||
this.calibrating = false;
|
this.calibrating = false;
|
||||||
|
this.setMode(ColorSensorMode.ReflectedLightIntensity);
|
||||||
}
|
}
|
||||||
|
|
||||||
_colorEventValue(value: number) {
|
_colorEventValue(value: number) {
|
||||||
@ -176,8 +176,8 @@ namespace sensors {
|
|||||||
//% group="Color Sensor"
|
//% group="Color Sensor"
|
||||||
//% blockGap=8
|
//% blockGap=8
|
||||||
color(): ColorSensorColor {
|
color(): ColorSensorColor {
|
||||||
this.poke();
|
|
||||||
this.setMode(ColorSensorMode.Color)
|
this.setMode(ColorSensorMode.Color)
|
||||||
|
this.poke();
|
||||||
return this.getNumber(NumberFormat.UInt8LE, 0)
|
return this.getNumber(NumberFormat.UInt8LE, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -194,8 +194,8 @@ namespace sensors {
|
|||||||
//% group="Color Sensor"
|
//% group="Color Sensor"
|
||||||
//% blockGap=8
|
//% blockGap=8
|
||||||
rgbRaw(): number[] {
|
rgbRaw(): number[] {
|
||||||
this.poke();
|
|
||||||
this.setMode(ColorSensorMode.RgbRaw);
|
this.setMode(ColorSensorMode.RgbRaw);
|
||||||
|
this.poke();
|
||||||
return [this.getNumber(NumberFormat.UInt16LE, 0), this.getNumber(NumberFormat.UInt16LE, 2), this.getNumber(NumberFormat.UInt16LE, 4)];
|
return [this.getNumber(NumberFormat.UInt16LE, 0), this.getNumber(NumberFormat.UInt16LE, 2), this.getNumber(NumberFormat.UInt16LE, 4)];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -248,8 +248,8 @@ namespace sensors {
|
|||||||
//% weight=87 blockGap=8
|
//% weight=87 blockGap=8
|
||||||
//% group="Color Sensor"
|
//% group="Color Sensor"
|
||||||
light(mode: LightIntensityMode) {
|
light(mode: LightIntensityMode) {
|
||||||
this.poke();
|
|
||||||
this.setMode(<ColorSensorMode><number>mode)
|
this.setMode(<ColorSensorMode><number>mode)
|
||||||
|
this.poke();
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case LightIntensityMode.ReflectedRaw:
|
case LightIntensityMode.ReflectedRaw:
|
||||||
return this.reflectedLightRaw();
|
return this.reflectedLightRaw();
|
||||||
@ -279,8 +279,8 @@ namespace sensors {
|
|||||||
*/
|
*/
|
||||||
//%
|
//%
|
||||||
reflectedLightRaw(): number {
|
reflectedLightRaw(): number {
|
||||||
this.poke();
|
|
||||||
this.setMode(ColorSensorMode.RefRaw);
|
this.setMode(ColorSensorMode.RefRaw);
|
||||||
|
this.poke();
|
||||||
return this.getNumber(NumberFormat.UInt16LE, 0);
|
return this.getNumber(NumberFormat.UInt16LE, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,7 +82,7 @@ namespace sensors.internal {
|
|||||||
poller: Poller;
|
poller: Poller;
|
||||||
|
|
||||||
constructor(p: number) {
|
constructor(p: number) {
|
||||||
this.port = p
|
this.port = p; // 0-based
|
||||||
this.connType = DAL.CONN_NONE
|
this.connType = DAL.CONN_NONE
|
||||||
this.devType = DAL.DEVICE_TYPE_NONE
|
this.devType = DAL.DEVICE_TYPE_NONE
|
||||||
this.iicid = ''
|
this.iicid = ''
|
||||||
@ -279,6 +279,7 @@ void cUiUpdatePower(void)
|
|||||||
for (let i = 0; i < conns.length; ++i) {
|
for (let i = 0; i < conns.length; ++i) {
|
||||||
r = (r << 8 | conns[i]);
|
r = (r << 8 | conns[i]);
|
||||||
}
|
}
|
||||||
|
//control.dmesg(`devices hash: ${r}`);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -445,20 +446,20 @@ void cUiUpdatePower(void)
|
|||||||
constructor(port: number) {
|
constructor(port: number) {
|
||||||
super(port)
|
super(port)
|
||||||
this.mode = 0
|
this.mode = 0
|
||||||
this.realmode = 0
|
this.realmode = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
_activated() {
|
_activated() {
|
||||||
this.realmode = 0
|
this.realmode = 0;
|
||||||
this._setMode(this.mode)
|
this._setMode(this.mode)
|
||||||
}
|
}
|
||||||
|
|
||||||
protected _setMode(m: number) {
|
protected _setMode(m: number) {
|
||||||
//control.dmesg(`_setMode p=${this.port} m: ${this.realmode} -> ${m}`)
|
|
||||||
let v = m | 0
|
let v = m | 0
|
||||||
this.mode = v
|
this.mode = v
|
||||||
if (!this.isActive()) return
|
if (!this.isActive()) return
|
||||||
if (this.realmode != this.mode) {
|
if (this.realmode != this.mode) {
|
||||||
|
control.dmesg(`_setMode p=${this._port} m: ${this.realmode} -> ${v}`)
|
||||||
this.realmode = v
|
this.realmode = v
|
||||||
setUartMode(this._port, v)
|
setUartMode(this._port, v)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user