From b0380fbef848dbc9886e576329893a685a41333b Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Tue, 24 Oct 2017 15:33:28 -0700 Subject: [PATCH] more annotations --- libs/core/_locales/core-jsdoc-strings.json | 2 +- libs/core/_locales/core-strings.json | 10 +++++++++- libs/core/buttons.ts | 3 +++ libs/core/ir.ts | 4 +++- libs/core/ultrasonic.ts | 23 ++++++++++++++++------ 5 files changed, 33 insertions(+), 9 deletions(-) diff --git a/libs/core/_locales/core-jsdoc-strings.json b/libs/core/_locales/core-jsdoc-strings.json index 72ee4d8c..489af20e 100644 --- a/libs/core/_locales/core-jsdoc-strings.json +++ b/libs/core/_locales/core-jsdoc-strings.json @@ -30,7 +30,7 @@ "input.GyroSensor.rate": "Get the current rotation rate from the gyroscope.", "input.IrSensor.distance": "Get the distance measured by the infrared sensor.", "input.IrSensor.remoteCommand": "Get the remote commandreceived the infrared sensor.", - "input.UltraSonicSensor.getDistance": "Get distance in mm", + "input.UltraSonicSensor.distance": "Gets the distance from the sonar in millimeters", "input.buttonDown": "Down button.", "input.buttonEnter": "Enter button.", "input.buttonLeft": "Left button.", diff --git a/libs/core/_locales/core-strings.json b/libs/core/_locales/core-strings.json index dd67b605..67abf2d5 100644 --- a/libs/core/_locales/core-strings.json +++ b/libs/core/_locales/core-strings.json @@ -25,6 +25,7 @@ "input.GyroSensor.rate|block": "%color|rotation rate", "input.IrSensor.distance|block": "%infrared|distance", "input.IrSensor.remoteCommand|block": "%infrared|remote command", + "input.UltraSonicSensor.distance|block": "%sonar|distance", "input.buttonDown|block": "button down", "input.buttonEnter|block": "button enter", "input.buttonLeft|block": "button left", @@ -47,6 +48,10 @@ "input.touchSensor2|block": "touch sensor 2", "input.touchSensor3|block": "touch sensor 3", "input.touchSensor4|block": "touch sensor 4", + "input.ultrasonic1|block": "ultrasonic 1", + "input.ultrasonic2|block": "ultrasonic 1", + "input.ultrasonic3|block": "ultrasonic 1", + "input.ultrasonic4|block": "ultrasonic 1", "input|block": "input", "output.getCurrentSpeed|block": "motor %out|speed", "output.pattern|block": "%pattern", @@ -65,9 +70,12 @@ "{id:category}Output": "Output", "{id:category}Screen": "Screen", "{id:category}Serial": "Serial", + "{id:group}Buttons": "Buttons", "{id:group}Color Sensor": "Color Sensor", "{id:group}Gyroscope": "Gyroscope", + "{id:group}Infrared sensor": "Infrared sensor", "{id:group}Lights": "Lights", "{id:group}Motors": "Motors", - "{id:group}Screen": "Screen" + "{id:group}Screen": "Screen", + "{id:group}Sonar": "Sonar" } \ No newline at end of file diff --git a/libs/core/buttons.ts b/libs/core/buttons.ts index 2090b9f8..1ef7d54c 100644 --- a/libs/core/buttons.ts +++ b/libs/core/buttons.ts @@ -93,6 +93,7 @@ namespace input { //% button.fieldOptions.width=220 //% button.fieldOptions.columns=3 //% weight=81 blockGap=8 + //% group="Buttons" isPressed() { return this._isPressed } @@ -110,6 +111,7 @@ namespace input { //% button.fieldOptions.width=220 //% button.fieldOptions.columns=3 //% weight=80 blockGap=8 + //% group="Buttons" wasPressed() { const r = this._wasPressed this._wasPressed = false @@ -130,6 +132,7 @@ namespace input { //% button.fieldOptions.width=220 //% button.fieldOptions.columns=3 //% weight=99 + //% group="Buttons" onEvent(ev: ButtonEvent, body: () => void) { control.onEvent(this._id, ev, body) } diff --git a/libs/core/ir.ts b/libs/core/ir.ts index 542a86f1..492fa700 100644 --- a/libs/core/ir.ts +++ b/libs/core/ir.ts @@ -118,7 +118,8 @@ namespace input { //% blockId=infraredGetDistance //% parts="infrared" //% blockNamespace=input - //% weight=65 blockGap=8 + //% weight=65 blockGap=8 + //% group="Infrared sensor" distance() { this.setMode(IrSensorMode.Proximity) return this.getNumber(NumberFormat.UInt8LE, 0) @@ -134,6 +135,7 @@ namespace input { //% parts="infrared" //% blockNamespace=input //% weight=65 blockGap=8 + //% group="Infrared sensor" remoteCommand() { this.setMode(IrSensorMode.RemoteControl) return this.getNumber(NumberFormat.UInt8LE, this.channel) diff --git a/libs/core/ultrasonic.ts b/libs/core/ultrasonic.ts index 0a16cb20..14e3166e 100644 --- a/libs/core/ultrasonic.ts +++ b/libs/core/ultrasonic.ts @@ -1,5 +1,6 @@ namespace input { + //% fixedInstances export class UltraSonicSensor extends internal.UartSensor { constructor(port: number) { super(port) @@ -9,23 +10,33 @@ namespace input { return DAL.DEVICE_TYPE_ULTRASONIC } - /** Get distance in mm */ - getDistance() { + /** + * Gets the distance from the sonar in millimeters + * @param sonar the ultrasonic sensor + */ + //% help=input/ultrasonic/distance + //% block="%sonar|distance" + //% blockId=sonarGetDistance + //% parts="ultrasonic" + //% blockNamespace=input + //% weight=65 blockGap=8 + //% group="Sonar" + distance() { // it supposedly also has an inch mode, but we stick to mm this._setMode(0) return this.getNumber(NumberFormat.UInt16LE, 0) & 0x0fff } } - //% whenUsed + //% fixedInstance whenUsed block="ultrasonic 1" export const ultrasonic1: UltraSonicSensor = new UltraSonicSensor(1) - //% whenUsed + //% fixedInstance whenUsed block="ultrasonic 1" export const ultrasonic2: UltraSonicSensor = new UltraSonicSensor(2) - //% whenUsed + //% fixedInstance whenUsed block="ultrasonic 1" export const ultrasonic3: UltraSonicSensor = new UltraSonicSensor(3) - //% whenUsed + //% fixedInstance whenUsed block="ultrasonic 1" export const ultrasonic4: UltraSonicSensor = new UltraSonicSensor(4) }