diff --git a/.github/makecode/blocks.png b/.github/makecode/blocks.png new file mode 100644 index 0000000..9dbeaa2 --- /dev/null +++ b/.github/makecode/blocks.png @@ -0,0 +1 @@ +data:, \ No newline at end of file diff --git a/.github/makecode/blocksdiff.png b/.github/makecode/blocksdiff.png new file mode 100644 index 0000000..b8390ee Binary files /dev/null and b/.github/makecode/blocksdiff.png differ diff --git a/.github/workflows/cfg-check.yml b/.github/workflows/cfg-check.yml new file mode 100644 index 0000000..a098f8b --- /dev/null +++ b/.github/workflows/cfg-check.yml @@ -0,0 +1,37 @@ +name: Check pxt.json + +on: + push: + branches: + - 'master' + - 'main' + +jobs: + check-cfg: + runs-on: ubuntu-latest + strategy: + matrix: + node-version: [14.x] + steps: + - uses: actions/checkout@v2 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + - name: npm install + run: | + npm install -g pxt + pxt target microbit + - name: Checkout current state + run: | + git checkout -- . + git clean -fd + - name: Fix files listed in config if necessary + run: pxt checkpkgcfg + - name: Create Pull Request + uses: peter-evans/create-pull-request@v3 + continue-on-error: true + with: + title: 'Removing missing files from pxt.json' + commit-message: 'Removing missing files from pxt.json' + delete-branch: true diff --git a/.github/workflows/makecode.yml b/.github/workflows/makecode.yml new file mode 100644 index 0000000..c046b20 --- /dev/null +++ b/.github/workflows/makecode.yml @@ -0,0 +1,29 @@ +name: MakeCode + +on: [push] + +jobs: + build: + + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [14.x] + + steps: + - uses: actions/checkout@v1 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + - name: npm install + run: | + npm install -g pxt + pxt target microbit + - name: build + run: | + pxt install + pxt build --cloud + env: + CI: true diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d2196e7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,11 @@ +# MakeCode +built +node_modules +yotta_modules +yotta_targets +pxt_modules +_site +*.db +*.tgz +.header.json +.simstate.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..f8106d4 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,23 @@ +{ + "editor.formatOnType": true, + "files.autoSave": "afterDelay", + "files.watcherExclude": { + "**/.git/objects/**": true, + "**/built/**": true, + "**/node_modules/**": true, + "**/yotta_modules/**": true, + "**/yotta_targets": true, + "**/pxt_modules/**": true + }, + "files.associations": { + "*.blocks": "html", + "*.jres": "json" + }, + "search.exclude": { + "**/built": true, + "**/node_modules": true, + "**/yotta_modules": true, + "**/yotta_targets": true, + "**/pxt_modules": true + } +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..9ee2cf6 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,30 @@ + +// A task runner that calls the MakeCode (PXT) compiler +{ + "version": "2.0.0", + "tasks": [{ + "label": "pxt deploy", + "type": "shell", + "command": "pxt deploy --local", + "group": "build", + "problemMatcher": [ "$tsc" ] + }, { + "label": "pxt build", + "type": "shell", + "command": "pxt build --local", + "group": "build", + "problemMatcher": [ "$tsc" ] + }, { + "label": "pxt install", + "type": "shell", + "command": "pxt install", + "group": "build", + "problemMatcher": [ "$tsc" ] + }, { + "label": "pxt clean", + "type": "shell", + "command": "pxt clean", + "group": "test", + "problemMatcher": [ "$tsc" ] + }] +} diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..91ceacd --- /dev/null +++ b/Gemfile @@ -0,0 +1,2 @@ +source 'https://rubygems.org' +gem 'github-pages', group: :jekyll_plugins \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d96afd5 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2020 DFRobot + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..9068464 --- /dev/null +++ b/Makefile @@ -0,0 +1,10 @@ +all: deploy + +build: + pxt build + +deploy: + pxt deploy + +test: + pxt test diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/_config.yml b/_config.yml new file mode 100644 index 0000000..f56a029 --- /dev/null +++ b/_config.yml @@ -0,0 +1,8 @@ +makecode: + target: microbit + platform: microbit + home_url: https://makecode.microbit.org/ +theme: jekyll-theme-slate +include: + - assets + - README.md diff --git a/_locales/es/ir-strings.json b/_locales/es/ir-strings.json new file mode 100644 index 0000000..d8b0a30 --- /dev/null +++ b/_locales/es/ir-strings.json @@ -0,0 +1,6 @@ +{ + "IR.IR_callbackUser|block": "Al recibir IR", + "IR.IR_init|block": "Inicializar el sensor infrarrojo", + "IR.IR_read|block": "Leer IR" + +} \ No newline at end of file diff --git a/_locales/es/maqueen-strings.json b/_locales/es/maqueen-strings.json new file mode 100644 index 0000000..cf9e794 --- /dev/null +++ b/_locales/es/maqueen-strings.json @@ -0,0 +1,23 @@ +{ + "maqueen.Motors.M1|block": "izquierdo", + "maqueen.Motors.M2|block": "derecho", + "maqueen.Patrol.PatrolLeft|block": "izquierdo", + "maqueen.Patrol.PatrolRight|block": "derecho", + "maqueen.LEDswitch.turnOn|block": "encender", + "maqueen.LEDswitch.turnOff|block": "apagar", + "maqueen.LED.LEDLeft|block": "derecho", + "maqueen.LED.LEDRight|block": "izquierdo", + "maqueen.Dir.CW|block": "avanzar", + "maqueen.Dir.CCW|block": "retroceder", + "maqueen.motorStop|block": "Parar motor|%motors", + "maqueen.motorStopAll|block": "Parar motores", + "maqueen.motorRun|block": "Motor|%index|sentido|%Dir|velocidad|%speed", + "maqueen.IR_callbackUser|block": "Al recibir IR", + "maqueen.Ultrasonic|block": "Leer ultrasonidos en |%unit", + "maqueen.readPatrol|block": "Leer siguelínea|%patrol", + "maqueen.writeLED|block": "LED|%led|%ledswitch", + "maqueen.IR_read|block": "Leer IR", + "maqueen.servoRun|block": "Servomotor|%index|ángulo|%angle", + "maqueen.IR_read_version|block": "versión IR", + "maqueen.Motors.All|block": "ambos" +} diff --git a/_locales/fr/ir-strings.json b/_locales/fr/ir-strings.json new file mode 100644 index 0000000..0a200af --- /dev/null +++ b/_locales/fr/ir-strings.json @@ -0,0 +1,5 @@ +{ + "IR.IR_callbackUser|block": "quand l'IR reçoit", + "IR.IR_init|block": "Initialiser le capteur infrarouge.", + "IR.IR_read|block": "lire l'infrarouge" +} \ No newline at end of file diff --git a/_locales/fr/maqueen-strings.json b/_locales/fr/maqueen-strings.json new file mode 100644 index 0000000..4446558 --- /dev/null +++ b/_locales/fr/maqueen-strings.json @@ -0,0 +1,27 @@ +{ + "PingUnit.Centimeters|block": "cm", + "PingUnit.MicroSeconds|block": "μs", + "maqueen.Dir.CCW|block": "antihoraire", + "maqueen.Dir.CW|block": "horaire", + "maqueen.IR_callbackUser|block": "quand l'IR reçoit", + "maqueen.IR_read_version|block": "Obtenir des informations sur le produit", + "maqueen.IR_read|block": "lire l'infrarouge", + "maqueen.LED.LEDLeft|block": "LEDGauche", + "maqueen.LED.LEDRight|block": "LEDDroite", + "maqueen.LEDswitch.turnOff|block": "éteindre", + "maqueen.LEDswitch.turnOn|block": "allumer", + "maqueen.motorRun|block": "Moteur|%index|dir|%Dir|vitesse|%speed", + "maqueen.Patrol.PatrolLeft|block": "DétecteurGauche", + "maqueen.Patrol.PatrolRight|block": "DétecteurDroite", + "maqueen.servoRun|block": "Servo|%index|angle|%angle", + "maqueen.Motors.M1|block": "M1", + "maqueen.Motors.M2|block": "M2", + "maqueen.Motors.All|block": "All", + "maqueen.Servos.S1|block": "S1", + "maqueen.Servos.S2|block": "S2", + "maqueen.motorStopAll|block": "Stop tous les moteurs", + "maqueen.motorStop|block": "Stop le moteur|%motors", + "maqueen.readPatrol|block": "Lire détecteur|%patrol", + "maqueen.Ultrasonic|block": "unité du senseur|%unit", + "maqueen.writeLED|block": "%ledswitch|la led|%led" +} diff --git a/_locales/ja/ir-jsdoc-strings.json b/_locales/ja/ir-jsdoc-strings.json new file mode 100644 index 0000000..e69de29 diff --git a/_locales/ja/ir-strings.json b/_locales/ja/ir-strings.json new file mode 100644 index 0000000..a50592e --- /dev/null +++ b/_locales/ja/ir-strings.json @@ -0,0 +1,7 @@ +{ + + "IR.IR_callbackUser|block": "赤外線(V2): IRコードを受信したとき", + "IR.IR_init|block": "赤外線センサーを初期化する", + "IR.IR_read|block": "赤外線リモコンのキー値(V2)" + +} \ No newline at end of file diff --git a/_locales/ja/maqueen-jsdoc-strings.json b/_locales/ja/maqueen-jsdoc-strings.json new file mode 100644 index 0000000..a3d1463 --- /dev/null +++ b/_locales/ja/maqueen-jsdoc-strings.json @@ -0,0 +1,15 @@ +{ + "maqueen.IR_read": "赤外線リモコンからのコード", + "maqueen.IR_read_version": "ロボットのバージョン番号", + "maqueen.IR_callbackUser": "リモコンボタンが押されたときの動作", + "maqueen.Ultrasonic": "超音波変換器からの値", + "maqueen.ltEvent": "指定したライン監視センサーが特定の色を感知したときの動作", + "maqueen.motorRun": "モーターの回転方向と速度をセットする / モーター:左, 右, すべて / 回転方向:前, 後ろ / 速さ:0~255", + "maqueen.motorStop": "モーターを止める", + "maqueen.readPatrol": "ライン監視センサーからの値", + "maqueen.servoRun": "サーボモーターを特定の角度に回転させる / ポート:S1、S2 / 角度:0~180度", + "maqueen.writeLED": "LEDライトのオン/オフ", + "maqueenIR.initIR": "赤外線リモコン受信機を指定ポートに接続する", + "maqueenIR.onPressEvent": "リモコンの指定ボタンが押されたときの動作", + "maqueencb": "@file pxt-maqueen/maqueen.ts\n@brief DFRobot's maqueen makecode library.\n@n [Get the module here](https://www.dfrobot.com.cn/goods-1802.html)\n@n This is a MakeCode graphical programming education robot.\n* @copyright [DFRobot](http://www.dfrobot.com), 2016\n@copyright MIT Lesser General Public License\n* @author [email](jie.tang@dfrobot.com)\n@date 2019-10-08" +} diff --git a/_locales/ja/maqueen-strings.json b/_locales/ja/maqueen-strings.json new file mode 100644 index 0000000..631c125 --- /dev/null +++ b/_locales/ja/maqueen-strings.json @@ -0,0 +1,40 @@ +{ + "PingUnit.Centimeters|block": "cm", + "maqueen.Motors.M1|block": "左", + "maqueen.Motors.M2|block": "右", + "maqueen.Motors.All|block": "すべて", + "maqueen.Servos.S1|block": "S1", + "maqueen.Servos.S2|block": "S2", + "maqueen.Dir.CW|block": "前", + "maqueen.Dir.CCW|block": "後ろ", + "maqueen.Patrol.PatrolLeft|block": "左", + "maqueen.Patrol.PatrolRight|block": "右", + "maqueen.Patrol1.PatrolLeft|block": "左", + "maqueen.Patrol1.PatrolRight|block": "右", + "maqueen.Voltage.High|block": "白", + "maqueen.Voltage.Low|block": "黒", + "maqueen.LED.LEDLeft|block": "左", + "maqueen.LED.LEDRight|block": "右", + "maqueen.LEDswitch.turnOn|block": "つける", + "maqueen.LEDswitch.turnOff|block": "消す", + "maqueen.IR_callbackUser|block": "赤外線: IRコードを受信したとき", + "maqueen.IR_read|block": "赤外線リモコンのキー値", + "maqueen.IR_callbackUserV2|block": "赤外線(V2): IRコードを受信したとき", + "maqueen.IR_readV2|block": "赤外線リモコンのキー値(V2)", + "maqueen.IR_read_version|block": "製品情報を取得", + "maqueen.Ultrasonic|block": "超音波センサー|%unit|の値", + "maqueen.motorRun|block": "%index|のモーターを|%Dir|へ 速さ|%speed|で回す", + "maqueen.motorStop|block": "%motors|のモーターを止める", + "maqueen.readPatrol|block": "ラインセンサー|%patrol|の値", + "maqueen.writeLED|block": "|%ledswitch|のLEDを|%led", + "maqueen.servoRun|block": "サーボモーター|%index|の角度を|%angle|にする", + "maqueen.ltEvent|block": "ラインセンサーの|%value|が|%vi|のとき", + "maqueenIR.onPressEvent|block": "赤外線: |%btn|ボタンが押されたとき", + "maqueenIR.initIR|block": "赤外線: |%pin|に接続", + "maqueenIRV2.onPressEvent|block": "赤外線(V2): |%btn|ボタンが押されたとき", + "maqueenIRV2.initIR|block": "赤外線(V2): |%pin|に接続", + "maqueen|block": "Maqueen", + "maqueenIR|block": "Maqueen 赤外線", + "{id:category}Maqueen": "Maqueen", + "{id:category}MaqueenIR": "Maqueen 赤外線" +} diff --git a/_locales/nb/ir-strings.json b/_locales/nb/ir-strings.json new file mode 100644 index 0000000..6ef5ece --- /dev/null +++ b/_locales/nb/ir-strings.json @@ -0,0 +1,5 @@ +{ + "IR.IR_callbackUser|block": "Når Infrarød mottar ", + "IR.IR_init|block": "Initialiser infrarød sensor.", + "IR.IR_read|block": "Les Infrarød tast" +} \ No newline at end of file diff --git a/_locales/nb/maqueen-strings.json b/_locales/nb/maqueen-strings.json new file mode 100644 index 0000000..fd66413 --- /dev/null +++ b/_locales/nb/maqueen-strings.json @@ -0,0 +1,29 @@ +{ + "maqueen.Motors.M1|block": "venstre", + "maqueen.Motors.M2|block": "høyre", + "maqueen.Patrol.PatrolLeft|block": "venstre", + "maqueen.Patrol.PatrolRight|block": "høyre", + "maqueen.LEDswitch.turnOn|block": "på", + "maqueen.LEDswitch.turnOff|block": "av", + "maqueen.LED.LEDLeft|block": "venstre", + "maqueen.LED.LEDRight|block": "høyre", + "maqueen.Dir.CW|block": "fremover", + "maqueen.Dir.CCW|block": "bakover", + "maqueen.motorStop|block": "Stopp motor|%motors", + "maqueen.motorRun|block": "Kjør|%index|motor|%Dir| ved hastighet|%speed", + "maqueen.IR_callbackUser|block": "Når Infrarød mottar", + "maqueen.Ultrasonic|block": "Les avstand fra ultralyd i|%unit", + "maqueen.writeLED|block": "Slå LED lys|%led|%ledswitch", + "maqueen.IR_read|block": "Les Infrarød tast", + "maqueen.servoRun|block": "Sett servo|%index|vinkel til|%angle", + "maqueen.IR_read_version|block": "get product information", + "maqueen.Motors.All|block": "begge", + "maqueen.Patrol1.PatrolLeft|block":"venstre", + "maqueen.Patrol1.PatrolRight|block":"høyre", + "maqueen.Voltage.High|block":"høy", + "maqueen.Voltage.Low|block":"lav", + "maqueen.ltEvent|block":"Når|%value linjesensor er|%vi", + "maqueen.IR_callbackUserV2|block": "Når Infrarød mottar ", + "maqueen.IR_readV2|block": "Les Infrarød tast" + +} diff --git a/_locales/pl/maqueen-strings.json b/_locales/pl/maqueen-strings.json new file mode 100644 index 0000000..b50ae09 --- /dev/null +++ b/_locales/pl/maqueen-strings.json @@ -0,0 +1,27 @@ +{ + "maqueen.Dir.CCW|block": "do tyłu", + "maqueen.Dir.CW|block": "do przodu", + "maqueen.IR_callbackUser|block": "gdy odbierze IR", + "maqueen.IR_read_version|block": "odczytaj wersję IR", + "maqueen.IR_read|block": "odczytaj IR", + "maqueen.LED.LEDLeft|block": "lewa LED", + "maqueen.LED.LEDRight|block": "prawa LED", + "maqueen.LEDswitch.turnOff|block": "wyłącz", + "maqueen.LEDswitch.turnOn|block": "włącz", + "maqueen.motorRun|block": "Silnik|%index|kierunek|%Dir|prędkość|%speed", + "maqueen.Motors.All|block": "oba", + "maqueen.Motors.M1|block": "M1", + "maqueen.Motors.M2|block": "M2", + "maqueen.motorStopAll|block": "Zatrzymaj oba silniki", + "maqueen.motorStop|block": "Zatrzymaj silnik|%motors", + "maqueen.Patrol.PatrolLeft|block": "lewy detektor linii", + "maqueen.Patrol.PatrolRight|block": "prawy detektor linii", + "maqueen.readPatrol|block": "Odczytaj detektor linii|%patrol", + "maqueen.servoRun|block": "Serwonapęd|%index|kąt|%angle", + "maqueen.Servos.S1|block": "S1", + "maqueen.Servos.S2|block": "S2", + "maqueen.Ultrasonic|block": "Odczytaj ultradźwięki |%unit", + "maqueen.writeLED|block": "LED|%led|%ledswitch", + "PingUnit.Centimeters|block": "cm", + "PingUnit.MicroSeconds|block": "μs", +} diff --git a/_locales/pt/ir-strings.json b/_locales/pt/ir-strings.json new file mode 100644 index 0000000..1ddb765 --- /dev/null +++ b/_locales/pt/ir-strings.json @@ -0,0 +1,5 @@ +{ + "IR.IR_callbackUser|block": "em Infravermelhos recebido", + "IR.IR_init|block": "Inicializar o sensor infravermelho.", + "IR.IR_read|block": "ler infravermelhos" +} \ No newline at end of file diff --git a/_locales/pt/maqueen-strings.json b/_locales/pt/maqueen-strings.json new file mode 100644 index 0000000..775e9ae --- /dev/null +++ b/_locales/pt/maqueen-strings.json @@ -0,0 +1,25 @@ +{ + "maqueen.Dir.CCW|block": "Contra-relógio", + "maqueen.Dir.CW|block": "Relógio", + "maqueen.IR_callbackUser|block": "em Infravermelhos recebido", + "maqueen.IR_read_version|block": "obet informação do produto", + "maqueen.IR_read|block": "ler infravermelhos", + "maqueen.LED.LEDLeft|block": "esquerda", + "maqueen.LED.LEDRight|block": "direita", + "maqueen.LEDswitch.turnOff|block": "desligar", + "maqueen.LEDswitch.turnOn|block": "ligar", + "maqueen.Motors.All|block": "todos", + "maqueen.Motors.M1|block": "esquerda", + "maqueen.Motors.M2|block": "direita", + "maqueen.Patrol.PatrolLeft|block": "esquerda", + "maqueen.Patrol.PatrolRight|block": "direita", + "maqueen.Servos.S1|block": "S1", + "maqueen.Servos.S2|block": "S2", + "maqueen.Ultrasonic|block": "distância em unidades |%unit ", + "maqueen.motorRun|block": "motor|%index|direção|%Dir|velocidade|%speed", + "maqueen.motorStop|block": "parar motor|%motors", + "maqueen.readPatrol|block": "ler batedor|%patrol", + "maqueen.servoRun|block": "servo|%index|angulo|%angle", + "maqueen.writeLED|block": "leds|%led|estado:|%ledswitch" + +} \ No newline at end of file diff --git a/_locales/ru/ir-jsdoc-strings.json b/_locales/ru/ir-jsdoc-strings.json new file mode 100644 index 0000000..e69de29 diff --git a/_locales/ru/ir-strings.json b/_locales/ru/ir-strings.json new file mode 100644 index 0000000..1f84804 --- /dev/null +++ b/_locales/ru/ir-strings.json @@ -0,0 +1,5 @@ +{ + "IR.IR_callbackUser|block": "ИК: при получении кода", + "IR.IR_init|block": "Инициализация инфракрасного датчика.", + "IR.IR_read|block": "ИК: код с пульта" +} \ No newline at end of file diff --git a/_locales/ru/maqueen-jsdoc-strings.json b/_locales/ru/maqueen-jsdoc-strings.json new file mode 100644 index 0000000..3ef149c --- /dev/null +++ b/_locales/ru/maqueen-jsdoc-strings.json @@ -0,0 +1,15 @@ +{ + "maqueen.IR_read": "Код с инфрокрасного пульта.", + "maqueen.IR_read_version": "Номер версии робота.", + "maqueen.IR_callbackUser": "Выполняет действия при получении с пульта кода нажатой кнопки", + "maqueen.Ultrasonic": "Значение с ультразвукового датчика.", + "maqueen.ltEvent": "Выполняет действия при приходе определённого цвета с указанного датчика следования по линии.", + "maqueen.motorRun": "Устанавливает направление и скорость мотора.", + "maqueen.motorStop": "Останавливает мотор.", + "maqueen.readPatrol": "Значение с датчика следования по линии.", + "maqueen.servoRun": "Поворачивает сервопривод на определенный угол.", + "maqueen.writeLED": "Включает/выключает лампочки.", + "maqueenIR.initIR": "Подключает инфракрасный приёмник команд с пульта к выбранному порту", + "maqueenIR.onPressEvent": "Выполняет действия при нажатии указанной кнопки на пульте.", + "maqueencb": "@file pxt-maqueen/maqueen.ts\n@brief DFRobot's maqueen makecode library.\n@n [Get the module here](https://www.dfrobot.com.cn/goods-1802.html)\n@n This is a MakeCode graphical programming education robot.\n* @copyright [DFRobot](http://www.dfrobot.com), 2016\n@copyright MIT Lesser General Public License\n* @author [email](jie.tang@dfrobot.com)\n@date 2019-10-08" +} \ No newline at end of file diff --git a/_locales/ru/maqueen-strings.json b/_locales/ru/maqueen-strings.json new file mode 100644 index 0000000..9b8ab06 --- /dev/null +++ b/_locales/ru/maqueen-strings.json @@ -0,0 +1,36 @@ +{ + "PingUnit.Centimeters|block": "см", + "maqueen.Dir.CCW|block": "назад", + "maqueen.Dir.CW|block": "вперед", + "maqueen.IR_callbackUser|block": "ИК: при получении кода", + "maqueen.IR_read_version|block": "номер версии", + "maqueen.IR_read|block": "ИК: код с пульта", + "maqueen.LED.LEDLeft|block": "левая", + "maqueen.LED.LEDRight|block": "правая", + "maqueen.LEDswitch.turnOff|block": "выкл", + "maqueen.LEDswitch.turnOn|block": "вкл", + "maqueen.Motors.All|block": "все", + "maqueen.Motors.M1|block": "левый", + "maqueen.Motors.M2|block": "правый", + "maqueen.Patrol.PatrolLeft|block": "левый", + "maqueen.Patrol.PatrolRight|block": "правый", + "maqueen.Patrol1.PatrolLeft|block": "левый", + "maqueen.Patrol1.PatrolRight|block": "правый", + "maqueen.Servos.S1|block": "S1", + "maqueen.Servos.S2|block": "S2", + "maqueen.Ultrasonic|block": "ультразвуковой датчик|%unit ", + "maqueen.Voltage.High|block": "белый", + "maqueen.Voltage.Low|block": "чёрный", + "maqueen.ltEvent|block": "следование по линии|%value|%vi", + "maqueen.motorRun|block": "мотор|%index|двигаться|%Dir|со скоростью|%speed", + "maqueen.motorStop|block": "мотор|%motors|остановить", + "maqueen.readPatrol|block": "датчик следования по линии|%patrol", + "maqueen.servoRun|block": "сервопривод|%index|угол|%angle", + "maqueen.writeLED|block": "лампочка|%led|%ledswitch", + "maqueenIR.initIR|block": "ИК: подключить к|%pin", + "maqueenIR.onPressEvent|block": "ИК: кнопка|%btn|нажата", + "maqueenIR|block": "Maqueen ИК", + "maqueen|block": "Maqueen", + "{id:category}Maqueen": "Maqueen", + "{id:category}MaqueenIR": "Maqueen ИК" +} \ No newline at end of file diff --git a/_locales/zh-cn/ir-strings.json b/_locales/zh-cn/ir-strings.json new file mode 100644 index 0000000..6d4c01f --- /dev/null +++ b/_locales/zh-cn/ir-strings.json @@ -0,0 +1,5 @@ +{ + "IR.IR_callbackUser|block": "当接收到红外时运行", + "IR.IR_init|block":"初始化红外传感器", + "IR.IR_read|block": "红外的值" +} \ No newline at end of file diff --git a/_locales/zh-cn/maqueen-strings.json b/_locales/zh-cn/maqueen-strings.json new file mode 100644 index 0000000..f824789 --- /dev/null +++ b/_locales/zh-cn/maqueen-strings.json @@ -0,0 +1,31 @@ +{ + "maqueen.Motors.M1|block": "左侧", + "maqueen.Motors.M2|block": "右侧", + "maqueen.Patrol.PatrolLeft|block": "左侧", + "maqueen.Patrol.PatrolRight|block": "右侧", + "maqueen.LEDswitch.turnOn|block": "打开", + "maqueen.LEDswitch.turnOff|block": "关闭", + "maqueen.LED.LEDLeft|block": "左侧", + "maqueen.LED.LEDRight|block": "右侧", + "maqueen.Dir.CW|block": "正转", + "maqueen.Dir.CCW|block": "反转", + "maqueen.motorStop|block": "电机 停止|%motors", + "maqueen.motorStopAll|block": "停止所有电机", + "maqueen.motorRun|block": "电机|%index|方向|%Dir|速度|%speed", + "maqueen.IR_callbackUser|block": "当接收到红外时运行", + "maqueen.Ultrasonic|block": "超声波距离|%unit", + "maqueen.readPatrol|block": "巡线传感器|%patrol", + "maqueen.writeLED|block": "LED灯|%led|%ledswitch", + "maqueen.IR_read|block": "红外的值", + "maqueen.servoRun|block": "舵机|%index|角度|%angle", + "maqueen.IR_read_version|block": "获取产品信息", + "maqueen.Motors.All|block": "全部", + "maqueen.Patrol1.PatrolLeft|block":"左侧", + "maqueen.Patrol1.PatrolRight|block":"右侧", + "maqueen.Voltage.High|block":"高", + "maqueen.Voltage.Low|block":"低", + "maqueen.ltEvent|block":"当|%value巡线传感器|%vi", + "maqueen.IR_callbackUserV2|block": "当接收到红外时运行", + "maqueen.IR_readV2|block": "红外的值" + +} diff --git a/_locales/zh-tw/ir-strings.json b/_locales/zh-tw/ir-strings.json new file mode 100644 index 0000000..2937a22 --- /dev/null +++ b/_locales/zh-tw/ir-strings.json @@ -0,0 +1,5 @@ +{ + "IR.IR_read|block": "紅外線數值", + "IR.IR_init|block": "初始化紅外傳感器", + "IR.IR_callbackUser|block": "當接收到紅外線時運行" +} \ No newline at end of file diff --git a/_locales/zh-tw/maqueen-strings.json b/_locales/zh-tw/maqueen-strings.json new file mode 100644 index 0000000..cc959bf --- /dev/null +++ b/_locales/zh-tw/maqueen-strings.json @@ -0,0 +1,30 @@ +{ + "maqueen.Motors.M1|block": "左側", + "maqueen.Motors.M2|block": "右側", + "maqueen.Patrol.PatrolLeft|block": "左側", + "maqueen.Patrol.PatrolRight|block": "右側", + "maqueen.LEDswitch.turnOn|block": "開", + "maqueen.LEDswitch.turnOff|block": "關", + "maqueen.LED.LEDLeft|block": "左側", + "maqueen.LED.LEDRight|block": "右側", + "maqueen.Dir.CW|block": "正轉", + "maqueen.Dir.CCW|block": "反轉", + "maqueen.motorStop|block": "馬達停止|%motors", + "maqueen.motorStopAll|block": "停止所有电机", + "maqueen.motorRun|block": "馬達|%index|方向|%Dir|速度|%speed", + "maqueen.IR_callbackUser|block": "當接收到紅外線時運行", + "maqueen.Ultrasonic|block": "超音波距離|%unit", + "maqueen.readPatrol|block": "循跡感測器|%patrol", + "maqueen.writeLED|block": "LED燈|%led|%ledswitch ", + "maqueen.IR_read|block": "紅外線數值", + "maqueen.servoRun|block": "舵機|%index|角度|%angle", + "maqueen.IR_read_version|block": "獲取產品訊息", + "maqueen.Motors.All|block": "全部", + "maqueen.Patrol1.PatrolLeft|block": "左側", + "maqueen.Patrol1.PatrolRight|block": "右側", + "maqueen.Voltage.High|block": "高", + "maqueen.Voltage.Low|block": "低", + "maqueen.ltEvent|block": "當|%value巡線傳感器|%vi", + "maqueen.IR_readV2|block": "紅外線數值", + "maqueen.IR_callbackUserV2|block": "當接收到紅外線時運行" +} diff --git a/ir.ts b/ir.ts new file mode 100644 index 0000000..35a6724 --- /dev/null +++ b/ir.ts @@ -0,0 +1,388 @@ +//Library based on :https://github.com/1010Technologies/pxt-makerbit-background +//Library based on :https://github.com/1010Technologies/pxt-makerbit-ir-receiver + + +/** + * Custom blocks + */ +//% weight=100 color=#0fbc11 icon="\uf1eb" block="IR" +namespace IR { + let irState: IrState; + const IR_REPEAT = 256; + const IR_INCOMPLETE = 257; + const IR_DATAGRAM = 258; + const REPEAT_TIMEOUT_MS = 120; + interface IrState { + hasNewDatagram: boolean; + bitsReceived: uint8; + addressSectionBits: uint16; + commandSectionBits: uint16; + hiword: uint16; + loword: uint16; + activeCommand: number; + repeatTimeout: number; + IR_callbackUser: () => void; + } + + + function appendBitToDatagram(bit: number): number { + irState.bitsReceived += 1; + + if (irState.bitsReceived <= 8) { + irState.hiword = (irState.hiword << 1) + bit; + } else if (irState.bitsReceived <= 16) { + irState.hiword = (irState.hiword << 1) + bit; + } else if (irState.bitsReceived <= 32) { + irState.loword = (irState.loword << 1) + bit; + } + + if (irState.bitsReceived === 32) { + irState.addressSectionBits = irState.hiword & 0xffff; + irState.commandSectionBits = irState.loword & 0xffff; + return IR_DATAGRAM; + } else { + return IR_INCOMPLETE; + } + } + + function decode(markAndSpace: number): number { + if (markAndSpace < 1600) { + // low bit + return appendBitToDatagram(0); + } else if (markAndSpace < 2700) { + // high bit + return appendBitToDatagram(1); + } + + irState.bitsReceived = 0; + + if (markAndSpace < 12500) { + // Repeat detected + return IR_REPEAT; + } else if (markAndSpace < 14500) { + // Start detected + return IR_INCOMPLETE; + } else { + return IR_INCOMPLETE; + } + } + + function enableIrMarkSpaceDetection(pin: DigitalPin) { + pins.setPull(pin, PinPullMode.PullNone); + + let mark = 0; + let space = 0; + + pins.onPulsed(pin, PulseValue.Low, () => { + // HIGH, see https://github.com/microsoft/pxt-microbit/issues/1416 + mark = pins.pulseDuration(); + }); + + pins.onPulsed(pin, PulseValue.High, () => { + // LOW + space = pins.pulseDuration(); + const status = decode(mark + space); + + if (status !== IR_INCOMPLETE) { + handleIrEvent(status); + } + }); + } + + + function handleIrEvent(irEvent: number) { + + // Refresh repeat timer + if (irEvent === IR_DATAGRAM || irEvent === IR_REPEAT) { + irState.repeatTimeout = input.runningTime() + REPEAT_TIMEOUT_MS; + } + + if (irEvent === IR_DATAGRAM) { + irState.hasNewDatagram = true; + + if (irState.IR_callbackUser) { + background.schedule(irState.IR_callbackUser, background.Thread.UserCallback, background.Mode.Once, 0); + } + + const newCommand = irState.commandSectionBits >> 8; + + } + } + + function initIrState() { + if (irState) { + return; + } + + irState = { + bitsReceived: 0, + hasNewDatagram: false, + addressSectionBits: 0, + commandSectionBits: 0, + hiword: 0, // TODO replace with uint32 + loword: 0, + activeCommand: -1, + repeatTimeout: 0, + IR_callbackUser: undefined, + }; + } + + /** + * Init IR . + */ + //% blockId="IR_init" + //% block="Init IR" + //% pin.fieldEditor="gridpicker" + //% pin.fieldOptions.columns=4 + //% pin.fieldOptions.tooltips="false" + //% weight=90 + export function IR_init(): void { + initIrState(); + enableIrMarkSpaceDetection(DigitalPin.P16) + background.schedule(notifyIrEvents, background.Thread.Priority, background.Mode.Repeat, REPEAT_TIMEOUT_MS); + } + + function notifyIrEvents() { + if (irState.activeCommand === -1) { + // skip to save CPU cylces + } else { + const now = input.runningTime(); + if (now > irState.repeatTimeout) { + // repeat timed out + + // const handler = irState.onIrButtonReleased.find(h => h.irButton === irState.activeCommand || IrButton.Any === h.irButton); + // if (handler) { + // background.schedule(handler.onEvent, background.Thread.UserCallback, background.Mode.Once, 0); + // } + + irState.bitsReceived = 0; + irState.activeCommand = -1; + } + } + } + + /** + * Do something when an IR datagram is received. + * @param handler body code to run when the event is raised + */ + //% blockId= IR_callbackUser + //% block="on IR datagram received" + //% weight=40 + export function IR_callbackUser(handler: () => void) { + initIrState(); + irState.IR_callbackUser = handler; + } + + /** + * Returns the IR datagram as 32-bit hexadecimal string. + * The last received datagram is returned or "0x00000000" if no data has been received yet. + */ + //% blockId=IR_read + //% block="IR datagram" + //% weight=30 + export function IR_read(): number { + basic.pause(0); // Yield to support background processing when called in tight loops + initIrState(); + return transMind(irState.commandSectionBits & 0x00ff) + } + function ir_rec_to16BitHex(value: number): string { + let hex = ""; + for (let pos = 0; pos < 4; pos++) { + let remainder = value % 16; + if (remainder < 10) { + hex = remainder.toString() + hex; + } else { + hex = String.fromCharCode(55 + remainder) + hex; + } + value = Math.idiv(value, 16); + } + return hex; + } + function transMind(data :number):number{ + switch (data) { + case 255 : data = 0; break; + case 127 : data = 1; break; + case 191 : data = 2; break; + case 223 : data = 4; break; + case 95 : data = 5; break; + case 159 : data = 6; break; + case 239 : data = 8; break; + case 111 : data = 9; break; + case 175 : data = 10; break; + case 207 : data = 12; break; + case 79 : data = 13; break; + case 143 : data = 14; break; + case 247 : data = 16; break; + case 119 : data = 17; break; + case 183 : data = 18; break; + case 215 : data = 20; break; + case 87 : data = 21; break; + case 151 : data = 22; break; + case 231 : data = 24; break; + case 103 : data = 25; break; + case 167 : data = 26; break; + default: break; + } + return data; + } + + +} + + + + +//% deprecated=true +namespace background { + + export enum Thread { + Priority = 0, + UserCallback = 1, + } + + export enum Mode { + Repeat, + Once, + } + + class Executor { + _newJobs: Job[] = undefined; + _jobsToRemove: number[] = undefined; + _pause: number = 100; + _type: Thread; + + constructor(type: Thread) { + this._type = type; + this._newJobs = []; + this._jobsToRemove = []; + control.runInParallel(() => this.loop()); + } + + push(task: () => void, delay: number, mode: Mode): number { + if (delay > 0 && delay < this._pause && mode === Mode.Repeat) { + this._pause = Math.floor(delay); + } + const job = new Job(task, delay, mode); + this._newJobs.push(job); + return job.id; + } + + cancel(jobId: number) { + this._jobsToRemove.push(jobId); + } + + loop(): void { + const _jobs: Job[] = []; + + let previous = control.millis(); + + while (true) { + const now = control.millis(); + const delta = now - previous; + previous = now; + + // Add new jobs + this._newJobs.forEach(function (job: Job, index: number) { + _jobs.push(job); + }); + this._newJobs = []; + + // Cancel jobs + this._jobsToRemove.forEach(function (jobId: number, index: number) { + for (let i = _jobs.length - 1; i >= 0; i--) { + const job = _jobs[i]; + if (job.id == jobId) { + _jobs.removeAt(i); + break; + } + } + }); + this._jobsToRemove = [] + + + // Execute all jobs + if (this._type === Thread.Priority) { + // newest first + for (let i = _jobs.length - 1; i >= 0; i--) { + if (_jobs[i].run(delta)) { + this._jobsToRemove.push(_jobs[i].id) + } + } + } else { + // Execute in order of schedule + for (let i = 0; i < _jobs.length; i++) { + if (_jobs[i].run(delta)) { + this._jobsToRemove.push(_jobs[i].id) + } + } + } + + basic.pause(this._pause); + } + } + } + + class Job { + id: number; + func: () => void; + delay: number; + remaining: number; + mode: Mode; + + constructor(func: () => void, delay: number, mode: Mode) { + this.id = randint(0, 2147483647) + this.func = func; + this.delay = delay; + this.remaining = delay; + this.mode = mode; + } + + run(delta: number): boolean { + if (delta <= 0) { + return false; + } + + this.remaining -= delta; + if (this.remaining > 0) { + return false; + } + + switch (this.mode) { + case Mode.Once: + this.func(); + basic.pause(0); + return true; + case Mode.Repeat: + this.func(); + this.remaining = this.delay; + basic.pause(0); + return false; + } + } + } + + const queues: Executor[] = []; + + export function schedule( + func: () => void, + type: Thread, + mode: Mode, + delay: number, + ): number { + if (!func || delay < 0) return 0; + + if (!queues[type]) { + queues[type] = new Executor(type); + } + + return queues[type].push(func, delay, mode); + } + + export function remove(type: Thread, jobId: number): void { + if (queues[type]) { + queues[type].cancel(jobId); + } + } +} + + diff --git a/main.blocks b/main.blocks new file mode 100644 index 0000000..802ac8d --- /dev/null +++ b/main.blocks @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/main.ts b/main.ts new file mode 100644 index 0000000..49ef24f --- /dev/null +++ b/main.ts @@ -0,0 +1,4 @@ +IR.IR_callbackUser(function () { + serial.writeLine("" + (IR.IR_read())) +}) +IR.IR_init() diff --git a/pxt.json b/pxt.json new file mode 100644 index 0000000..64a4650 --- /dev/null +++ b/pxt.json @@ -0,0 +1,34 @@ +{ + "name": "ir", + "version": "1.0.3", + "description": "", + "dependencies": { + "core": "*", + "microphone": "*" + }, + "files": [ + "main.blocks", + "main.ts", + "README.md", + "_locales/zh-cn/ir-strings.json", + "_locales/zh-tw/ir-strings.json", + "_locales/pt/ir-strings.json", + "_locales/fr/ir-strings.json", + "_locales/es/ir-strings.json", + "_locales/nb/ir-strings.json", + "_locales/ru/ir-strings.json", + "_locales/ja/ir-strings.json", + "ir.ts" + ], + "testFiles": [ + "test.ts" + ], + "targetVersions": { + "target": "7.0.51", + "targetId": "microbit" + }, + "supportedTargets": [ + "microbit" + ], + "preferredEditor": "tsprj" +} diff --git a/test.ts b/test.ts new file mode 100644 index 0000000..4beac41 --- /dev/null +++ b/test.ts @@ -0,0 +1,2 @@ + +// \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..46f831b --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,9 @@ +{ + "compilerOptions": { + "target": "ES5", + "noImplicitAny": true, + "outDir": "built", + "rootDir": "." + }, + "exclude": ["pxt_modules/**/*test.ts"] +}