From 9384d8cd966f77eb4c058adcd9b41dbcc67b8e9e Mon Sep 17 00:00:00 2001 From: ocogeclub Date: Thu, 3 Mar 2022 21:32:00 +0900 Subject: [PATCH] =?UTF-8?q?[update]=20=E8=BB=BD=E5=BE=AE=E3=81=AA=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- blocks/sensors/amg8833/AMG8833x.js | 6 +++--- blocks/sensors/amg8833/index.js | 2 +- blocks/sensors/dht11/index.js | 2 +- blocks/sensors/paj7620/PAJ7620x.js | 6 +++--- blocks/sensors/paj7620/index.js | 2 +- ugj_blocks.js | 8 +++----- 6 files changed, 12 insertions(+), 14 deletions(-) diff --git a/blocks/sensors/amg8833/AMG8833x.js b/blocks/sensors/amg8833/AMG8833x.js index 32cc5bc..d6d6dfd 100644 --- a/blocks/sensors/amg8833/AMG8833x.js +++ b/blocks/sensors/amg8833/AMG8833x.js @@ -5,9 +5,9 @@ const pig = require('@ocogeclub/pigpio'); let pi = -1; let i2c_hand = -1; -exports.init = async (i2c_bus, i2c_addr, win = null) => { - if (win !== null) { - win.addEventListener('beforeunload', async () => { +exports.init = async (i2c_bus, i2c_addr, wael = null) => { + if (wael !== null) { + wael('beforeunload', async () => { await exports.stop(); }); } diff --git a/blocks/sensors/amg8833/index.js b/blocks/sensors/amg8833/index.js index 465e75e..4f81afa 100644 --- a/blocks/sensors/amg8833/index.js +++ b/blocks/sensors/amg8833/index.js @@ -65,7 +65,7 @@ Blockly.JavaScript['ugj_grideye_init'] = function (block) { Blockly.JavaScript.provideFunction_( 'require_amg8833', [`const _amg8833 = require('${modpath}');`] ); - var code = `await _amg8833.init(${elutil.i2c_bus}, ${dropdown_addr}, window);\n`; + var code = `await _amg8833.init(${elutil.i2c_bus}, ${dropdown_addr}, window.addEventListener);\n`; return code;// }; /********************** */ diff --git a/blocks/sensors/dht11/index.js b/blocks/sensors/dht11/index.js index 112cf23..b54a03b 100644 --- a/blocks/sensors/dht11/index.js +++ b/blocks/sensors/dht11/index.js @@ -16,7 +16,7 @@ Blockly.Blocks['ugj_dht11'] = { Blockly.JavaScript['ugj_dht11'] = function (block) { var value_pin = Blockly.JavaScript.valueToCode(block, 'pin', Blockly.JavaScript.ORDER_ATOMIC); let pypath = elutil.path.join(elutil.blocks_sensors_dir, 'dht11', 'dht11.py'); - var code = `let _th = require('child_process').spawnSync('python3', ['${pypath}', '${value_pin}']).stdout.toString(); + var code = `let _th = require('child_process').spawnSync('python3', ['${pypath}', '${value_pin}'], {timeout: 5000}).stdout.toString(); let _dhtdata = JSON.parse(_th);`; // let _dht11data[0] = // console.log('t=' + obj.temperature); diff --git a/blocks/sensors/paj7620/PAJ7620x.js b/blocks/sensors/paj7620/PAJ7620x.js index 78c4cdb..c4ae933 100644 --- a/blocks/sensors/paj7620/PAJ7620x.js +++ b/blocks/sensors/paj7620/PAJ7620x.js @@ -316,9 +316,9 @@ let pig = -1; let pi = -1; let i2c_hand = -1; //Initialize the sensors -exports.init = async (i2c_bus, i2c_addr, win = null) => { - if (win !== null) { - win.addEventListener('beforeunload', async () => { +exports.init = async (i2c_bus, i2c_addr, wael = null) => { + if (wael !== null) { + wael('beforeunload', async () => { await exports.stop(); }); } diff --git a/blocks/sensors/paj7620/index.js b/blocks/sensors/paj7620/index.js index fc42956..1198be8 100644 --- a/blocks/sensors/paj7620/index.js +++ b/blocks/sensors/paj7620/index.js @@ -39,7 +39,7 @@ Blockly.JavaScript['ugj_gesture_init'] = function (block) { Blockly.JavaScript.provideFunction_( 'require_paj7620', [`const _paj7620 = require('${modpath}');`] ); - var code = `await _paj7620.init(${elutil.i2c_bus}, ${value_i2c_addr}, window); + var code = `await _paj7620.init(${elutil.i2c_bus}, ${value_i2c_addr}, window.addEventListener); `; return code; }; diff --git a/ugj_blocks.js b/ugj_blocks.js index 166cbf6..71a0a27 100644 --- a/ugj_blocks.js +++ b/ugj_blocks.js @@ -2165,7 +2165,7 @@ Blockly.Blocks['ugj_spawnsync'] = { this.setInputsInline(true); this.setPreviousStatement(true, null); this.setNextStatement(true, null); - this.setTooltip("外部プログラムを実行して子プロセスを生成し、子プロセスが終了するまで待ちます。"); + this.setTooltip("外部プログラムを実行して子プロセスを生成し、子プロセスが終了するまで待ちます。タイムアウトは10秒です。"); this.setHelpUrl(""); this.setStyle('special_blocks') } @@ -2173,9 +2173,7 @@ Blockly.Blocks['ugj_spawnsync'] = { Blockly.JavaScript['ugj_spawnsync'] = function (block) { var value_childprocess = Blockly.JavaScript.valueToCode(block, 'childprocess', Blockly.JavaScript.ORDER_NONE); var value_data = Blockly.JavaScript.valueToCode(block, 'data', Blockly.JavaScript.ORDER_ATOMIC); - // var variable_data = Blockly.JavaScript.nameDB_.getName(block.getFieldValue('data'), Blockly.Variables.NAME_TYPE); - var code = `${value_data} = require('child_process').spawnSync(${value_childprocess}).stdout.toString();\n`; - // var code = `${variable_data} = require('child_process').execFileSync(${value_childprocess});\n`; + var code = `${value_data} = require('child_process').spawnSync(${value_childprocess}, {timeout: 10000}).stdout.toString();\n`; return code; }; @@ -2214,7 +2212,7 @@ Blockly.JavaScript['ugj_spawn'] = function (block) { `${value_data} = _data.toString();`, statements_do, "})", - `window.addEventListener( 'beforeunload', function() { _child.kill() }, false );`, + `window.addEventListener( 'beforeunload', () => _child.kill(), false );`, '' ].join("\n"); return code;