From f768a4024efe26092434a55b9d5f5ef24522a824 Mon Sep 17 00:00:00 2001 From: ocogeclub Date: Thu, 9 Sep 2021 17:41:39 +0900 Subject: [PATCH] =?UTF-8?q?[update]=20=E3=82=A4=E3=83=B3=E3=82=B9=E3=83=88?= =?UTF-8?q?=E3=83=BC=E3=83=A9=E3=81=AB=20lgpio=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- installer/install.sh | 14 +++++++++++++- ugj_blocks.js | 39 +++++++++++++++++++++++++++------------ ugj_script.js | 2 ++ 3 files changed, 42 insertions(+), 13 deletions(-) diff --git a/installer/install.sh b/installer/install.sh index 9a60f9a..9213c8b 100644 --- a/installer/install.sh +++ b/installer/install.sh @@ -1,9 +1,21 @@ #!/bin/bash -x # Usage: bash install.sh +NODEJS=14.17.0 + +# install lgpio (and python3) +sudo apt update +sudo apt install python3 swig python3-dev python3-setuptools -y +wget http://abyz.me.uk/lg/lg.zip +unzip lg.zip +rm lg.zip +cd lg +make +sudo make install + # install node.js (=electron node version) via n (https://github.com/tj/n) curl -L https://raw.githubusercontent.com/tj/n/master/bin/n -o n -sudo bash n 14.17.0 +sudo bash n $NODEJS # install python code formatter python3 -m pip install black # install desktop entry diff --git a/ugj_blocks.js b/ugj_blocks.js index ef66b17..4bf0879 100644 --- a/ugj_blocks.js +++ b/ugj_blocks.js @@ -2677,18 +2677,26 @@ Blockly.JavaScript['ugj_blackboard_content'] = function (block) { /************* */ /** Soft Sleep */ /************* */ +var ugjSleepDefinition = { + "type": "ugj_sleep", + "message0": "%{BKY_UGJ_SLEEP_TITLE}", + "args0": [ + { + "type": "input_value", + "name": "sec", + "check": "Number" + } + ], + "inputsInline": true, + "previousStatement": null, + "nextStatement": null, + "tooltip": "%{BKY_UGJ_SLEEP_TOOLTIP}", + "helpUrl": "", + "style": "special_blocks" +}; Blockly.Blocks['ugj_sleep'] = { init: function () { - this.appendValueInput("sec") - .setCheck("Number"); - this.appendDummyInput() - .appendField("秒待つ"); - this.setInputsInline(true); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setStyle('special_blocks') - this.setTooltip("指定した秒数だけ処理を中断します。"); - this.setHelpUrl(""); + this.jsonInit(ugjSleepDefinition); } }; Blockly.JavaScript['ugj_sleep'] = function (block) { @@ -2698,10 +2706,17 @@ Blockly.JavaScript['ugj_sleep'] = function (block) { ['const ' + Blockly.JavaScript.FUNCTION_NAME_PLACEHOLDER_ + ' = milisec =>', 'new Promise(r => setTimeout(r, milisec));'] ); - var code = `await ${functionName}(${value_sec}*1000);`; + var code = `await ${functionName}(${value_sec}*1000);\n`; + return code; +}; +Blockly.Python['ugj_sleep'] = function(block) { + var value_sec = Blockly.Python.valueToCode(block, 'sec', Blockly.Python.ORDER_ATOMIC); + Blockly.Python.provideFunction_( + 'import_sleep', ['from time import sleep'] + ) + var code = `sleep(${value_sec})\n`; return code; }; - /********************* */ /** Carriage Return ** */ /********************* */ diff --git a/ugj_script.js b/ugj_script.js index 1610230..25c7565 100644 --- a/ugj_script.js +++ b/ugj_script.js @@ -123,6 +123,8 @@ Blockly.Msg["UGJ_DECTOHEX_TOOLTIP"] = "10進数を16進数に変換します。" Blockly.Msg["UGJ_CANVAS_INIT_TITLE"] = "キャンバスを表示"; Blockly.Msg["UGJ_CANVAS_INIT_TOOLTIP"] = "キャンバスを表示し、使用できるようにします。"; +Blockly.Msg["UGJ_SLEEP_TITLE"] = "%1 秒待つ"; +Blockly.Msg["UGJ_SLEEP_TOOLTIP"] = "指定した秒数だけ処理を中断します。"; // Customize Toolbox class CustomCategory extends Blockly.ToolboxCategory {