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
5 changed files with 96 additions and 90 deletions

View File

@ -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)
}