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:
Guillaume Jenkins 2018-02-26 11:33:50 -05:00 committed by GitHub
parent 2d355bb2ca
commit 130a47d684
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 96 additions and 90 deletions

View File

@ -110,15 +110,15 @@ namespace sensors {
* @param handler the code to run when detected * @param handler the code to run when detected
*/ */
//% help=sensors/color-sensor/on-color-detected //% help=sensors/color-sensor/on-color-detected
//% block="on %sensor|detected color %color" //% block="on **color** %this|detected color %color"
//% blockId=colorOnColorDetected //% blockId=colorOnColorDetected
//% parts="colorsensor" //% parts="colorsensor"
//% blockNamespace=sensors //% blockNamespace=sensors
//% sensor.fieldEditor="ports" //% this.fieldEditor="ports"
//% weight=100 blockGap=12 //% weight=100 blockGap=12
//% group="Color Sensor" //% group="Color Sensor"
//% color.fieldEditor="gridpicker" //% color.fieldEditor="gridpicker"
//% color.fieldOptions.columns=4 //% color.fieldOptions.columns=4
//% color.fieldOptions.tooltips=true //% color.fieldOptions.tooltips=true
//% color.fieldOptions.hideRect=true //% color.fieldOptions.hideRect=true
//% color.fieldOptions.width=268 //% color.fieldOptions.width=268
@ -135,15 +135,15 @@ namespace sensors {
* @param color the color to detect * @param color the color to detect
*/ */
//% help=sensors/color-sensor/pause-for-color //% help=sensors/color-sensor/pause-for-color
//% block="pause %sensor|for color %color" //% block="pause **color** %this|for color %color"
//% blockId=colorPauseForColorDetected //% blockId=colorPauseForColorDetected
//% parts="colorsensor" //% parts="colorsensor"
//% blockNamespace=sensors //% blockNamespace=sensors
//% sensor.fieldEditor="ports" //% this.fieldEditor="ports"
//% weight=99 blockGap=8 //% weight=99 blockGap=8
//% group="Color Sensor" //% group="Color Sensor"
//% color.fieldEditor="gridpicker" //% color.fieldEditor="gridpicker"
//% color.fieldOptions.columns=4 //% color.fieldOptions.columns=4
//% color.fieldOptions.tooltips=true //% color.fieldOptions.tooltips=true
//% color.fieldOptions.hideRect=true //% color.fieldOptions.hideRect=true
//% color.fieldOptions.width=268 //% color.fieldOptions.width=268
@ -160,11 +160,11 @@ namespace sensors {
* @param sensor the color sensor to query the request * @param sensor the color sensor to query the request
*/ */
//% help=sensors/color-sensor/color //% help=sensors/color-sensor/color
//% block="%sensor| color" //% block="**color** %this| color"
//% blockId=colorGetColor //% blockId=colorGetColor
//% parts="colorsensor" //% parts="colorsensor"
//% blockNamespace=sensors //% blockNamespace=sensors
//% sensor.fieldEditor="ports" //% this.fieldEditor="ports"
//% weight=98 //% weight=98
//% group="Color Sensor" //% group="Color Sensor"
//% blockGap=8 //% blockGap=8
@ -179,11 +179,11 @@ namespace sensors {
* @param handler the code to run when detected * @param handler the code to run when detected
*/ */
//% help=sensors/color-sensor/on-light-changed //% help=sensors/color-sensor/on-light-changed
//% block="on %sensor|%mode|%condition" //% block="on **color** %this|%mode|%condition"
//% blockId=colorOnLightChanged //% blockId=colorOnLightChanged
//% parts="colorsensor" //% parts="colorsensor"
//% blockNamespace=sensors //% blockNamespace=sensors
//% sensor.fieldEditor="ports" //% this.fieldEditor="ports"
//% weight=89 blockGap=12 //% weight=89 blockGap=12
//% group="Color Sensor" //% group="Color Sensor"
onLightChanged(mode: LightIntensityMode, condition: LightCondition, handler: () => void) { onLightChanged(mode: LightIntensityMode, condition: LightCondition, handler: () => void) {
@ -196,11 +196,11 @@ namespace sensors {
* @param color the color to detect * @param color the color to detect
*/ */
//% help=sensors/color-sensor/pause-for-light //% help=sensors/color-sensor/pause-for-light
//% block="pause %sensor|for %mode|%condition" //% block="pause **color** %this|for %mode|%condition"
//% blockId=colorPauseForLight //% blockId=colorPauseForLight
//% parts="colorsensor" //% parts="colorsensor"
//% blockNamespace=sensors //% blockNamespace=sensors
//% sensor.fieldEditor="ports" //% this.fieldEditor="ports"
//% weight=88 blockGap=8 //% weight=88 blockGap=8
//% group="Color Sensor" //% group="Color Sensor"
pauseForLight(mode: LightIntensityMode, condition: LightCondition) { pauseForLight(mode: LightIntensityMode, condition: LightCondition) {
@ -214,11 +214,11 @@ namespace sensors {
* @param sensor the color sensor port * @param sensor the color sensor port
*/ */
//% help=sensors/color-sensor/light //% help=sensors/color-sensor/light
//% block="%sensor|%mode" //% block="**color** %this|%mode"
//% blockId=colorLight //% blockId=colorLight
//% parts="colorsensor" //% parts="colorsensor"
//% blockNamespace=sensors //% blockNamespace=sensors
//% sensor.fieldEditor="ports" //% this.fieldEditor="ports"
//% weight=87 //% weight=87
//% group="Color Sensor" //% group="Color Sensor"
light(mode: LightIntensityMode) { light(mode: LightIntensityMode) {
@ -241,10 +241,10 @@ namespace sensors {
* @param condition the dark or bright light condition * @param condition the dark or bright light condition
* @param value the value threshold * @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 //% group="Threshold" blockGap=8 weight=90
//% value.min=0 value.max=100 //% value.min=0 value.max=100
//% sensor.fieldEditor="ports" //% this.fieldEditor="ports"
//% help=sensors/color-sensor/set-threshold //% help=sensors/color-sensor/set-threshold
setThreshold(condition: LightCondition, value: number) { setThreshold(condition: LightCondition, value: number) {
if (condition == LightCondition.Dark) if (condition == LightCondition.Dark)
@ -257,9 +257,9 @@ namespace sensors {
* Get a threshold value * Get a threshold value
* @param condition the light condition * @param condition the light condition
*/ */
//% blockId=colorGetThreshold block="%sensor|%condition" //% blockId=colorGetThreshold block="**color** %this|%condition"
//% group="Threshold" blockGap=8 weight=89 //% group="Threshold" blockGap=8 weight=89
//% sensor.fieldEditor="ports" //% this.fieldEditor="ports"
//% help=sensors/color-sensor/threshold //% help=sensors/color-sensor/threshold
threshold(condition: LightCondition): number { threshold(condition: LightCondition): number {
return this.thresholdDetector.threshold(<ThresholdState><number>LightCondition.Dark); 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%. * 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 //% group="Threshold" weight=91 blockGap=8
//% sensor.fieldEditor="ports" //% this.fieldEditor="ports"
//% help=sensors/color-sensor/calibrate-light //% help=sensors/color-sensor/calibrate-light
calibrateLight(mode: LightIntensityMode, deviation: number = 8) { calibrateLight(mode: LightIntensityMode, deviation: number = 8) {
this.calibrating = true; // prevent events this.calibrating = true; // prevent events
@ -324,7 +324,7 @@ namespace sensors {
//% weight=97 //% weight=97
//% help=sensors/color //% help=sensors/color
//% color.fieldEditor="gridpicker" //% color.fieldEditor="gridpicker"
//% color.fieldOptions.columns=4 //% color.fieldOptions.columns=4
//% color.fieldOptions.tooltips=true //% color.fieldOptions.tooltips=true
//% color.fieldOptions.hideRect=true //% color.fieldOptions.hideRect=true
//% color.fieldOptions.width=268 //% color.fieldOptions.width=268
@ -332,15 +332,15 @@ namespace sensors {
return color; 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) 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) 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) 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) export const color4: ColorSensor = new ColorSensor(4)
} }

View File

@ -37,11 +37,11 @@ namespace sensors {
* @param sensor the gyroscope to query the request * @param sensor the gyroscope to query the request
*/ */
//% help=sensors/gyro/angle //% help=sensors/gyro/angle
//% block="%sensor|angle" //% block="**gyro** %this|angle"
//% blockId=gyroGetAngle //% blockId=gyroGetAngle
//% parts="gyroscope" //% parts="gyroscope"
//% blockNamespace=sensors //% blockNamespace=sensors
//% sensor.fieldEditor="ports" //% this.fieldEditor="ports"
//% weight=64 blockGap=8 //% weight=64 blockGap=8
//% group="Gyro Sensor" //% group="Gyro Sensor"
angle(): number { angle(): number {
@ -57,12 +57,12 @@ namespace sensors {
* @param sensor the gyroscope to query the request * @param sensor the gyroscope to query the request
*/ */
//% help=sensors/gyro/rate //% help=sensors/gyro/rate
//% block="%sensor|rate" //% block="**gyro** %this|rate"
//% blockId=gyroGetRate //% blockId=gyroGetRate
//% parts="gyroscope" //% parts="gyroscope"
//% blockNamespace=sensors //% blockNamespace=sensors
//% sensor.fieldEditor="ports" //% this.fieldEditor="ports"
//% weight=65 blockGap=8 //% weight=65 blockGap=8
//% group="Gyro Sensor" //% group="Gyro Sensor"
rate(): number { rate(): number {
if (this.calibrating) if (this.calibrating)
@ -82,18 +82,18 @@ namespace sensors {
* Forces a calibration of the gyro. Must be called when the sensor is completely still. * Forces a calibration of the gyro. Must be called when the sensor is completely still.
*/ */
//% help=sensors/gyro/reset //% help=sensors/gyro/reset
//% block="reset %sensor|" //% block="reset **gyro** %this|"
//% blockId=gyroReset //% blockId=gyroReset
//% parts="gyroscope" //% parts="gyroscope"
//% blockNamespace=sensors //% blockNamespace=sensors
//% sensor.fieldEditor="ports" //% this.fieldEditor="ports"
//% weight=50 //% weight=50
//% group="Gyro Sensor" //% group="Gyro Sensor"
reset(): void { reset(): void {
if (this.calibrating) return; // already in calibration mode if (this.calibrating) return; // already in calibration mode
this.calibrating = true; this.calibrating = true;
// may be triggered by a button click, // may be triggered by a button click,
// give time for robot to settle // give time for robot to settle
pause(700); pause(700);
// send a reset command // send a reset command
@ -127,7 +127,7 @@ namespace sensors {
/** /**
* Enables or disable drift correction * Enables or disable drift correction
* @param enabled * @param enabled
*/ */
//% //%
setDriftCorrection(enabled: boolean) { 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) 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) 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) 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) export const gyro4: GyroSensor = new GyroSensor(4)
} }

View File

@ -84,7 +84,7 @@ namespace sensors {
* @param button the remote button to query the request * @param button the remote button to query the request
*/ */
//% help=sensors/beacon/is-pressed //% help=sensors/beacon/is-pressed
//% block="%button|is pressed" //% block="**remote button** %button|is pressed"
//% blockId=remoteButtonIsPressed //% blockId=remoteButtonIsPressed
//% parts="remote" //% parts="remote"
//% blockNamespace=sensors //% blockNamespace=sensors
@ -99,7 +99,7 @@ namespace sensors {
* @param button the remote button to query the request * @param button the remote button to query the request
*/ */
//% help=sensors/beacon/was-pressed //% help=sensors/beacon/was-pressed
//% block="%button|was pressed" //% block="**remote button** %button|was pressed"
//% blockId=remotebuttonWasPressed //% blockId=remotebuttonWasPressed
//% parts="remote" //% parts="remote"
//% blockNamespace=sensors //% blockNamespace=sensors
@ -116,7 +116,7 @@ namespace sensors {
* @param body code to run when the event is raised * @param body code to run when the event is raised
*/ */
//% help=sensors/beacon/on-event //% help=sensors/beacon/on-event
//% blockId=remotebuttonEvent block="on %button|%event" //% blockId=remotebuttonEvent block="on **remote button** %button|%event"
//% parts="remote" //% parts="remote"
//% blockNamespace=sensors //% blockNamespace=sensors
//% weight=99 blockGap=8 //% weight=99 blockGap=8
@ -130,7 +130,7 @@ namespace sensors {
* @param ev the event to wait for * @param ev the event to wait for
*/ */
//% help=sensors/beacon/pause-until //% help=sensors/beacon/pause-until
//% blockId=remoteButtonPauseUntil block="pause until %button|%event" //% blockId=remoteButtonPauseUntil block="pause until **remote button** %button|%event"
//% parts="remote" //% parts="remote"
//% blockNamespace=sensors //% blockNamespace=sensors
//% weight=99 blockGap=8 //% weight=99 blockGap=8
@ -185,12 +185,13 @@ namespace sensors {
* @param handler the code to run when detected * @param handler the code to run when detected
*/ */
//% help=sensors/infrared/on-event //% help=sensors/infrared/on-event
//% block="on %sensor|%event" //% block="on **infrared** %this|%event"
//% blockId=infraredOn //% blockId=infraredOn
//% parts="infraredsensor" //% parts="infraredsensor"
//% blockNamespace=sensors //% blockNamespace=sensors
//% weight=100 blockGap=8 //% weight=100 blockGap=8
//% group="Infrared Sensor" //% group="Infrared Sensor"
//% this.fieldEditor="ports"
onEvent(event: InfraredSensorEvent, handler: () => void) { onEvent(event: InfraredSensorEvent, handler: () => void) {
this._setMode(InfraredSensorMode.Proximity) this._setMode(InfraredSensorMode.Proximity)
control.onEvent(this._id, event, handler); control.onEvent(this._id, event, handler);
@ -200,12 +201,13 @@ namespace sensors {
* Wait until the infrared sensor detects something * Wait until the infrared sensor detects something
*/ */
//% help=sensors/infrared/pause-until //% help=sensors/infrared/pause-until
//% block="pause until %sensor| %event" //% block="pause until **infrared** %this| %event"
//% blockId=infraredwait //% blockId=infraredwait
//% parts="infraredsensor" //% parts="infraredsensor"
//% blockNamespace=sensors //% blockNamespace=sensors
//% weight=99 blockGap=8 //% weight=99 blockGap=8
//% group="Infrared Sensor" //% group="Infrared Sensor"
//% this.fieldEditor="ports"
pauseUntil(event: InfraredSensorEvent) { pauseUntil(event: InfraredSensorEvent) {
this._setMode(InfraredSensorMode.Proximity) this._setMode(InfraredSensorMode.Proximity)
control.waitForEvent(this._id, event); control.waitForEvent(this._id, event);
@ -216,12 +218,13 @@ namespace sensors {
* @param sensor the infrared sensor * @param sensor the infrared sensor
*/ */
//% help=sensors/infrared/proximity //% help=sensors/infrared/proximity
//% block="%sensor|proximity" //% block="**infrared** %this|proximity"
//% blockId=infraredGetProximity //% blockId=infraredGetProximity
//% parts="infrared" //% parts="infrared"
//% blockNamespace=sensors //% blockNamespace=sensors
//% weight=98 blockGap=8 //% weight=98 blockGap=8
//% group="Infrared Sensor" //% group="Infrared Sensor"
//% this.fieldEditor="ports"
proximity(): number { proximity(): number {
this._setMode(InfraredSensorMode.Proximity) this._setMode(InfraredSensorMode.Proximity)
return this.getNumber(NumberFormat.UInt8LE, 0) return this.getNumber(NumberFormat.UInt8LE, 0)
@ -232,9 +235,10 @@ namespace sensors {
* @param channel the channel to listen * @param channel the channel to listen
*/ */
//% blockNamespace=sensors //% blockNamespace=sensors
//% blockId=irSetRemoteChannel block="set %sensor|remote channel to %channel" //% blockId=irSetRemoteChannel block="set **infrared** %this|remote channel to %channel"
//% weight=99 //% weight=99
//% group="Remote Infrared Beacon" //% group="Remote Infrared Beacon"
//% this.fieldEditor="ports"
//% help=sensors/beacon/set-remote-channel //% help=sensors/beacon/set-remote-channel
setRemoteChannel(channel: InfraredRemoteChannel) { setRemoteChannel(channel: InfraredRemoteChannel) {
this.setMode(InfraredSensorMode.RemoteControl) this.setMode(InfraredSensorMode.RemoteControl)
@ -247,9 +251,10 @@ namespace sensors {
* @param condition the dark or bright light condition * @param condition the dark or bright light condition
* @param value the value threshold * @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 //% group="Threshold" blockGap=8 weight=49
//% value.min=0 value.max=100 //% value.min=0 value.max=100
//% this.fieldEditor="ports"
setPromixityThreshold(condition: InfraredSensorEvent, value: number) { setPromixityThreshold(condition: InfraredSensorEvent, value: number) {
if (condition == InfraredSensorEvent.ObjectNear) if (condition == InfraredSensorEvent.ObjectNear)
this._proximityThreshold.setLowThreshold(value) this._proximityThreshold.setLowThreshold(value)
@ -261,9 +266,9 @@ namespace sensors {
* Get a threshold value * Get a threshold value
* @param condition the proximity condition * @param condition the proximity condition
*/ */
//% blockId=irGetThreshold block="%sensor|%condition" //% blockId=irGetThreshold block="**infrared** %this|%condition"
//% group="Threshold" blockGap=8 weight=49 //% group="Threshold" blockGap=8 weight=49
//% sensor.fieldEditor="ports" //% this.fieldEditor="ports"
proximityThreshold(condition: InfraredSensorEvent): number { proximityThreshold(condition: InfraredSensorEvent): number {
return this._proximityThreshold.threshold(<ThresholdState><number>LightCondition.Dark); 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) 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) 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) 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) export const infraredSensor4: InfraredSensor = new InfraredSensor(4)
/** /**
* Remote beacon (center) button. * Remote beacon (center) button.
*/ */
//% whenUsed block="remote button center" weight=95 fixedInstance //% whenUsed block="center" weight=95 fixedInstance
export const remoteButtonCenter = __irButton(InfraredRemoteButton.CenterBeacon) export const remoteButtonCenter = __irButton(InfraredRemoteButton.CenterBeacon)
/** /**
* Remote top-left button. * 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) export const remoteButtonTopLeft = __irButton(InfraredRemoteButton.TopLeft)
/** /**
* Remote top-right button. * 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) export const remoteButtonTopRight = __irButton(InfraredRemoteButton.TopRight)
/** /**
* Remote bottom-left button. * 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) export const remoteButtonBottomLeft = __irButton(InfraredRemoteButton.BottomLeft)
/** /**
* Remote bottom-right button. * 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) export const remoteButtonBottomRight = __irButton(InfraredRemoteButton.BottomRight)
} }

View File

@ -30,10 +30,10 @@ namespace sensors {
* @param body code to run when the event is raised * @param body code to run when the event is raised
*/ */
//% help=sensors/touch-sensor/on-event //% help=sensors/touch-sensor/on-event
//% blockId=touchEvent block="on %sensor|%event" //% blockId=touchEvent block="on **touch** %this|%event"
//% parts="touch" //% parts="touch"
//% blockNamespace=sensors //% blockNamespace=sensors
//% sensor.fieldEditor="ports" //% this.fieldEditor="ports"
//% weight=99 blockGap=12 //% weight=99 blockGap=12
//% group="Touch Sensor" //% group="Touch Sensor"
onEvent(ev: ButtonEvent, body: () => void) { onEvent(ev: ButtonEvent, body: () => void) {
@ -46,10 +46,10 @@ namespace sensors {
* @param event the kind of button gesture that needs to be detected * @param event the kind of button gesture that needs to be detected
*/ */
//% help=sensors/touch-sensor/pause-until //% help=sensors/touch-sensor/pause-until
//% blockId=touchWaitUntil block="pause until %sensor|%event" //% blockId=touchWaitUntil block="pause until **touch** %this|%event"
//% parts="touch" //% parts="touch"
//% blockNamespace=sensors //% blockNamespace=sensors
//% sensor.fieldEditor="ports" //% this.fieldEditor="ports"
//% weight=98 blockGap=12 //% weight=98 blockGap=12
//% group="Touch Sensor" //% group="Touch Sensor"
pauseUntil(ev: ButtonEvent) { pauseUntil(ev: ButtonEvent) {
@ -61,11 +61,11 @@ namespace sensors {
* @param sensor the port to query the request * @param sensor the port to query the request
*/ */
//% help=sensors/touch-sensor/is-pressed //% help=sensors/touch-sensor/is-pressed
//% block="%sensor|is pressed" //% block="**touch** %this|is pressed"
//% blockId=touchIsPressed //% blockId=touchIsPressed
//% parts="touch" //% parts="touch"
//% blockNamespace=sensors //% blockNamespace=sensors
//% sensor.fieldEditor="ports" //% this.fieldEditor="ports"
//% weight=81 blockGap=8 //% weight=81 blockGap=8
//% group="Touch Sensor" //% group="Touch Sensor"
isPressed() { isPressed() {
@ -77,11 +77,11 @@ namespace sensors {
* @param sensor the port to query the request * @param sensor the port to query the request
*/ */
//% help=sensors/touch-sensor/was-pressed //% help=sensors/touch-sensor/was-pressed
//% block="%sensor|was pressed" //% block="**touch** %this|was pressed"
//% blockId=touchWasPressed //% blockId=touchWasPressed
//% parts="touch" //% parts="touch"
//% blockNamespace=sensors //% blockNamespace=sensors
//% sensor.fieldEditor="ports" //% this.fieldEditor="ports"
//% weight=81 //% weight=81
//% group="Touch Sensor" //% group="Touch Sensor"
wasPressed() { 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) 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) 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) 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) export const touch4: TouchSensor = new TouchSensor(4)
} }

View File

@ -43,10 +43,10 @@ namespace sensors {
*/ */
//% help=sensors/ultrasonic/on-event //% help=sensors/ultrasonic/on-event
//% blockId=ultrasonicOn //% blockId=ultrasonicOn
//% block="on %sensor|%event" //% block="on **ultrasonic** %this|%event"
//% parts="ultrasonicsensor" //% parts="ultrasonicsensor"
//% blockNamespace=sensors //% blockNamespace=sensors
//% sensor.fieldEditor="ports" //% this.fieldEditor="ports"
//% weight=100 blockGap=8 //% weight=100 blockGap=8
//% group="Ultrasonic Sensor" //% group="Ultrasonic Sensor"
onEvent(event: UltrasonicSensorEvent, handler: () => void) { onEvent(event: UltrasonicSensorEvent, handler: () => void) {
@ -57,13 +57,13 @@ namespace sensors {
* Waits for the event to occur * Waits for the event to occur
*/ */
//% help=sensors/ultrasonic/pause-until //% help=sensors/ultrasonic/pause-until
//% block="pause until %sensor| %event" //% block="pause until **ultrasonic** %this| %event"
//% blockId=ultrasonicWait //% blockId=ultrasonicWait
//% parts="ultrasonicsensor" //% parts="ultrasonicsensor"
//% blockNamespace=sensors //% blockNamespace=sensors
//% sensor.fieldEditor="ports" //% this.fieldEditor="ports"
//% weight=99 blockGap=8 //% weight=99 blockGap=8
//% group="Ultrasonic Sensor" //% group="Ultrasonic Sensor"
pauseUntil(event: UltrasonicSensorEvent) { pauseUntil(event: UltrasonicSensorEvent) {
control.waitForEvent(this._id, event); control.waitForEvent(this._id, event);
} }
@ -73,13 +73,13 @@ namespace sensors {
* @param sensor the ultrasonic sensor port * @param sensor the ultrasonic sensor port
*/ */
//% help=sensors/ultrasonic/distance //% help=sensors/ultrasonic/distance
//% block="%sensor|distance" //% block="**ultrasonic** %this|distance"
//% blockId=sonarGetDistance //% blockId=sonarGetDistance
//% parts="ultrasonicsensor" //% parts="ultrasonicsensor"
//% blockNamespace=sensors //% blockNamespace=sensors
//% sensor.fieldEditor="ports" //% this.fieldEditor="ports"
//% weight=65 //% weight=65
//% group="Ultrasonic Sensor" //% group="Ultrasonic Sensor"
distance(): number { distance(): number {
// it supposedly also has an inch mode, but we stick to cm // it supposedly also has an inch mode, but we stick to cm
this._setMode(0) this._setMode(0)
@ -92,9 +92,10 @@ namespace sensors {
* @param condition the dark or bright light condition * @param condition the dark or bright light condition
* @param value the value threshold * @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 //% group="Threshold" blockGap=8 weight=80
//% value.min=0 value.max=255 //% value.min=0 value.max=255
//% this.fieldEditor="ports"
setThreshold(condition: UltrasonicSensorEvent, value: number) { setThreshold(condition: UltrasonicSensorEvent, value: number) {
switch (condition) { switch (condition) {
case UltrasonicSensorEvent.ObjectNear: this.promixityThreshold.setLowThreshold(value); break; case UltrasonicSensorEvent.ObjectNear: this.promixityThreshold.setLowThreshold(value); break;
@ -107,9 +108,9 @@ namespace sensors {
* Gets the threshold value * Gets the threshold value
* @param condition the proximity condition * @param condition the proximity condition
*/ */
//% blockId=ultrasonicGetThreshold block="%sensor|%condition" //% blockId=ultrasonicGetThreshold block="**ultrasonic** %this|%condition"
//% group="Threshold" blockGap=8 weight=79 //% group="Threshold" blockGap=8 weight=79
//% sensor.fieldEditor="ports" //% this.fieldEditor="ports"
threshold(condition: UltrasonicSensorEvent): number { threshold(condition: UltrasonicSensorEvent): number {
switch (condition) { switch (condition) {
case UltrasonicSensorEvent.ObjectNear: this.promixityThreshold.threshold(ThresholdState.Low); break; 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) 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) 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) 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) export const ultrasonic3: UltraSonicSensor = new UltraSonicSensor(3)
} }