Sensor names are now part of the block text (#341)
* Sensor names are now part of the block text * Use ports field editor
This commit is contained in:
		
				
					committed by
					
						
						GitHub
					
				
			
			
				
	
			
			
			
						parent
						
							2d355bb2ca
						
					
				
				
					commit
					130a47d684
				
			@@ -110,15 +110,15 @@ namespace sensors {
 | 
			
		||||
         * @param handler the code to run when detected
 | 
			
		||||
         */
 | 
			
		||||
        //% help=sensors/color-sensor/on-color-detected
 | 
			
		||||
        //% block="on %sensor|detected color %color"
 | 
			
		||||
        //% block="on **color** %this|detected color %color"
 | 
			
		||||
        //% blockId=colorOnColorDetected
 | 
			
		||||
        //% parts="colorsensor"
 | 
			
		||||
        //% blockNamespace=sensors
 | 
			
		||||
        //% sensor.fieldEditor="ports"
 | 
			
		||||
        //% this.fieldEditor="ports"
 | 
			
		||||
        //% weight=100 blockGap=12
 | 
			
		||||
        //% group="Color Sensor"
 | 
			
		||||
        //% color.fieldEditor="gridpicker"
 | 
			
		||||
        //% color.fieldOptions.columns=4 
 | 
			
		||||
        //% color.fieldOptions.columns=4
 | 
			
		||||
        //% color.fieldOptions.tooltips=true
 | 
			
		||||
        //% color.fieldOptions.hideRect=true
 | 
			
		||||
        //% color.fieldOptions.width=268
 | 
			
		||||
@@ -135,15 +135,15 @@ namespace sensors {
 | 
			
		||||
         * @param color the color to detect
 | 
			
		||||
         */
 | 
			
		||||
        //% help=sensors/color-sensor/pause-for-color
 | 
			
		||||
        //% block="pause %sensor|for color %color"
 | 
			
		||||
        //% block="pause **color** %this|for color %color"
 | 
			
		||||
        //% blockId=colorPauseForColorDetected
 | 
			
		||||
        //% parts="colorsensor"
 | 
			
		||||
        //% blockNamespace=sensors
 | 
			
		||||
        //% sensor.fieldEditor="ports"
 | 
			
		||||
        //% this.fieldEditor="ports"
 | 
			
		||||
        //% weight=99 blockGap=8
 | 
			
		||||
        //% group="Color Sensor"
 | 
			
		||||
        //% color.fieldEditor="gridpicker"
 | 
			
		||||
        //% color.fieldOptions.columns=4 
 | 
			
		||||
        //% color.fieldOptions.columns=4
 | 
			
		||||
        //% color.fieldOptions.tooltips=true
 | 
			
		||||
        //% color.fieldOptions.hideRect=true
 | 
			
		||||
        //% color.fieldOptions.width=268
 | 
			
		||||
@@ -160,11 +160,11 @@ namespace sensors {
 | 
			
		||||
         * @param sensor the color sensor to query the request
 | 
			
		||||
         */
 | 
			
		||||
        //% help=sensors/color-sensor/color
 | 
			
		||||
        //% block="%sensor| color"
 | 
			
		||||
        //% block="**color** %this| color"
 | 
			
		||||
        //% blockId=colorGetColor
 | 
			
		||||
        //% parts="colorsensor"
 | 
			
		||||
        //% blockNamespace=sensors
 | 
			
		||||
        //% sensor.fieldEditor="ports"
 | 
			
		||||
        //% this.fieldEditor="ports"
 | 
			
		||||
        //% weight=98
 | 
			
		||||
        //% group="Color Sensor"
 | 
			
		||||
        //% blockGap=8
 | 
			
		||||
@@ -179,11 +179,11 @@ namespace sensors {
 | 
			
		||||
         * @param handler the code to run when detected
 | 
			
		||||
         */
 | 
			
		||||
        //% help=sensors/color-sensor/on-light-changed
 | 
			
		||||
        //% block="on %sensor|%mode|%condition"
 | 
			
		||||
        //% block="on **color** %this|%mode|%condition"
 | 
			
		||||
        //% blockId=colorOnLightChanged
 | 
			
		||||
        //% parts="colorsensor"
 | 
			
		||||
        //% blockNamespace=sensors
 | 
			
		||||
        //% sensor.fieldEditor="ports"
 | 
			
		||||
        //% this.fieldEditor="ports"
 | 
			
		||||
        //% weight=89 blockGap=12
 | 
			
		||||
        //% group="Color Sensor"
 | 
			
		||||
        onLightChanged(mode: LightIntensityMode, condition: LightCondition, handler: () => void) {
 | 
			
		||||
@@ -196,11 +196,11 @@ namespace sensors {
 | 
			
		||||
         * @param color the color to detect
 | 
			
		||||
         */
 | 
			
		||||
        //% help=sensors/color-sensor/pause-for-light
 | 
			
		||||
        //% block="pause %sensor|for %mode|%condition"
 | 
			
		||||
        //% block="pause **color** %this|for %mode|%condition"
 | 
			
		||||
        //% blockId=colorPauseForLight
 | 
			
		||||
        //% parts="colorsensor"
 | 
			
		||||
        //% blockNamespace=sensors
 | 
			
		||||
        //% sensor.fieldEditor="ports"
 | 
			
		||||
        //% this.fieldEditor="ports"
 | 
			
		||||
        //% weight=88 blockGap=8
 | 
			
		||||
        //% group="Color Sensor"
 | 
			
		||||
        pauseForLight(mode: LightIntensityMode, condition: LightCondition) {
 | 
			
		||||
@@ -214,11 +214,11 @@ namespace sensors {
 | 
			
		||||
         * @param sensor the color sensor port
 | 
			
		||||
         */
 | 
			
		||||
        //% help=sensors/color-sensor/light
 | 
			
		||||
        //% block="%sensor|%mode"
 | 
			
		||||
        //% block="**color** %this|%mode"
 | 
			
		||||
        //% blockId=colorLight
 | 
			
		||||
        //% parts="colorsensor"
 | 
			
		||||
        //% blockNamespace=sensors
 | 
			
		||||
        //% sensor.fieldEditor="ports"
 | 
			
		||||
        //% this.fieldEditor="ports"
 | 
			
		||||
        //% weight=87
 | 
			
		||||
        //% group="Color Sensor"
 | 
			
		||||
        light(mode: LightIntensityMode) {
 | 
			
		||||
@@ -241,10 +241,10 @@ namespace sensors {
 | 
			
		||||
         * @param condition the dark or bright light condition
 | 
			
		||||
         * @param value the value threshold
 | 
			
		||||
         */
 | 
			
		||||
        //% blockId=colorSetThreshold block="set %sensor|%condition|to %value"
 | 
			
		||||
        //% blockId=colorSetThreshold block="set **color** %this|%condition|to %value"
 | 
			
		||||
        //% group="Threshold" blockGap=8 weight=90
 | 
			
		||||
        //% value.min=0 value.max=100
 | 
			
		||||
        //% sensor.fieldEditor="ports"
 | 
			
		||||
        //% this.fieldEditor="ports"
 | 
			
		||||
        //% help=sensors/color-sensor/set-threshold
 | 
			
		||||
        setThreshold(condition: LightCondition, value: number) {
 | 
			
		||||
            if (condition == LightCondition.Dark)
 | 
			
		||||
@@ -257,9 +257,9 @@ namespace sensors {
 | 
			
		||||
         * Get a threshold value
 | 
			
		||||
         * @param condition the light condition
 | 
			
		||||
         */
 | 
			
		||||
        //% blockId=colorGetThreshold block="%sensor|%condition"
 | 
			
		||||
        //% blockId=colorGetThreshold block="**color** %this|%condition"
 | 
			
		||||
        //% group="Threshold" blockGap=8 weight=89
 | 
			
		||||
        //% sensor.fieldEditor="ports"
 | 
			
		||||
        //% this.fieldEditor="ports"
 | 
			
		||||
        //% help=sensors/color-sensor/threshold
 | 
			
		||||
        threshold(condition: LightCondition): number {
 | 
			
		||||
            return this.thresholdDetector.threshold(<ThresholdState><number>LightCondition.Dark);
 | 
			
		||||
@@ -268,9 +268,9 @@ namespace sensors {
 | 
			
		||||
        /**
 | 
			
		||||
         * Collects measurement of the light condition and adjusts the threshold to 10% / 90%.
 | 
			
		||||
         */
 | 
			
		||||
        //% blockId=colorCalibrateLight block="calibrate|%sensor|for %mode"
 | 
			
		||||
        //% blockId=colorCalibrateLight block="calibrate **color** %this|for %mode"
 | 
			
		||||
        //% group="Threshold" weight=91 blockGap=8
 | 
			
		||||
        //% sensor.fieldEditor="ports"
 | 
			
		||||
        //% this.fieldEditor="ports"
 | 
			
		||||
        //% help=sensors/color-sensor/calibrate-light
 | 
			
		||||
        calibrateLight(mode: LightIntensityMode, deviation: number = 8) {
 | 
			
		||||
            this.calibrating = true; // prevent events
 | 
			
		||||
@@ -324,7 +324,7 @@ namespace sensors {
 | 
			
		||||
    //% weight=97
 | 
			
		||||
    //% help=sensors/color
 | 
			
		||||
    //% color.fieldEditor="gridpicker"
 | 
			
		||||
    //% color.fieldOptions.columns=4 
 | 
			
		||||
    //% color.fieldOptions.columns=4
 | 
			
		||||
    //% color.fieldOptions.tooltips=true
 | 
			
		||||
    //% color.fieldOptions.hideRect=true
 | 
			
		||||
    //% color.fieldOptions.width=268
 | 
			
		||||
@@ -332,15 +332,15 @@ namespace sensors {
 | 
			
		||||
        return color;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //% whenUsed block="color 3" weight=95 fixedInstance jres=icons.port3
 | 
			
		||||
    //% whenUsed block="3" weight=95 fixedInstance jres=icons.port3
 | 
			
		||||
    export const color3: ColorSensor = new ColorSensor(3)
 | 
			
		||||
 | 
			
		||||
    //% whenUsed block="color 1" weight=90 fixedInstance jres=icons.port1
 | 
			
		||||
    //% whenUsed block="1" weight=90 fixedInstance jres=icons.port1
 | 
			
		||||
    export const color1: ColorSensor = new ColorSensor(1)
 | 
			
		||||
 | 
			
		||||
    //% whenUsed block="color 2" weight=90 fixedInstance jres=icons.port2
 | 
			
		||||
    //% whenUsed block="2" weight=90 fixedInstance jres=icons.port2
 | 
			
		||||
    export const color2: ColorSensor = new ColorSensor(2)
 | 
			
		||||
 | 
			
		||||
    //% whenUsed block="color 4" weight=90 fixedInstance jres=icons.port4
 | 
			
		||||
    //% whenUsed block="4" weight=90 fixedInstance jres=icons.port4
 | 
			
		||||
    export const color4: ColorSensor = new ColorSensor(4)
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -37,11 +37,11 @@ namespace sensors {
 | 
			
		||||
         * @param sensor the gyroscope to query the request
 | 
			
		||||
         */
 | 
			
		||||
        //% help=sensors/gyro/angle
 | 
			
		||||
        //% block="%sensor|angle"
 | 
			
		||||
        //% block="**gyro** %this|angle"
 | 
			
		||||
        //% blockId=gyroGetAngle
 | 
			
		||||
        //% parts="gyroscope"
 | 
			
		||||
        //% blockNamespace=sensors
 | 
			
		||||
        //% sensor.fieldEditor="ports"
 | 
			
		||||
        //% this.fieldEditor="ports"
 | 
			
		||||
        //% weight=64 blockGap=8
 | 
			
		||||
        //% group="Gyro Sensor"
 | 
			
		||||
        angle(): number {
 | 
			
		||||
@@ -57,12 +57,12 @@ namespace sensors {
 | 
			
		||||
         * @param sensor the gyroscope to query the request
 | 
			
		||||
         */
 | 
			
		||||
        //% help=sensors/gyro/rate
 | 
			
		||||
        //% block="%sensor|rate"
 | 
			
		||||
        //% block="**gyro** %this|rate"
 | 
			
		||||
        //% blockId=gyroGetRate
 | 
			
		||||
        //% parts="gyroscope"
 | 
			
		||||
        //% blockNamespace=sensors
 | 
			
		||||
        //% sensor.fieldEditor="ports"
 | 
			
		||||
        //% weight=65 blockGap=8        
 | 
			
		||||
        //% this.fieldEditor="ports"
 | 
			
		||||
        //% weight=65 blockGap=8
 | 
			
		||||
        //% group="Gyro Sensor"
 | 
			
		||||
        rate(): number {
 | 
			
		||||
            if (this.calibrating)
 | 
			
		||||
@@ -82,18 +82,18 @@ namespace sensors {
 | 
			
		||||
         * Forces a calibration of the gyro. Must be called when the sensor is completely still.
 | 
			
		||||
         */
 | 
			
		||||
        //% help=sensors/gyro/reset
 | 
			
		||||
        //% block="reset %sensor|"
 | 
			
		||||
        //% blockId=gyroReset  
 | 
			
		||||
        //% block="reset **gyro** %this|"
 | 
			
		||||
        //% blockId=gyroReset
 | 
			
		||||
        //% parts="gyroscope"
 | 
			
		||||
        //% blockNamespace=sensors
 | 
			
		||||
        //% sensor.fieldEditor="ports"
 | 
			
		||||
        //% weight=50        
 | 
			
		||||
        //% this.fieldEditor="ports"
 | 
			
		||||
        //% weight=50
 | 
			
		||||
        //% group="Gyro Sensor"
 | 
			
		||||
        reset(): void {
 | 
			
		||||
            if (this.calibrating) return; // already in calibration mode
 | 
			
		||||
 | 
			
		||||
            this.calibrating = true;
 | 
			
		||||
            // may be triggered by a button click, 
 | 
			
		||||
            // may be triggered by a button click,
 | 
			
		||||
            // give time for robot to settle
 | 
			
		||||
            pause(700);
 | 
			
		||||
            // send a reset command
 | 
			
		||||
@@ -127,7 +127,7 @@ namespace sensors {
 | 
			
		||||
 | 
			
		||||
        /**
 | 
			
		||||
         * Enables or disable drift correction
 | 
			
		||||
         * @param enabled 
 | 
			
		||||
         * @param enabled
 | 
			
		||||
         */
 | 
			
		||||
        //%
 | 
			
		||||
        setDriftCorrection(enabled: boolean) {
 | 
			
		||||
@@ -135,15 +135,15 @@ namespace sensors {
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //% fixedInstance whenUsed block="gyro 2" weight=95 jres=icons.port2
 | 
			
		||||
    //% fixedInstance whenUsed block="2" weight=95 jres=icons.port2
 | 
			
		||||
    export const gyro2: GyroSensor = new GyroSensor(2)
 | 
			
		||||
 | 
			
		||||
    //% fixedInstance whenUsed block="gyro 1" jres=icons.port1
 | 
			
		||||
    //% fixedInstance whenUsed block="1" jres=icons.port1
 | 
			
		||||
    export const gyro1: GyroSensor = new GyroSensor(1)
 | 
			
		||||
 | 
			
		||||
    //% fixedInstance whenUsed block="gyro 3" jres=icons.port3
 | 
			
		||||
    //% fixedInstance whenUsed block="3" jres=icons.port3
 | 
			
		||||
    export const gyro3: GyroSensor = new GyroSensor(3)
 | 
			
		||||
 | 
			
		||||
    //% fixedInstance whenUsed block="gyro 4" jres=icons.port4
 | 
			
		||||
    //% fixedInstance whenUsed block="4" jres=icons.port4
 | 
			
		||||
    export const gyro4: GyroSensor = new GyroSensor(4)
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -84,7 +84,7 @@ namespace sensors {
 | 
			
		||||
         * @param button the remote button to query the request
 | 
			
		||||
         */
 | 
			
		||||
        //% help=sensors/beacon/is-pressed
 | 
			
		||||
        //% block="%button|is pressed"
 | 
			
		||||
        //% block="**remote button** %button|is pressed"
 | 
			
		||||
        //% blockId=remoteButtonIsPressed
 | 
			
		||||
        //% parts="remote"
 | 
			
		||||
        //% blockNamespace=sensors
 | 
			
		||||
@@ -99,7 +99,7 @@ namespace sensors {
 | 
			
		||||
         * @param button the remote button to query the request
 | 
			
		||||
         */
 | 
			
		||||
        //% help=sensors/beacon/was-pressed
 | 
			
		||||
        //% block="%button|was pressed"
 | 
			
		||||
        //% block="**remote button** %button|was pressed"
 | 
			
		||||
        //% blockId=remotebuttonWasPressed
 | 
			
		||||
        //% parts="remote"
 | 
			
		||||
        //% blockNamespace=sensors
 | 
			
		||||
@@ -116,7 +116,7 @@ namespace sensors {
 | 
			
		||||
         * @param body code to run when the event is raised
 | 
			
		||||
         */
 | 
			
		||||
        //% help=sensors/beacon/on-event
 | 
			
		||||
        //% blockId=remotebuttonEvent block="on %button|%event"
 | 
			
		||||
        //% blockId=remotebuttonEvent block="on **remote button** %button|%event"
 | 
			
		||||
        //% parts="remote"
 | 
			
		||||
        //% blockNamespace=sensors
 | 
			
		||||
        //% weight=99 blockGap=8
 | 
			
		||||
@@ -130,7 +130,7 @@ namespace sensors {
 | 
			
		||||
         * @param ev the event to wait for
 | 
			
		||||
         */
 | 
			
		||||
        //% help=sensors/beacon/pause-until
 | 
			
		||||
        //% blockId=remoteButtonPauseUntil block="pause until %button|%event"
 | 
			
		||||
        //% blockId=remoteButtonPauseUntil block="pause until **remote button** %button|%event"
 | 
			
		||||
        //% parts="remote"
 | 
			
		||||
        //% blockNamespace=sensors
 | 
			
		||||
        //% weight=99 blockGap=8
 | 
			
		||||
@@ -185,12 +185,13 @@ namespace sensors {
 | 
			
		||||
         * @param handler the code to run when detected
 | 
			
		||||
         */
 | 
			
		||||
        //% help=sensors/infrared/on-event
 | 
			
		||||
        //% block="on %sensor|%event"
 | 
			
		||||
        //% block="on **infrared** %this|%event"
 | 
			
		||||
        //% blockId=infraredOn
 | 
			
		||||
        //% parts="infraredsensor"
 | 
			
		||||
        //% blockNamespace=sensors
 | 
			
		||||
        //% weight=100 blockGap=8
 | 
			
		||||
        //% group="Infrared Sensor"
 | 
			
		||||
        //% this.fieldEditor="ports"
 | 
			
		||||
        onEvent(event: InfraredSensorEvent, handler: () => void) {
 | 
			
		||||
            this._setMode(InfraredSensorMode.Proximity)
 | 
			
		||||
            control.onEvent(this._id, event, handler);
 | 
			
		||||
@@ -200,12 +201,13 @@ namespace sensors {
 | 
			
		||||
         * Wait until the infrared sensor detects something
 | 
			
		||||
         */
 | 
			
		||||
        //% help=sensors/infrared/pause-until
 | 
			
		||||
        //% block="pause until %sensor| %event"
 | 
			
		||||
        //% block="pause until **infrared** %this| %event"
 | 
			
		||||
        //% blockId=infraredwait
 | 
			
		||||
        //% parts="infraredsensor"
 | 
			
		||||
        //% blockNamespace=sensors
 | 
			
		||||
        //% weight=99 blockGap=8
 | 
			
		||||
        //% group="Infrared Sensor"
 | 
			
		||||
        //% this.fieldEditor="ports"
 | 
			
		||||
        pauseUntil(event: InfraredSensorEvent) {
 | 
			
		||||
            this._setMode(InfraredSensorMode.Proximity)
 | 
			
		||||
            control.waitForEvent(this._id, event);
 | 
			
		||||
@@ -216,12 +218,13 @@ namespace sensors {
 | 
			
		||||
         * @param sensor the infrared sensor
 | 
			
		||||
         */
 | 
			
		||||
        //% help=sensors/infrared/proximity
 | 
			
		||||
        //% block="%sensor|proximity"
 | 
			
		||||
        //% block="**infrared** %this|proximity"
 | 
			
		||||
        //% blockId=infraredGetProximity
 | 
			
		||||
        //% parts="infrared"
 | 
			
		||||
        //% blockNamespace=sensors
 | 
			
		||||
        //% weight=98 blockGap=8   
 | 
			
		||||
        //% group="Infrared Sensor"     
 | 
			
		||||
        //% weight=98 blockGap=8
 | 
			
		||||
        //% group="Infrared Sensor"
 | 
			
		||||
        //% this.fieldEditor="ports"
 | 
			
		||||
        proximity(): number {
 | 
			
		||||
            this._setMode(InfraredSensorMode.Proximity)
 | 
			
		||||
            return this.getNumber(NumberFormat.UInt8LE, 0)
 | 
			
		||||
@@ -232,9 +235,10 @@ namespace sensors {
 | 
			
		||||
         * @param channel the channel to listen
 | 
			
		||||
         */
 | 
			
		||||
        //% blockNamespace=sensors
 | 
			
		||||
        //% blockId=irSetRemoteChannel block="set %sensor|remote channel to %channel"
 | 
			
		||||
        //% weight=99       
 | 
			
		||||
        //% blockId=irSetRemoteChannel block="set **infrared** %this|remote channel to %channel"
 | 
			
		||||
        //% weight=99
 | 
			
		||||
        //% group="Remote Infrared Beacon"
 | 
			
		||||
        //% this.fieldEditor="ports"
 | 
			
		||||
        //% help=sensors/beacon/set-remote-channel
 | 
			
		||||
        setRemoteChannel(channel: InfraredRemoteChannel) {
 | 
			
		||||
            this.setMode(InfraredSensorMode.RemoteControl)
 | 
			
		||||
@@ -247,9 +251,10 @@ namespace sensors {
 | 
			
		||||
         * @param condition the dark or bright light condition
 | 
			
		||||
         * @param value the value threshold
 | 
			
		||||
         */
 | 
			
		||||
        //% blockId=irSetThreshold block="set %sensor|%condition|to %value"
 | 
			
		||||
        //% blockId=irSetThreshold block="set **infrared** %this|%condition|to %value"
 | 
			
		||||
        //% group="Threshold" blockGap=8 weight=49
 | 
			
		||||
        //% value.min=0 value.max=100
 | 
			
		||||
        //% this.fieldEditor="ports"
 | 
			
		||||
        setPromixityThreshold(condition: InfraredSensorEvent, value: number) {
 | 
			
		||||
            if (condition == InfraredSensorEvent.ObjectNear)
 | 
			
		||||
                this._proximityThreshold.setLowThreshold(value)
 | 
			
		||||
@@ -261,9 +266,9 @@ namespace sensors {
 | 
			
		||||
         * Get a threshold value
 | 
			
		||||
         * @param condition the proximity condition
 | 
			
		||||
         */
 | 
			
		||||
        //% blockId=irGetThreshold block="%sensor|%condition"
 | 
			
		||||
        //% blockId=irGetThreshold block="**infrared** %this|%condition"
 | 
			
		||||
        //% group="Threshold" blockGap=8 weight=49
 | 
			
		||||
        //% sensor.fieldEditor="ports"
 | 
			
		||||
        //% this.fieldEditor="ports"
 | 
			
		||||
        proximityThreshold(condition: InfraredSensorEvent): number {
 | 
			
		||||
            return this._proximityThreshold.threshold(<ThresholdState><number>LightCondition.Dark);
 | 
			
		||||
        }
 | 
			
		||||
@@ -275,45 +280,45 @@ namespace sensors {
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //% fixedInstance whenUsed block="infrared 1" jres=icons.port1
 | 
			
		||||
    //% fixedInstance whenUsed block="1" jres=icons.port1
 | 
			
		||||
    export const infraredSensor1: InfraredSensor = new InfraredSensor(1)
 | 
			
		||||
 | 
			
		||||
    //% fixedInstance whenUsed block="infrared 2" jres=icons.port2
 | 
			
		||||
    //% fixedInstance whenUsed block="2" jres=icons.port2
 | 
			
		||||
    export const infraredSensor2: InfraredSensor = new InfraredSensor(2)
 | 
			
		||||
 | 
			
		||||
    //% fixedInstance whenUsed block="infrared 3" jres=icons.port3
 | 
			
		||||
    //% fixedInstance whenUsed block="3" jres=icons.port3
 | 
			
		||||
    export const infraredSensor3: InfraredSensor = new InfraredSensor(3)
 | 
			
		||||
 | 
			
		||||
    //% fixedInstance whenUsed block="infrared 4" jres=icons.port4
 | 
			
		||||
    //% fixedInstance whenUsed block="4" jres=icons.port4
 | 
			
		||||
    export const infraredSensor4: InfraredSensor = new InfraredSensor(4)
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Remote beacon (center) button.
 | 
			
		||||
     */
 | 
			
		||||
    //% whenUsed block="remote button center" weight=95 fixedInstance
 | 
			
		||||
    //% whenUsed block="center" weight=95 fixedInstance
 | 
			
		||||
    export const remoteButtonCenter = __irButton(InfraredRemoteButton.CenterBeacon)
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Remote top-left button.
 | 
			
		||||
     */
 | 
			
		||||
    //% whenUsed block="remote button top left" weight=95 fixedInstance
 | 
			
		||||
    //% whenUsed block="top left" weight=95 fixedInstance
 | 
			
		||||
    export const remoteButtonTopLeft = __irButton(InfraredRemoteButton.TopLeft)
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Remote top-right button.
 | 
			
		||||
     */
 | 
			
		||||
    //% whenUsed block="remote button top right" weight=95 fixedInstance
 | 
			
		||||
    //% whenUsed block="top right" weight=95 fixedInstance
 | 
			
		||||
    export const remoteButtonTopRight = __irButton(InfraredRemoteButton.TopRight)
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Remote bottom-left button.
 | 
			
		||||
     */
 | 
			
		||||
    //% whenUsed block="remote button bottom left" weight=95 fixedInstance
 | 
			
		||||
    //% whenUsed block="bottom left" weight=95 fixedInstance
 | 
			
		||||
    export const remoteButtonBottomLeft = __irButton(InfraredRemoteButton.BottomLeft)
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Remote bottom-right button.
 | 
			
		||||
     */
 | 
			
		||||
    //% whenUsed block="remote button bottom right" weight=95 fixedInstance
 | 
			
		||||
    //% whenUsed block="bottom right" weight=95 fixedInstance
 | 
			
		||||
    export const remoteButtonBottomRight = __irButton(InfraredRemoteButton.BottomRight)
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -30,10 +30,10 @@ namespace sensors {
 | 
			
		||||
         * @param body code to run when the event is raised
 | 
			
		||||
         */
 | 
			
		||||
        //% help=sensors/touch-sensor/on-event
 | 
			
		||||
        //% blockId=touchEvent block="on %sensor|%event"
 | 
			
		||||
        //% blockId=touchEvent block="on **touch** %this|%event"
 | 
			
		||||
        //% parts="touch"
 | 
			
		||||
        //% blockNamespace=sensors
 | 
			
		||||
        //% sensor.fieldEditor="ports"
 | 
			
		||||
        //% this.fieldEditor="ports"
 | 
			
		||||
        //% weight=99 blockGap=12
 | 
			
		||||
        //% group="Touch Sensor"
 | 
			
		||||
        onEvent(ev: ButtonEvent, body: () => void) {
 | 
			
		||||
@@ -46,10 +46,10 @@ namespace sensors {
 | 
			
		||||
         * @param event the kind of button gesture that needs to be detected
 | 
			
		||||
         */
 | 
			
		||||
        //% help=sensors/touch-sensor/pause-until
 | 
			
		||||
        //% blockId=touchWaitUntil block="pause until %sensor|%event"
 | 
			
		||||
        //% blockId=touchWaitUntil block="pause until **touch** %this|%event"
 | 
			
		||||
        //% parts="touch"
 | 
			
		||||
        //% blockNamespace=sensors
 | 
			
		||||
        //% sensor.fieldEditor="ports"
 | 
			
		||||
        //% this.fieldEditor="ports"
 | 
			
		||||
        //% weight=98 blockGap=12
 | 
			
		||||
        //% group="Touch Sensor"
 | 
			
		||||
        pauseUntil(ev: ButtonEvent) {
 | 
			
		||||
@@ -61,11 +61,11 @@ namespace sensors {
 | 
			
		||||
         * @param sensor the port to query the request
 | 
			
		||||
         */
 | 
			
		||||
        //% help=sensors/touch-sensor/is-pressed
 | 
			
		||||
        //% block="%sensor|is pressed"
 | 
			
		||||
        //% block="**touch** %this|is pressed"
 | 
			
		||||
        //% blockId=touchIsPressed
 | 
			
		||||
        //% parts="touch"
 | 
			
		||||
        //% blockNamespace=sensors
 | 
			
		||||
        //% sensor.fieldEditor="ports"
 | 
			
		||||
        //% this.fieldEditor="ports"
 | 
			
		||||
        //% weight=81 blockGap=8
 | 
			
		||||
        //% group="Touch Sensor"
 | 
			
		||||
        isPressed() {
 | 
			
		||||
@@ -77,11 +77,11 @@ namespace sensors {
 | 
			
		||||
         * @param sensor the port to query the request
 | 
			
		||||
         */
 | 
			
		||||
        //% help=sensors/touch-sensor/was-pressed
 | 
			
		||||
        //% block="%sensor|was pressed"
 | 
			
		||||
        //% block="**touch** %this|was pressed"
 | 
			
		||||
        //% blockId=touchWasPressed
 | 
			
		||||
        //% parts="touch"
 | 
			
		||||
        //% blockNamespace=sensors
 | 
			
		||||
        //% sensor.fieldEditor="ports"
 | 
			
		||||
        //% this.fieldEditor="ports"
 | 
			
		||||
        //% weight=81
 | 
			
		||||
        //% group="Touch Sensor"
 | 
			
		||||
        wasPressed() {
 | 
			
		||||
@@ -89,12 +89,12 @@ namespace sensors {
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //% whenUsed block="touch 1" weight=95 fixedInstance jres=icons.port1
 | 
			
		||||
    //% whenUsed block="1" weight=95 fixedInstance jres=icons.port1
 | 
			
		||||
    export const touch1: TouchSensor = new TouchSensor(1)
 | 
			
		||||
    //% whenUsed block="touch 2" weight=95 fixedInstance jres=icons.port2
 | 
			
		||||
    //% whenUsed block="2" weight=95 fixedInstance jres=icons.port2
 | 
			
		||||
    export const touch2: TouchSensor = new TouchSensor(2)
 | 
			
		||||
    //% whenUsed block="touch 3" weight=95 fixedInstance jres=icons.port3
 | 
			
		||||
    //% whenUsed block="3" weight=95 fixedInstance jres=icons.port3
 | 
			
		||||
    export const touch3: TouchSensor = new TouchSensor(3)
 | 
			
		||||
    //% whenUsed block="touch 4" weight=95 fixedInstance jres=icons.port4
 | 
			
		||||
    //% whenUsed block="4" weight=95 fixedInstance jres=icons.port4
 | 
			
		||||
    export const touch4: TouchSensor = new TouchSensor(4)
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -43,10 +43,10 @@ namespace sensors {
 | 
			
		||||
         */
 | 
			
		||||
        //% help=sensors/ultrasonic/on-event
 | 
			
		||||
        //% blockId=ultrasonicOn
 | 
			
		||||
        //% block="on %sensor|%event"
 | 
			
		||||
        //% block="on **ultrasonic** %this|%event"
 | 
			
		||||
        //% parts="ultrasonicsensor"
 | 
			
		||||
        //% blockNamespace=sensors
 | 
			
		||||
        //% sensor.fieldEditor="ports"
 | 
			
		||||
        //% this.fieldEditor="ports"
 | 
			
		||||
        //% weight=100 blockGap=8
 | 
			
		||||
        //% group="Ultrasonic Sensor"
 | 
			
		||||
        onEvent(event: UltrasonicSensorEvent, handler: () => void) {
 | 
			
		||||
@@ -57,13 +57,13 @@ namespace sensors {
 | 
			
		||||
         * Waits for the event to occur
 | 
			
		||||
         */
 | 
			
		||||
        //% help=sensors/ultrasonic/pause-until
 | 
			
		||||
        //% block="pause until %sensor| %event"
 | 
			
		||||
        //% block="pause until **ultrasonic** %this| %event"
 | 
			
		||||
        //% blockId=ultrasonicWait
 | 
			
		||||
        //% parts="ultrasonicsensor"
 | 
			
		||||
        //% blockNamespace=sensors
 | 
			
		||||
        //% sensor.fieldEditor="ports"
 | 
			
		||||
        //% this.fieldEditor="ports"
 | 
			
		||||
        //% weight=99 blockGap=8
 | 
			
		||||
        //% group="Ultrasonic Sensor"        
 | 
			
		||||
        //% group="Ultrasonic Sensor"
 | 
			
		||||
        pauseUntil(event: UltrasonicSensorEvent) {
 | 
			
		||||
            control.waitForEvent(this._id, event);
 | 
			
		||||
        }
 | 
			
		||||
@@ -73,13 +73,13 @@ namespace sensors {
 | 
			
		||||
         * @param sensor the ultrasonic sensor port
 | 
			
		||||
         */
 | 
			
		||||
        //% help=sensors/ultrasonic/distance
 | 
			
		||||
        //% block="%sensor|distance"
 | 
			
		||||
        //% block="**ultrasonic** %this|distance"
 | 
			
		||||
        //% blockId=sonarGetDistance
 | 
			
		||||
        //% parts="ultrasonicsensor"
 | 
			
		||||
        //% blockNamespace=sensors
 | 
			
		||||
        //% sensor.fieldEditor="ports"
 | 
			
		||||
        //% this.fieldEditor="ports"
 | 
			
		||||
        //% weight=65
 | 
			
		||||
        //% group="Ultrasonic Sensor"     
 | 
			
		||||
        //% group="Ultrasonic Sensor"
 | 
			
		||||
        distance(): number {
 | 
			
		||||
            // it supposedly also has an inch mode, but we stick to cm
 | 
			
		||||
            this._setMode(0)
 | 
			
		||||
@@ -92,9 +92,10 @@ namespace sensors {
 | 
			
		||||
         * @param condition the dark or bright light condition
 | 
			
		||||
         * @param value the value threshold
 | 
			
		||||
         */
 | 
			
		||||
        //% blockId=ultrasonicSetThreshold block="set %sensor|%condition|to %value"
 | 
			
		||||
        //% blockId=ultrasonicSetThreshold block="set **ultrasonic** %this|%condition|to %value"
 | 
			
		||||
        //% group="Threshold" blockGap=8 weight=80
 | 
			
		||||
        //% value.min=0 value.max=255
 | 
			
		||||
        //% this.fieldEditor="ports"
 | 
			
		||||
        setThreshold(condition: UltrasonicSensorEvent, value: number) {
 | 
			
		||||
            switch (condition) {
 | 
			
		||||
                case UltrasonicSensorEvent.ObjectNear: this.promixityThreshold.setLowThreshold(value); break;
 | 
			
		||||
@@ -107,9 +108,9 @@ namespace sensors {
 | 
			
		||||
         * Gets the threshold value
 | 
			
		||||
         * @param condition the proximity condition
 | 
			
		||||
         */
 | 
			
		||||
        //% blockId=ultrasonicGetThreshold block="%sensor|%condition"
 | 
			
		||||
        //% blockId=ultrasonicGetThreshold block="**ultrasonic** %this|%condition"
 | 
			
		||||
        //% group="Threshold" blockGap=8 weight=79
 | 
			
		||||
        //% sensor.fieldEditor="ports"
 | 
			
		||||
        //% this.fieldEditor="ports"
 | 
			
		||||
        threshold(condition: UltrasonicSensorEvent): number {
 | 
			
		||||
            switch (condition) {
 | 
			
		||||
                case UltrasonicSensorEvent.ObjectNear: this.promixityThreshold.threshold(ThresholdState.Low); break;
 | 
			
		||||
@@ -120,15 +121,15 @@ namespace sensors {
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //% fixedInstance whenUsed block="ultrasonic 4" jres=icons.port4
 | 
			
		||||
    //% fixedInstance whenUsed block="4" jres=icons.port4
 | 
			
		||||
    export const ultrasonic4: UltraSonicSensor = new UltraSonicSensor(4)
 | 
			
		||||
 | 
			
		||||
    //% fixedInstance whenUsed block="ultrasonic 1" jres=icons.port1
 | 
			
		||||
    //% fixedInstance whenUsed block="1" jres=icons.port1
 | 
			
		||||
    export const ultrasonic1: UltraSonicSensor = new UltraSonicSensor(1)
 | 
			
		||||
 | 
			
		||||
    //% fixedInstance whenUsed block="ultrasonic 2" jres=icons.port2
 | 
			
		||||
    //% fixedInstance whenUsed block="2" jres=icons.port2
 | 
			
		||||
    export const ultrasonic2: UltraSonicSensor = new UltraSonicSensor(2)
 | 
			
		||||
 | 
			
		||||
    //% fixedInstance whenUsed block="ultrasonic 3" jres=icons.port3
 | 
			
		||||
    //% fixedInstance whenUsed block="3" jres=icons.port3
 | 
			
		||||
    export const ultrasonic3: UltraSonicSensor = new UltraSonicSensor(3)
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user