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