From 7cafe4810b052d78c8a6a14375c250b8b4ea8c7e Mon Sep 17 00:00:00 2001 From: hogan96 <234513426@qq.com> Date: Wed, 10 May 2023 09:43:18 +0800 Subject: [PATCH] =?UTF-8?q?=E8=80=B3=E6=B4=9E=E8=B6=85=E5=A3=B0=E6=B3=A2?= =?UTF-8?q?=E9=92=88=E5=AF=B9microbit=E7=89=88=E6=9C=AC=E8=B0=83=E6=95=B4?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E5=80=BC/=E5=A2=9E=E5=8A=A0=E6=AF=AB?= =?UTF-8?q?=E7=B1=B3=E5=8D=95=E4=BD=8D=E9=80=89=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/tasks.json | 87 +++++++++++++++++++--------- .vscode/tasks.json.old | 36 ++++++++++++ _locales/zh-cn/robotbit-strings.json | 5 +- _locales/zh-tw/robotbit-strings.json | 5 +- main.ts | 26 ++++++++- pxt.json | 12 +++- 6 files changed, 136 insertions(+), 35 deletions(-) create mode 100644 .vscode/tasks.json.old diff --git a/.vscode/tasks.json b/.vscode/tasks.json index e193aef..0384f15 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -1,36 +1,67 @@ // A task runner that calls the PXT compiler and { - "version": "0.1.0", + "version": "2.0.0", // The command is pxt. Assumes that PXT has been installed using npm install -g pxt "command": "pxt", - // The command is a shell script - "isShellCommand": true, - - // Show the output window always. - "showOutput": "always", - - "tasks": [{ - "taskName": "deploy", - "isBuildCommand": true, - "problemMatcher": "$tsc", - "args": [""] - }, { - "taskName": "build", - "isTestCommand": true, - "problemMatcher": "$tsc", - "args": [""] - }, { - "taskName": "clean", - "isTestCommand": true, - "problemMatcher": "$tsc", - "args": [""] - }, { - "taskName": "serial", - "isTestCommand": true, - "problemMatcher": "$tsc", - "args": [""] - }] + "tasks": [ + { + "label": "deploy", + "type": "shell", + "command": "pxt", + "args": [ + "deploy", + "" + ], + "problemMatcher": "$tsc", + "group": { + "_id": "build", + "isDefault": false + } + }, + { + "label": "build", + "type": "shell", + "command": "pxt", + "args": [ + "build", + "" + ], + "problemMatcher": "$tsc", + "group": { + "_id": "test", + "isDefault": false + } + }, + { + "label": "clean", + "type": "shell", + "command": "pxt", + "args": [ + "clean", + "" + ], + "problemMatcher": "$tsc", + "group": { + "_id": "test", + "isDefault": false + } + }, + { + "label": "serial", + "type": "shell", + "command": "pxt", + "args": [ + "serial", + "" + ], + "problemMatcher": "$tsc", + "group": { + "_id": "test", + "isDefault": false + } + } + ] } diff --git a/.vscode/tasks.json.old b/.vscode/tasks.json.old new file mode 100644 index 0000000..e193aef --- /dev/null +++ b/.vscode/tasks.json.old @@ -0,0 +1,36 @@ + +// A task runner that calls the PXT compiler and +{ + "version": "0.1.0", + + // The command is pxt. Assumes that PXT has been installed using npm install -g pxt + "command": "pxt", + + // The command is a shell script + "isShellCommand": true, + + // Show the output window always. + "showOutput": "always", + + "tasks": [{ + "taskName": "deploy", + "isBuildCommand": true, + "problemMatcher": "$tsc", + "args": [""] + }, { + "taskName": "build", + "isTestCommand": true, + "problemMatcher": "$tsc", + "args": [""] + }, { + "taskName": "clean", + "isTestCommand": true, + "problemMatcher": "$tsc", + "args": [""] + }, { + "taskName": "serial", + "isTestCommand": true, + "problemMatcher": "$tsc", + "args": [""] + }] +} diff --git a/_locales/zh-cn/robotbit-strings.json b/_locales/zh-cn/robotbit-strings.json index ec5da5a..89cb5c1 100644 --- a/_locales/zh-cn/robotbit-strings.json +++ b/_locales/zh-cn/robotbit-strings.json @@ -14,11 +14,14 @@ "robotbit.MotorStop|block": "电机 停止|%index|", "robotbit.MotorStopAll|block": "停止所有电机", "robotbit.RgbUltrasonic|block": "猫耳RGB超声波|引脚 %pin", - "robotbit.HoleUltrasonic|block": "猫耳洞超声波|引脚 %pin", + "robotbit.HoleUltrasonic|block": "猫耳洞超声波|引脚 %pin|单位 %unit", "robotbit.MatrixDraw|block": "LED矩阵 描点|X %x|Y %y", "robotbit.MatrixClear|block": "清空 LED矩阵 ", "robotbit.MatrixRefresh|block": "刷新 LED矩阵 ", + "robotbit.ValueUnit.Millimeter|block": "毫米", + "robotbit.ValueUnit.Centimeters|block": "厘米", + "{id:group}Servo": "舵机", "{id:group}Motor": "电机/步进电机", "{id:group}Modules": "外接模块" diff --git a/_locales/zh-tw/robotbit-strings.json b/_locales/zh-tw/robotbit-strings.json index e5adc49..53a56d3 100644 --- a/_locales/zh-tw/robotbit-strings.json +++ b/_locales/zh-tw/robotbit-strings.json @@ -13,10 +13,13 @@ "robotbit.MotorStop|block": "馬達 停止|%index|", "robotbit.MotorStopAll|block": "停止所有馬達", "robotbit.RgbUltrasonic|block": "貓耳RGB超聲波|腳位 %pin", - "robotbit.HoleUltrasonic|block": "貓耳洞超聲波|腳位 %pin", + "robotbit.HoleUltrasonic|block": "貓耳洞超聲波|腳位 %pin|單位 %unit", "robotbit.MatrixDraw|block": "LED矩陣 描點|X %x|Y %y", "robotbit.MatrixClear|block": "清空 LED矩陣", + "robotbit.ValueUnit.Millimeter|block": "毫米", + "robotbit.ValueUnit.Centimeters|block": "厘米", + "{id:group}Servo": "舵機", "{id:group}Motor": "馬達/步進", "{id:group}Modules": "外部模塊" diff --git a/main.ts b/main.ts index 0f40404..06c082a 100644 --- a/main.ts +++ b/main.ts @@ -91,6 +91,13 @@ namespace robotbit { T5B0 = 1800 } + export enum ValueUnit { + //% block="mm" + Millimeter, + //% block="cm" + Centimeters + } + let initialized = false let initializedMatrix = false let neoStrip: neopixel.Strip; @@ -524,10 +531,12 @@ namespace robotbit { /** * signal pin * @param pin singal pin; eg: DigitalPin.P1 + * @param unit desired conversion unit */ - //% blockId=robotbit_holeultrasonicver block="Ultrasonic(with LEGO Hole)|pin %pin" + //% blockId=robotbit_holeultrasonicver block="Ultrasonic(with LEGO Hole)|pin %pin|unit %unit" //% group="Modules" weight=40 - export function HoleUltrasonic(pin: DigitalPin): number { + export function HoleUltrasonic(pin: DigitalPin, unit: ValueUnit): number { + pins.setPull(pin, PinPullMode.PullNone); // pins.setPull(pin, PinPullMode.PullDown); pins.digitalWritePin(pin, 0); control.waitMicros(2); @@ -546,6 +555,17 @@ namespace robotbit { distanceBuf = d; pins.digitalWritePin(pin, 0); basic.pause(15) - return Math.floor(ret / 40 + (ret / 800)); + if (parseInt(control.hardwareVersion()) == 2) { + d = ret *10 /58; + } + else{ + // return Math.floor(ret / 40 + (ret / 800)); + d = ret * 15 / 58; + } + switch (unit) { + case ValueUnit.Millimeter: return Math.floor(d) + case ValueUnit.Centimeters: return Math.floor(d/10) + default: return d; + } } } diff --git a/pxt.json b/pxt.json index ac4db69..f5c668e 100644 --- a/pxt.json +++ b/pxt.json @@ -1,12 +1,13 @@ { "name": "robotbit", - "version": "0.4.4", + "version": "0.4.5", "description": "Extension for Kittenbot Robotbit", "license": "MIT", "dependencies": { "core": "*", "neopixel": "github:kittenbot/pxt-neopixel", - "SensorPlus": "github:kittenbothk/pxt-moduleplus" + "SensorPlus": "github:kittenbothk/pxt-moduleplus", + "microphone": "*" }, "files": [ "README.md", @@ -18,5 +19,12 @@ "test.ts" ], "public": true, + "targetVersions": { + "target": "5.1.26", + "targetId": "microbit" + }, + "supportedTargets": [ + "microbit" + ], "preferredEditor": "tsprj" }