From 34a5aeb7d2e7b4afbb357571ea1cdf53a776c58f Mon Sep 17 00:00:00 2001 From: Peli de Halleux Date: Thu, 30 Nov 2017 09:53:43 -0800 Subject: [PATCH] moving IR as well --- libs/core/_locales/core-jsdoc-strings.json | 14 ----------- libs/core/_locales/core-strings.json | 21 ---------------- libs/core/pxt.json | 1 - libs/ev3/pxt.json | 3 ++- libs/infrared-sensor/README.md | 3 +++ .../infrared-sensor-jsdoc-strings.json | 16 +++++++++++++ .../_locales/infrared-sensor-strings.json | 24 +++++++++++++++++++ libs/{core => infrared-sensor}/ir.ts | 8 +++---- libs/infrared-sensor/pxt.json | 15 ++++++++++++ libs/infrared-sensor/test.ts | 0 libs/ultrasonic-sensor/README.md | 4 ++-- pxtarget.json | 1 + 12 files changed, 66 insertions(+), 44 deletions(-) create mode 100644 libs/infrared-sensor/README.md create mode 100644 libs/infrared-sensor/_locales/infrared-sensor-jsdoc-strings.json create mode 100644 libs/infrared-sensor/_locales/infrared-sensor-strings.json rename libs/{core => infrared-sensor}/ir.ts (97%) create mode 100644 libs/infrared-sensor/pxt.json create mode 100644 libs/infrared-sensor/test.ts diff --git a/libs/core/_locales/core-jsdoc-strings.json b/libs/core/_locales/core-jsdoc-strings.json index 6f82c463..7d672f03 100644 --- a/libs/core/_locales/core-jsdoc-strings.json +++ b/libs/core/_locales/core-jsdoc-strings.json @@ -70,20 +70,6 @@ "screen.unpackPNG": "Decompresses a 1-bit gray scale PNG image to image format.", "sensors.GyroSensor.angle": "Get the current angle from the gyroscope.", "sensors.GyroSensor.rate": "Get the current rotation rate from the gyroscope.", - "sensors.InfraredSensor.on": "Registers code to run when an object is getting near.", - "sensors.InfraredSensor.on|param|handler": "the code to run when detected", - "sensors.InfraredSensor.proximity": "Get the promixity measured by the infrared sensor, from ``0`` (close) to ``100`` (far)", - "sensors.InfraredSensor.remoteCommand": "Get the remote commandreceived the infrared sensor.", - "sensors.InfraredSensor.waitUntil": "Waits for the event to occur", - "sensors.RemoteInfraredBeaconButton.isPressed": "Check if a remote button is currently pressed or not.", - "sensors.RemoteInfraredBeaconButton.onEvent": "Do something when a button or sensor is clicked, up or down", - "sensors.RemoteInfraredBeaconButton.onEvent|param|body": "code to run when the event is raised", - "sensors.RemoteInfraredBeaconButton.wasPressed": "See if the remote button was pressed again since the last time you checked.", - "sensors.remoteButtonBottomLeft": "Remote bottom-left button.", - "sensors.remoteButtonBottomRight": "Remote bottom-right button.", - "sensors.remoteButtonCenter": "Remote beacon (center) button.", - "sensors.remoteButtonTopLeft": "Remote top-left button.", - "sensors.remoteButtonTopRight": "Remote top-right button.", "serial": "Reading and writing data over a serial connection.", "serial.writeDmesg": "Send DMESG debug buffer over serial." } \ No newline at end of file diff --git a/libs/core/_locales/core-strings.json b/libs/core/_locales/core-strings.json index 2448ecc8..3da8c2f7 100644 --- a/libs/core/_locales/core-strings.json +++ b/libs/core/_locales/core-strings.json @@ -2,8 +2,6 @@ "ButtonEvent.Click|block": "click", "ButtonEvent.Down|block": "down", "ButtonEvent.Up|block": "up", - "InfraredSensorEvent.ObjectDetected|block": "object detected", - "InfraredSensorEvent.ObjectNear|block": "object near", "LightsPattern.GreenFlash|block": "Flashing Green", "LightsPattern.GreenPulse|block": "Pulsing Green", "LightsPattern.Green|block": "Green", @@ -58,27 +56,10 @@ "screen|block": "screen", "sensors.GyroSensor.angle|block": "`icons.gyroSensor` %sensor|angle", "sensors.GyroSensor.rate|block": "`icons.gyroSensor` %sensor|rotation rate", - "sensors.InfraredSensor.on|block": "on `icons.infraredSensor` %sensor|%event", - "sensors.InfraredSensor.proximity|block": "`icons.infraredSensor` %infrared|proximity", - "sensors.InfraredSensor.remoteCommand|block": "`icons.infraredSensor` %infrared|remote command", - "sensors.InfraredSensor.waitUntil|block": "wait until `icons.infraredSensor` %sensor| %event", - "sensors.RemoteInfraredBeaconButton.isPressed|block": "`icons.infraredSensor` %button|is pressed", - "sensors.RemoteInfraredBeaconButton.onEvent|block": "on `icons.infraredSensor` %button|%event", - "sensors.RemoteInfraredBeaconButton.wasPressed|block": "`icons.infraredSensor` %button|was pressed", "sensors.gyro1|block": "1", "sensors.gyro2|block": "2", "sensors.gyro3|block": "3", "sensors.gyro4|block": "4", - "sensors.infraredSensor1|block": "1", - "sensors.infraredSensor2|block": "2", - "sensors.infraredSensor3|block": "3", - "sensors.infraredSensor4|block": "4", - "sensors.remoteButtonBottomLeft|block": "bottom-left", - "sensors.remoteButtonBottomRight|block": "bottom-right", - "sensors.remoteButtonCenter|block": "center", - "sensors.remoteButtonTopLeft|block": "top-left", - "sensors.remoteButtonTopRight|block": "top-right", - "sensors|block": "sensors", "serial|block": "serial", "{id:category}Brick": "Brick", "{id:category}Control": "Control", @@ -92,9 +73,7 @@ "{id:category}Serial": "Serial", "{id:group}Buttons": "Buttons", "{id:group}Gyro Sensor": "Gyro Sensor", - "{id:group}Infrared Sensor": "Infrared Sensor", "{id:group}Light": "Light", "{id:group}Motors": "Motors", - "{id:group}Remote Infrared Beacon": "Remote Infrared Beacon", "{id:group}Screen": "Screen" } \ No newline at end of file diff --git a/libs/core/pxt.json b/libs/core/pxt.json index 250ecca5..203eb3b7 100644 --- a/libs/core/pxt.json +++ b/libs/core/pxt.json @@ -18,7 +18,6 @@ "output.ts", "core.ts", "input.ts", - "ir.ts", "gyro.ts", "shims.d.ts", "enums.d.ts", diff --git a/libs/ev3/pxt.json b/libs/ev3/pxt.json index dcd28778..6d5ca312 100644 --- a/libs/ev3/pxt.json +++ b/libs/ev3/pxt.json @@ -11,7 +11,8 @@ "music": "file:../music", "color-sensor": "file:../color-sensor", "touch-sensor": "file:../touch-sensor", - "ultrasonic-sensor": "file:../ultrasonic-sensor" + "ultrasonic-sensor": "file:../ultrasonic-sensor", + "infrared-sensor": "file:../infrared-sensor" }, "public": true } diff --git a/libs/infrared-sensor/README.md b/libs/infrared-sensor/README.md new file mode 100644 index 00000000..dc893e0f --- /dev/null +++ b/libs/infrared-sensor/README.md @@ -0,0 +1,3 @@ +# Infrared sensor + +The library to interact with the Infrared Sensor. \ No newline at end of file diff --git a/libs/infrared-sensor/_locales/infrared-sensor-jsdoc-strings.json b/libs/infrared-sensor/_locales/infrared-sensor-jsdoc-strings.json new file mode 100644 index 00000000..85472c80 --- /dev/null +++ b/libs/infrared-sensor/_locales/infrared-sensor-jsdoc-strings.json @@ -0,0 +1,16 @@ +{ + "sensors.InfraredSensor.onEvent": "Registers code to run when an object is getting near.", + "sensors.InfraredSensor.onEvent|param|handler": "the code to run when detected", + "sensors.InfraredSensor.proximity": "Get the promixity measured by the infrared sensor, from ``0`` (close) to ``100`` (far)", + "sensors.InfraredSensor.remoteCommand": "Get the remote commandreceived the infrared sensor.", + "sensors.InfraredSensor.waitUntil": "Waits for the event to occur", + "sensors.RemoteInfraredBeaconButton.isPressed": "Check if a remote button is currently pressed or not.", + "sensors.RemoteInfraredBeaconButton.onEvent": "Do something when a button or sensor is clicked, up or down", + "sensors.RemoteInfraredBeaconButton.onEvent|param|body": "code to run when the event is raised", + "sensors.RemoteInfraredBeaconButton.wasPressed": "See if the remote button was pressed again since the last time you checked.", + "sensors.remoteButtonBottomLeft": "Remote bottom-left button.", + "sensors.remoteButtonBottomRight": "Remote bottom-right button.", + "sensors.remoteButtonCenter": "Remote beacon (center) button.", + "sensors.remoteButtonTopLeft": "Remote top-left button.", + "sensors.remoteButtonTopRight": "Remote top-right button." +} \ No newline at end of file diff --git a/libs/infrared-sensor/_locales/infrared-sensor-strings.json b/libs/infrared-sensor/_locales/infrared-sensor-strings.json new file mode 100644 index 00000000..ac335a2d --- /dev/null +++ b/libs/infrared-sensor/_locales/infrared-sensor-strings.json @@ -0,0 +1,24 @@ +{ + "InfraredSensorEvent.ObjectDetected|block": "object detected", + "InfraredSensorEvent.ObjectNear|block": "object near", + "sensors.InfraredSensor.onEvent|block": "on `icons.infraredSensor` %sensor|%event", + "sensors.InfraredSensor.proximity|block": "`icons.infraredSensor` %infrared|proximity", + "sensors.InfraredSensor.remoteCommand|block": "`icons.infraredSensor` %infrared|remote command", + "sensors.InfraredSensor.waitUntil|block": "wait until `icons.infraredSensor` %sensor| %event", + "sensors.RemoteInfraredBeaconButton.isPressed|block": "`icons.infraredSensor` %button|is pressed", + "sensors.RemoteInfraredBeaconButton.onEvent|block": "on `icons.infraredSensor` %button|%event", + "sensors.RemoteInfraredBeaconButton.wasPressed|block": "`icons.infraredSensor` %button|was pressed", + "sensors.infraredSensor1|block": "1", + "sensors.infraredSensor2|block": "2", + "sensors.infraredSensor3|block": "3", + "sensors.infraredSensor4|block": "4", + "sensors.remoteButtonBottomLeft|block": "bottom-left", + "sensors.remoteButtonBottomRight|block": "bottom-right", + "sensors.remoteButtonCenter|block": "center", + "sensors.remoteButtonTopLeft|block": "top-left", + "sensors.remoteButtonTopRight|block": "top-right", + "sensors|block": "sensors", + "{id:category}Sensors": "Sensors", + "{id:group}Infrared Sensor": "Infrared Sensor", + "{id:group}Remote Infrared Beacon": "Remote Infrared Beacon" +} \ No newline at end of file diff --git a/libs/core/ir.ts b/libs/infrared-sensor/ir.ts similarity index 97% rename from libs/core/ir.ts rename to libs/infrared-sensor/ir.ts index 31af128a..bf7f3b69 100644 --- a/libs/core/ir.ts +++ b/libs/infrared-sensor/ir.ts @@ -199,10 +199,8 @@ namespace sensors { //% blockNamespace=sensors //% weight=100 blockGap=8 //% group="Infrared Sensor" - on(event: InfraredSensorEvent, handler: () => void) { + onEvent(event: InfraredSensorEvent, handler: () => void) { control.onEvent(this._id, InfraredSensorEvent.ObjectNear, handler); - if ( this.proximity() == InfraredSensorEvent.ObjectNear) - control.runInBackground(handler); } /** @@ -230,7 +228,7 @@ namespace sensors { //% blockNamespace=sensors //% weight=65 blockGap=8 //% group="Infrared Sensor" - proximity() { + proximity(): number { this._setMode(IrSensorMode.Proximity) return this.getNumber(NumberFormat.UInt8LE, 0) } @@ -246,7 +244,7 @@ namespace sensors { //% blockNamespace=sensors //% weight=65 blockGap=8 //% group="Infrared Sensor" - remoteCommand() { + remoteCommand(): number { this._setMode(IrSensorMode.RemoteControl) return this.getNumber(NumberFormat.UInt8LE, this.channel) } diff --git a/libs/infrared-sensor/pxt.json b/libs/infrared-sensor/pxt.json new file mode 100644 index 00000000..2c41e8c1 --- /dev/null +++ b/libs/infrared-sensor/pxt.json @@ -0,0 +1,15 @@ +{ + "name": "infrared-sensor", + "description": "Infrared Sensor support", + "files": [ + "README.md", + "ir.ts" + ], + "testFiles": [ + "test.ts" + ], + "public": true, + "dependencies": { + "core": "file:../core" + } +} \ No newline at end of file diff --git a/libs/infrared-sensor/test.ts b/libs/infrared-sensor/test.ts new file mode 100644 index 00000000..e69de29b diff --git a/libs/ultrasonic-sensor/README.md b/libs/ultrasonic-sensor/README.md index 18721304..914c6342 100644 --- a/libs/ultrasonic-sensor/README.md +++ b/libs/ultrasonic-sensor/README.md @@ -1,3 +1,3 @@ -# Touch sensor +# Ultrasonic sensor -The library to interact with the Touch Sensor. \ No newline at end of file +The library to interact with the Ultrasonic Sensor. \ No newline at end of file diff --git a/pxtarget.json b/pxtarget.json index cabbb4e5..1f16ae36 100644 --- a/pxtarget.json +++ b/pxtarget.json @@ -13,6 +13,7 @@ "libs/color-sensor", "libs/touch-sensor", "libs/ultrasonic-sensor", + "libs/infrared-sensor", "libs/ev3" ], "simulator": {