mirror of
https://github.com/ocogeclub/ocoge.git
synced 2024-11-21 23:29:48 +00:00
20211127
This commit is contained in:
parent
4680afcd95
commit
1255e84661
4
index.js
4
index.js
@ -184,8 +184,8 @@ Blockly.Msg["UGJ_DECTOHEX_TOOLTIP"] = "10進数を16進数に変換します。"
|
|||||||
|
|
||||||
Blockly.Msg["UGJ_CANVAS_INIT_TITLE"] = "キャンバスを表示";
|
Blockly.Msg["UGJ_CANVAS_INIT_TITLE"] = "キャンバスを表示";
|
||||||
Blockly.Msg["UGJ_CANVAS_INIT_TOOLTIP"] = "キャンバスを表示し、使用できるようにします。";
|
Blockly.Msg["UGJ_CANVAS_INIT_TOOLTIP"] = "キャンバスを表示し、使用できるようにします。";
|
||||||
Blockly.Msg["UGJ_FACEAPI_TITLE"] = "TensorFlowによる顔検出: %1 ランドマークを検出 %2 %3";
|
// Blockly.Msg["UGJ_FACEAPI_TITLE"] = "TensorFlowによる顔検出: %1 ランドマークを検出 %2 %3";
|
||||||
Blockly.Msg["UGJ_FACEAPI_TOOLTIP"] = "TensorFlow とFaceAPI をロードし、顔検出をできるようにします。";
|
// Blockly.Msg["UGJ_FACEAPI_TOOLTIP"] = "TensorFlow とFaceAPI をロードし、顔検出をできるようにします。";
|
||||||
Blockly.Msg["UGJ_SLEEP_TITLE"] = "%1 秒待つ";
|
Blockly.Msg["UGJ_SLEEP_TITLE"] = "%1 秒待つ";
|
||||||
Blockly.Msg["UGJ_SLEEP_TOOLTIP"] = "指定した秒数だけ処理を中断します。";
|
Blockly.Msg["UGJ_SLEEP_TOOLTIP"] = "指定した秒数だけ処理を中断します。";
|
||||||
|
|
||||||
|
399
ugj_blocks.js
399
ugj_blocks.js
@ -135,8 +135,8 @@ Blockly.JavaScript['ugj_controls_forEach'] = function (block) {
|
|||||||
var variable_item = Blockly.JavaScript.nameDB_.getName(block.getFieldValue('item'), Blockly.Variables.NAME_TYPE);
|
var variable_item = Blockly.JavaScript.nameDB_.getName(block.getFieldValue('item'), Blockly.Variables.NAME_TYPE);
|
||||||
var statements_do = Blockly.JavaScript.statementToCode(block, 'do');
|
var statements_do = Blockly.JavaScript.statementToCode(block, 'do');
|
||||||
var code = [
|
var code = [
|
||||||
`for (let i_index in ${value_list}) {`,
|
`for (let _index in ${value_list}) {`,
|
||||||
`${variable_item} = ${value_list}[i_index];`,
|
`${variable_item} = ${value_list}[_index];`,
|
||||||
statements_do,
|
statements_do,
|
||||||
`}`,
|
`}`,
|
||||||
''
|
''
|
||||||
@ -321,9 +321,9 @@ Blockly.Blocks['ugj_gpio_open'] = {
|
|||||||
};
|
};
|
||||||
Blockly.JavaScript['ugj_gpio_open'] = function (block) {
|
Blockly.JavaScript['ugj_gpio_open'] = function (block) {
|
||||||
Blockly.JavaScript.provideFunction_(
|
Blockly.JavaScript.provideFunction_(
|
||||||
'require_gpio', [`const pi = require('@ocogeclub/` + elutil.gpio_backend + `');`]
|
'require_gpio', [`const _pi = require('@ocogeclub/` + elutil.gpio_backend + `');`]
|
||||||
);
|
);
|
||||||
var code = `await pi.gpio_open();\n`; //
|
var code = `await _pi.gpio_open();\n`; //
|
||||||
return code;
|
return code;
|
||||||
};
|
};
|
||||||
Blockly.Python['ugj_gpio_open'] = function (block) {
|
Blockly.Python['ugj_gpio_open'] = function (block) {
|
||||||
@ -352,7 +352,7 @@ Blockly.Blocks['ugj_gpio_close'] = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
Blockly.JavaScript['ugj_gpio_close'] = function (block) {
|
Blockly.JavaScript['ugj_gpio_close'] = function (block) {
|
||||||
var code = 'await pi.gpio_close();\n';
|
var code = 'await _pi.gpio_close();\n';
|
||||||
return code;
|
return code;
|
||||||
};
|
};
|
||||||
Blockly.Python['ugj_gpio_close'] = function (block) {
|
Blockly.Python['ugj_gpio_close'] = function (block) {
|
||||||
@ -387,7 +387,7 @@ Blockly.Blocks['ugj_gpio_set_output'] = {
|
|||||||
};
|
};
|
||||||
Blockly.JavaScript['ugj_gpio_set_output'] = function (block) {
|
Blockly.JavaScript['ugj_gpio_set_output'] = function (block) {
|
||||||
var value_gpio = Blockly.JavaScript.valueToCode(block, 'gpio', Blockly.JavaScript.ORDER_ATOMIC);
|
var value_gpio = Blockly.JavaScript.valueToCode(block, 'gpio', Blockly.JavaScript.ORDER_ATOMIC);
|
||||||
var code = `await pi.gpio_set_output(${value_gpio});\n`;
|
var code = `await _pi.gpio_set_output(${value_gpio});\n`;
|
||||||
return code;
|
return code;
|
||||||
};
|
};
|
||||||
Blockly.Python['ugj_gpio_set_output'] = function (block) {
|
Blockly.Python['ugj_gpio_set_output'] = function (block) {
|
||||||
@ -442,7 +442,7 @@ Blockly.Blocks['ugj_gpio_set_input'] = {
|
|||||||
Blockly.JavaScript['ugj_gpio_set_input'] = function (block) {
|
Blockly.JavaScript['ugj_gpio_set_input'] = function (block) {
|
||||||
var value_gpio = Blockly.JavaScript.valueToCode(block, 'gpio', Blockly.JavaScript.ORDER_ATOMIC);
|
var value_gpio = Blockly.JavaScript.valueToCode(block, 'gpio', Blockly.JavaScript.ORDER_ATOMIC);
|
||||||
var dropdown_lflag = block.getFieldValue('lflag');
|
var dropdown_lflag = block.getFieldValue('lflag');
|
||||||
var code = `await pi.gpio_set_input(${value_gpio}, ${dropdown_lflag});\n`;
|
var code = `await _pi.gpio_set_input(${value_gpio}, ${dropdown_lflag});\n`;
|
||||||
return code;
|
return code;
|
||||||
};
|
};
|
||||||
Blockly.Python['ugj_gpio_set_input'] = function (block) {
|
Blockly.Python['ugj_gpio_set_input'] = function (block) {
|
||||||
@ -478,7 +478,7 @@ Blockly.Blocks['ugj_gpio_read'] = {
|
|||||||
};
|
};
|
||||||
Blockly.JavaScript['ugj_gpio_read'] = function (block) {
|
Blockly.JavaScript['ugj_gpio_read'] = function (block) {
|
||||||
var value_gpio = Blockly.JavaScript.valueToCode(block, 'gpio', Blockly.JavaScript.ORDER_ATOMIC);
|
var value_gpio = Blockly.JavaScript.valueToCode(block, 'gpio', Blockly.JavaScript.ORDER_ATOMIC);
|
||||||
var code = `await pi.gpio_read(${value_gpio})`;
|
var code = `await _pi.gpio_read(${value_gpio})`;
|
||||||
return [code, Blockly.JavaScript.ORDER_NONE];
|
return [code, Blockly.JavaScript.ORDER_NONE];
|
||||||
};
|
};
|
||||||
Blockly.Python['ugj_gpio_read'] = function (block) {
|
Blockly.Python['ugj_gpio_read'] = function (block) {
|
||||||
@ -529,7 +529,7 @@ Blockly.Blocks['ugj_gpio_write'] = {
|
|||||||
Blockly.JavaScript['ugj_gpio_write'] = function (block) {
|
Blockly.JavaScript['ugj_gpio_write'] = function (block) {
|
||||||
var value_gpio = Blockly.JavaScript.valueToCode(block, 'gpio', Blockly.JavaScript.ORDER_ATOMIC);
|
var value_gpio = Blockly.JavaScript.valueToCode(block, 'gpio', Blockly.JavaScript.ORDER_ATOMIC);
|
||||||
var dropdown_level = block.getFieldValue('level');
|
var dropdown_level = block.getFieldValue('level');
|
||||||
var code = `await pi.gpio_write(${value_gpio}, ${dropdown_level});\n`;
|
var code = `await _pi.gpio_write(${value_gpio}, ${dropdown_level});\n`;
|
||||||
return code;
|
return code;
|
||||||
};
|
};
|
||||||
Blockly.Python['ugj_gpio_write'] = function (block) {
|
Blockly.Python['ugj_gpio_write'] = function (block) {
|
||||||
@ -572,7 +572,7 @@ Blockly.Blocks['ugj_servo'] = {
|
|||||||
Blockly.JavaScript['ugj_servo'] = function (block) {
|
Blockly.JavaScript['ugj_servo'] = function (block) {
|
||||||
var value_gpio = Blockly.JavaScript.valueToCode(block, 'gpio', Blockly.JavaScript.ORDER_ATOMIC);
|
var value_gpio = Blockly.JavaScript.valueToCode(block, 'gpio', Blockly.JavaScript.ORDER_ATOMIC);
|
||||||
var value_pulsewidth = Blockly.JavaScript.valueToCode(block, 'pulsewidth', Blockly.JavaScript.ORDER_ATOMIC);
|
var value_pulsewidth = Blockly.JavaScript.valueToCode(block, 'pulsewidth', Blockly.JavaScript.ORDER_ATOMIC);
|
||||||
var code = `await pi.servo(${value_gpio}, ${value_pulsewidth});\n`;
|
var code = `await _pi.servo(${value_gpio}, ${value_pulsewidth});\n`;
|
||||||
return code;
|
return code;
|
||||||
};
|
};
|
||||||
Blockly.Python['ugj_servo'] = function (block) {
|
Blockly.Python['ugj_servo'] = function (block) {
|
||||||
@ -621,7 +621,7 @@ Blockly.JavaScript['ugj_pwm'] = function (block) {
|
|||||||
var value_gpio = Blockly.JavaScript.valueToCode(block, 'gpio', Blockly.JavaScript.ORDER_ATOMIC);
|
var value_gpio = Blockly.JavaScript.valueToCode(block, 'gpio', Blockly.JavaScript.ORDER_ATOMIC);
|
||||||
var value_pwm_frequency = Blockly.JavaScript.valueToCode(block, 'pwm_frequency', Blockly.JavaScript.ORDER_ATOMIC);
|
var value_pwm_frequency = Blockly.JavaScript.valueToCode(block, 'pwm_frequency', Blockly.JavaScript.ORDER_ATOMIC);
|
||||||
var value_pwm_duty_cycle = Blockly.JavaScript.valueToCode(block, 'pwm_duty_cycle', Blockly.JavaScript.ORDER_ATOMIC);
|
var value_pwm_duty_cycle = Blockly.JavaScript.valueToCode(block, 'pwm_duty_cycle', Blockly.JavaScript.ORDER_ATOMIC);
|
||||||
var code = `await pi.pwm(${value_gpio}, ${value_pwm_frequency}, ${value_pwm_duty_cycle});\n`;
|
var code = `await _pi.pwm(${value_gpio}, ${value_pwm_frequency}, ${value_pwm_duty_cycle});\n`;
|
||||||
return code;
|
return code;
|
||||||
};
|
};
|
||||||
Blockly.Python['ugj_pwm'] = function (block) {
|
Blockly.Python['ugj_pwm'] = function (block) {
|
||||||
@ -678,9 +678,9 @@ Blockly.JavaScript['ugj_serial_open'] = function (block) {
|
|||||||
// var value_tty = Blockly.JavaScript.valueToCode(block, 'tty', Blockly.JavaScript.ORDER_ATOMIC);
|
// var value_tty = Blockly.JavaScript.valueToCode(block, 'tty', Blockly.JavaScript.ORDER_ATOMIC);
|
||||||
var dropdown_baud = block.getFieldValue('baud');
|
var dropdown_baud = block.getFieldValue('baud');
|
||||||
Blockly.JavaScript.provideFunction_(
|
Blockly.JavaScript.provideFunction_(
|
||||||
'require_gpio', [`const pi = require('@ocogeclub/` + elutil.gpio_backend + `');`]
|
'require_gpio', [`const _pi = require('@ocogeclub/` + elutil.gpio_backend + `');`]
|
||||||
);
|
);
|
||||||
var code = `await pi.serial_open('/dev/serial0', ${dropdown_baud});\n`;
|
var code = `await _pi.serial_open('/dev/serial0', ${dropdown_baud});\n`;
|
||||||
return code;
|
return code;
|
||||||
};
|
};
|
||||||
Blockly.Python['ugj_serial_open'] = function (block) {
|
Blockly.Python['ugj_serial_open'] = function (block) {
|
||||||
@ -711,7 +711,7 @@ Blockly.Blocks['ugj_serial_close'] = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
Blockly.JavaScript['ugj_serial_close'] = function (block) {
|
Blockly.JavaScript['ugj_serial_close'] = function (block) {
|
||||||
var code = 'pi.serial_close();\n';
|
var code = 'await _pi.serial_close();\n';
|
||||||
return code;
|
return code;
|
||||||
};
|
};
|
||||||
Blockly.Python['ugj_serial_close'] = function (block) {
|
Blockly.Python['ugj_serial_close'] = function (block) {
|
||||||
@ -746,7 +746,7 @@ Blockly.Blocks['ugj_serial_write'] = {
|
|||||||
};
|
};
|
||||||
Blockly.JavaScript['ugj_serial_write'] = function (block) {
|
Blockly.JavaScript['ugj_serial_write'] = function (block) {
|
||||||
var value_data = Blockly.JavaScript.valueToCode(block, 'data', Blockly.JavaScript.ORDER_ATOMIC);
|
var value_data = Blockly.JavaScript.valueToCode(block, 'data', Blockly.JavaScript.ORDER_ATOMIC);
|
||||||
var code = `await pi.serial_write(${value_data});\n`;
|
var code = `await _pi.serial_write(${value_data});\n`;
|
||||||
return code;
|
return code;
|
||||||
};
|
};
|
||||||
Blockly.Python['ugj_serial_write'] = function (block) {
|
Blockly.Python['ugj_serial_write'] = function (block) {
|
||||||
@ -781,7 +781,7 @@ Blockly.Blocks['ugj_serial_read'] = {
|
|||||||
};
|
};
|
||||||
Blockly.JavaScript['ugj_serial_read'] = function (block) {
|
Blockly.JavaScript['ugj_serial_read'] = function (block) {
|
||||||
var value_count = Blockly.JavaScript.valueToCode(block, 'count', Blockly.JavaScript.ORDER_ATOMIC);
|
var value_count = Blockly.JavaScript.valueToCode(block, 'count', Blockly.JavaScript.ORDER_ATOMIC);
|
||||||
var code = `await pi.serial_read(${value_count})`;
|
var code = `await _pi.serial_read(${value_count})`;
|
||||||
return [code, Blockly.JavaScript.ORDER_ATOMIC];
|
return [code, Blockly.JavaScript.ORDER_ATOMIC];
|
||||||
};
|
};
|
||||||
Blockly.Python['ugj_serial_read'] = function (block) {
|
Blockly.Python['ugj_serial_read'] = function (block) {
|
||||||
@ -818,9 +818,9 @@ Blockly.Blocks['ugj_i2c_open'] = {
|
|||||||
Blockly.JavaScript['ugj_i2c_open'] = function (block) {
|
Blockly.JavaScript['ugj_i2c_open'] = function (block) {
|
||||||
var value_i2c_address = Blockly.JavaScript.valueToCode(block, 'i2c_address', Blockly.JavaScript.ORDER_ATOMIC);
|
var value_i2c_address = Blockly.JavaScript.valueToCode(block, 'i2c_address', Blockly.JavaScript.ORDER_ATOMIC);
|
||||||
Blockly.JavaScript.provideFunction_(
|
Blockly.JavaScript.provideFunction_(
|
||||||
'require_gpio', [`const pi = require('@ocogeclub/` + elutil.gpio_backend + `');`]
|
'require_gpio', [`const _pi = require('@ocogeclub/` + elutil.gpio_backend + `');`]
|
||||||
);
|
);
|
||||||
var code = `console.log('i2c_hand='+pi.i2c_open(${elutil.i2c_bus}, ${value_i2c_address}));\n`;
|
var code = `await _pi.i2c_open(${elutil.i2c_bus}, ${value_i2c_address});\n`;
|
||||||
return code;
|
return code;
|
||||||
};
|
};
|
||||||
Blockly.Python['ugj_i2c_open'] = function (block) {
|
Blockly.Python['ugj_i2c_open'] = function (block) {
|
||||||
@ -850,7 +850,7 @@ Blockly.Blocks['ugj_i2c_close'] = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
Blockly.JavaScript['ugj_i2c_close'] = function (block) {
|
Blockly.JavaScript['ugj_i2c_close'] = function (block) {
|
||||||
var code = `await pi.i2c_close();\n`;
|
var code = `await _pi.i2c_close();\n`;
|
||||||
return code;
|
return code;
|
||||||
};
|
};
|
||||||
Blockly.Python['ugj_i2c_close'] = function (block) {
|
Blockly.Python['ugj_i2c_close'] = function (block) {
|
||||||
@ -891,7 +891,7 @@ Blockly.Blocks['ugj_i2c_write_byte_data'] = {
|
|||||||
Blockly.JavaScript['ugj_i2c_write_byte_data'] = function (block) {
|
Blockly.JavaScript['ugj_i2c_write_byte_data'] = function (block) {
|
||||||
var value_reg = Blockly.JavaScript.valueToCode(block, 'reg', Blockly.JavaScript.ORDER_ATOMIC);
|
var value_reg = Blockly.JavaScript.valueToCode(block, 'reg', Blockly.JavaScript.ORDER_ATOMIC);
|
||||||
var value_byte_val = Blockly.JavaScript.valueToCode(block, 'byte_val', Blockly.JavaScript.ORDER_ATOMIC);
|
var value_byte_val = Blockly.JavaScript.valueToCode(block, 'byte_val', Blockly.JavaScript.ORDER_ATOMIC);
|
||||||
var code = `await pi.i2c_write_byte_data(${value_reg}, ${value_byte_val});\n`;
|
var code = `await _pi.i2c_write_byte_data(${value_reg}, ${value_byte_val});\n`;
|
||||||
return code;
|
return code;
|
||||||
};
|
};
|
||||||
Blockly.Python['ugj_i2c_write_byte_data'] = function (block) {
|
Blockly.Python['ugj_i2c_write_byte_data'] = function (block) {
|
||||||
@ -927,7 +927,7 @@ Blockly.Blocks['ugj_i2c_read_byte_data'] = {
|
|||||||
};
|
};
|
||||||
Blockly.JavaScript['ugj_i2c_read_byte_data'] = function (block) {
|
Blockly.JavaScript['ugj_i2c_read_byte_data'] = function (block) {
|
||||||
var value_reg = Blockly.JavaScript.valueToCode(block, 'reg', Blockly.JavaScript.ORDER_ATOMIC);
|
var value_reg = Blockly.JavaScript.valueToCode(block, 'reg', Blockly.JavaScript.ORDER_ATOMIC);
|
||||||
var code = `await pi.i2c_read_byte_data(${value_reg})\n`;
|
var code = `await _pi.i2c_read_byte_data(${value_reg})\n`;
|
||||||
return [code, Blockly.JavaScript.ORDER_ATOMIC];
|
return [code, Blockly.JavaScript.ORDER_ATOMIC];
|
||||||
};
|
};
|
||||||
Blockly.Python['ugj_i2c_read_byte_data'] = function (block) {
|
Blockly.Python['ugj_i2c_read_byte_data'] = function (block) {
|
||||||
@ -966,7 +966,7 @@ Blockly.Blocks['ugj_i2c_write_i2c_block_data'] = {
|
|||||||
Blockly.JavaScript['ugj_i2c_write_i2c_block_data'] = function (block) {
|
Blockly.JavaScript['ugj_i2c_write_i2c_block_data'] = function (block) {
|
||||||
var value_reg = Blockly.JavaScript.valueToCode(block, 'reg', Blockly.JavaScript.ORDER_ATOMIC);
|
var value_reg = Blockly.JavaScript.valueToCode(block, 'reg', Blockly.JavaScript.ORDER_ATOMIC);
|
||||||
var value_data = Blockly.JavaScript.valueToCode(block, 'data', Blockly.JavaScript.ORDER_ATOMIC);
|
var value_data = Blockly.JavaScript.valueToCode(block, 'data', Blockly.JavaScript.ORDER_ATOMIC);
|
||||||
var code = `await pi.i2c_write_i2c_block_data (${value_reg}, ${value_data});`;
|
var code = `await _pi.i2c_write_i2c_block_data (${value_reg}, ${value_data});`;
|
||||||
return code;
|
return code;
|
||||||
};
|
};
|
||||||
Blockly.Python['ugj_i2c_write_i2c_block_data'] = function (block) {
|
Blockly.Python['ugj_i2c_write_i2c_block_data'] = function (block) {
|
||||||
@ -1003,7 +1003,7 @@ Blockly.Blocks['ugj_i2c_read_device'] = {
|
|||||||
};
|
};
|
||||||
Blockly.JavaScript['ugj_i2c_read_device'] = function (block) {
|
Blockly.JavaScript['ugj_i2c_read_device'] = function (block) {
|
||||||
var value_count = Blockly.JavaScript.valueToCode(block, 'count', Blockly.JavaScript.ORDER_ATOMIC);
|
var value_count = Blockly.JavaScript.valueToCode(block, 'count', Blockly.JavaScript.ORDER_ATOMIC);
|
||||||
var code = `await pi.i2c_read_device(${value_count})`;
|
var code = `await _pi.i2c_read_device(${value_count})`;
|
||||||
return [code, Blockly.JavaScript.ORDER_ATOMIC];
|
return [code, Blockly.JavaScript.ORDER_ATOMIC];
|
||||||
};
|
};
|
||||||
Blockly.Python['ugj_i2c_read_device'] = function (block) {
|
Blockly.Python['ugj_i2c_read_device'] = function (block) {
|
||||||
@ -1038,7 +1038,7 @@ Blockly.Blocks['ugj_i2c_write_device'] = {
|
|||||||
};
|
};
|
||||||
Blockly.JavaScript['ugj_i2c_write_device'] = function (block) {
|
Blockly.JavaScript['ugj_i2c_write_device'] = function (block) {
|
||||||
var value_data = Blockly.JavaScript.valueToCode(block, 'data', Blockly.JavaScript.ORDER_ATOMIC);
|
var value_data = Blockly.JavaScript.valueToCode(block, 'data', Blockly.JavaScript.ORDER_ATOMIC);
|
||||||
var code = `await pi.i2c_write_device(${value_data})\n`;
|
var code = `await _pi.i2c_write_device(${value_data})\n`;
|
||||||
return code;
|
return code;
|
||||||
};
|
};
|
||||||
Blockly.Python['ugj_i2c_write_device'] = function (block) {
|
Blockly.Python['ugj_i2c_write_device'] = function (block) {
|
||||||
@ -1094,19 +1094,19 @@ Blockly.JavaScript['ugj_bme280'] = function (block) {
|
|||||||
var variable_hum = Blockly.JavaScript.nameDB_.getName(block.getFieldValue('hum'), Blockly.Variables.NAME_TYPE);
|
var variable_hum = Blockly.JavaScript.nameDB_.getName(block.getFieldValue('hum'), Blockly.Variables.NAME_TYPE);
|
||||||
var variable_pres = Blockly.JavaScript.nameDB_.getName(block.getFieldValue('pres'), Blockly.Variables.NAME_TYPE);
|
var variable_pres = Blockly.JavaScript.nameDB_.getName(block.getFieldValue('pres'), Blockly.Variables.NAME_TYPE);
|
||||||
Blockly.JavaScript.provideFunction_(
|
Blockly.JavaScript.provideFunction_(
|
||||||
'require_bme280', [`const bme280 = require('@ocogeclub/bme280');`]
|
'require_bme280', [`const _bme280 = require('@ocogeclub/bme280');`]
|
||||||
);
|
);
|
||||||
var code = [
|
var code = [
|
||||||
`const options = {`,
|
`const options = {`,
|
||||||
` i2cBusNo: ${elutil.i2c_bus},`,
|
` i2cBusNo: ${elutil.i2c_bus},`,
|
||||||
` i2cAddress: ${value_address}`,
|
` i2cAddress: ${value_address}`,
|
||||||
`};`,
|
`};`,
|
||||||
`await bme280.init(options);`,
|
`await _bme280.init(options);`,
|
||||||
`let thp = await bme280.readSensorData();`,
|
`let _thp = await _bme280.readSensorData();`,
|
||||||
`${variable_temp} = Math.round(thp.temperature_C * 10) / 10;`,
|
`${variable_temp} = Math.round(_thp.temperature_C * 10) / 10;`,
|
||||||
`${variable_hum} = Math.round(thp.humidity * 10) / 10;`,
|
`${variable_hum} = Math.round(_thp.humidity * 10) / 10;`,
|
||||||
`${variable_pres} = Math.round(thp.pressure_hPa);`,
|
`${variable_pres} = Math.round(_thp.pressure_hPa);`,
|
||||||
`await bme280.cancel();`,
|
`await _bme280.cancel();`,
|
||||||
``
|
``
|
||||||
].join('\n');
|
].join('\n');
|
||||||
return code;
|
return code;
|
||||||
@ -1159,9 +1159,9 @@ Blockly.Blocks['ugj_gesture_init'] = {
|
|||||||
Blockly.JavaScript['ugj_gesture_init'] = function (block) {
|
Blockly.JavaScript['ugj_gesture_init'] = function (block) {
|
||||||
var value_i2c_addr = Blockly.JavaScript.valueToCode(block, 'i2c_addr', Blockly.JavaScript.ORDER_ATOMIC);
|
var value_i2c_addr = Blockly.JavaScript.valueToCode(block, 'i2c_addr', Blockly.JavaScript.ORDER_ATOMIC);
|
||||||
Blockly.JavaScript.provideFunction_(
|
Blockly.JavaScript.provideFunction_(
|
||||||
'require_paj7620', [`const paj7620 = require('@ocogeclub/paj7620');`]
|
'require_paj7620', [`const _paj7620 = require('@ocogeclub/paj7620');`]
|
||||||
);
|
);
|
||||||
var code = `await paj7620.init(${elutil.i2c_bus}, ${value_i2c_addr});
|
var code = `await _paj7620.init(${elutil.i2c_bus}, ${value_i2c_addr});
|
||||||
`;
|
`;
|
||||||
return code;
|
return code;
|
||||||
};
|
};
|
||||||
@ -1190,7 +1190,7 @@ Blockly.Blocks['ugj_gesture_read'] = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
Blockly.JavaScript['ugj_gesture_read'] = function (block) {
|
Blockly.JavaScript['ugj_gesture_read'] = function (block) {
|
||||||
var code = 'await paj7620.return_gesture()';
|
var code = 'await _paj7620.return_gesture()';
|
||||||
return [code, Blockly.JavaScript.ORDER_ATOMIC];
|
return [code, Blockly.JavaScript.ORDER_ATOMIC];
|
||||||
};
|
};
|
||||||
Blockly.Python['ugj_gesture_read'] = function (block) {
|
Blockly.Python['ugj_gesture_read'] = function (block) {
|
||||||
@ -1218,7 +1218,7 @@ Blockly.Blocks['ugj_gesture_stop'] = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
Blockly.JavaScript['ugj_gesture_stop'] = function (block) {
|
Blockly.JavaScript['ugj_gesture_stop'] = function (block) {
|
||||||
var code = 'await paj7620.stop();\n';
|
var code = 'await _paj7620.stop();\n';
|
||||||
return code;
|
return code;
|
||||||
};
|
};
|
||||||
Blockly.Python['ugj_gesture_stop'] = function (block) {
|
Blockly.Python['ugj_gesture_stop'] = function (block) {
|
||||||
@ -1366,8 +1366,30 @@ Blockly.Python['ugj_grideye_stop'] = function (block) {
|
|||||||
var with_landmark;
|
var with_landmark;
|
||||||
var ugjFaceapiDefinition = {
|
var ugjFaceapiDefinition = {
|
||||||
"type": "ugj_faceapi",
|
"type": "ugj_faceapi",
|
||||||
"message0": "%{BKY_UGJ_FACEAPI_TITLE}",
|
"message0": "TensorFlowによる顔検出を1秒に %1 回実行: %2 ランドマークを検出 %3 %4",
|
||||||
"args0": [
|
"args0": [
|
||||||
|
{
|
||||||
|
"type": "field_dropdown",
|
||||||
|
"name": "interval_sec",
|
||||||
|
"options": [
|
||||||
|
[
|
||||||
|
"1",
|
||||||
|
"1000"
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"2",
|
||||||
|
"500"
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"5",
|
||||||
|
"200"
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"10",
|
||||||
|
"100"
|
||||||
|
]
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "field_checkbox",
|
"type": "field_checkbox",
|
||||||
"name": "with_landmark",
|
"name": "with_landmark",
|
||||||
@ -1381,8 +1403,7 @@ var ugjFaceapiDefinition = {
|
|||||||
"name": "do"
|
"name": "do"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"inputsInline": true,
|
"tooltip": "TensorFlow とFaceAPI をロードし、顔検出をできるようにします。",
|
||||||
"tooltip": "%{BKY_UGJ_FACEAPI_TOOLTIP}",
|
|
||||||
"helpUrl": "",
|
"helpUrl": "",
|
||||||
"style": "multimedia_blocks"
|
"style": "multimedia_blocks"
|
||||||
};
|
};
|
||||||
@ -1392,11 +1413,13 @@ Blockly.Blocks['ugj_faceapi'] = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
Blockly.JavaScript['ugj_faceapi'] = function (block) {
|
Blockly.JavaScript['ugj_faceapi'] = function (block) {
|
||||||
|
var dropdown_interval_sec = block.getFieldValue('interval_sec');
|
||||||
with_landmark = block.getFieldValue('with_landmark') == 'TRUE';
|
with_landmark = block.getFieldValue('with_landmark') == 'TRUE';
|
||||||
var statements_do = Blockly.JavaScript.statementToCode(block, 'do');
|
var statements_do = Blockly.JavaScript.statementToCode(block, 'do');
|
||||||
var code = [
|
var code = [
|
||||||
`require('@tensorflow/tfjs-node');`,
|
`require('@tensorflow/tfjs-node');`,
|
||||||
`const faceapi = require('@vladmandic/face-api/dist/face-api.node.js');`,
|
`const _faceapi = require('@vladmandic/face-api/dist/face-api.node.js');`,
|
||||||
|
`const _interval_sec = ${dropdown_interval_sec};`,
|
||||||
statements_do,
|
statements_do,
|
||||||
''
|
''
|
||||||
].join('\n');
|
].join('\n');
|
||||||
@ -1416,10 +1439,10 @@ Blockly.Blocks['ugj_face_init'] = {
|
|||||||
};
|
};
|
||||||
Blockly.JavaScript['ugj_face_init'] = function (block) {
|
Blockly.JavaScript['ugj_face_init'] = function (block) {
|
||||||
var code = [
|
var code = [
|
||||||
"const videoEl = document.getElementById('subdisplay');",
|
"const _videoEl = document.getElementById('subdisplay');",
|
||||||
`const displaySize = { width: videoEl.width, height: videoEl.height };`,
|
`const _displaySize = { width: videoEl.width, height: videoEl.height };`,
|
||||||
"const stream = await navigator.mediaDevices.getUserMedia({ audio: false, video: displaySize });",
|
"const _stream = await navigator.mediaDevices.getUserMedia({ audio: false, video: _displaySize });",
|
||||||
"videoEl.srcObject = stream;",
|
"_videoEl.srcObject = _stream;",
|
||||||
""
|
""
|
||||||
].join('\n');
|
].join('\n');
|
||||||
return code;
|
return code;
|
||||||
@ -1438,12 +1461,12 @@ Blockly.Blocks['ugj_face_display'] = {
|
|||||||
};
|
};
|
||||||
Blockly.JavaScript['ugj_face_display'] = function (block) {
|
Blockly.JavaScript['ugj_face_display'] = function (block) {
|
||||||
var code = [
|
var code = [
|
||||||
"videoEl.style.display = 'inline-block';",
|
"_videoEl.style.display = 'inline-block';",
|
||||||
`const overlay = document.createElement('canvas');`,
|
`const _overlay = document.createElement('canvas');`,
|
||||||
`overlay.setAttribute('width', videoEl.width);`,
|
`_overlay.setAttribute('width', _videoEl.width);`,
|
||||||
`overlay.setAttribute('height', videoEl.height);`,
|
`_overlay.setAttribute('height', _videoEl.height);`,
|
||||||
`overlay.className = 'subdisplay';`,
|
`_overlay.className = 'subdisplay';`,
|
||||||
`document.getElementById('display_area').appendChild(overlay);`,
|
`document.getElementById('display_area').appendChild(_overlay);`,
|
||||||
""
|
""
|
||||||
].join('\n');
|
].join('\n');
|
||||||
return code;
|
return code;
|
||||||
@ -1472,41 +1495,41 @@ Blockly.JavaScript['ugj_face_detect'] = function (block) {
|
|||||||
var variable_w = Blockly.JavaScript.nameDB_.getName(block.getFieldValue('w'), Blockly.Variables.NAME_TYPE);
|
var variable_w = Blockly.JavaScript.nameDB_.getName(block.getFieldValue('w'), Blockly.Variables.NAME_TYPE);
|
||||||
var variable_h = Blockly.JavaScript.nameDB_.getName(block.getFieldValue('h'), Blockly.Variables.NAME_TYPE);
|
var variable_h = Blockly.JavaScript.nameDB_.getName(block.getFieldValue('h'), Blockly.Variables.NAME_TYPE);
|
||||||
var statements_do = Blockly.JavaScript.statementToCode(block, 'do');
|
var statements_do = Blockly.JavaScript.statementToCode(block, 'do');
|
||||||
var code_model = `await faceapi.nets.tinyFaceDetector.load('${ugj_const.library_path}models/');`;
|
var code_model = `await _faceapi.nets.tinyFaceDetector.load('${ugj_const.library_path}models/');`;
|
||||||
if (with_landmark) { code_model += `\nawait faceapi.nets.faceLandmark68TinyNet.load('${ugj_const.library_path}models/');`; }
|
if (with_landmark) { code_model += `\nawait _faceapi.nets.faceLandmark68TinyNet.load('${ugj_const.library_path}models/');`; }
|
||||||
var code_detect_face = " let result = await faceapi.detectSingleFace(videoEl, options)"
|
var code_detect_face = " let _result = await _faceapi.detectSingleFace(_videoEl, _options)"
|
||||||
if (with_landmark) { code_detect_face += `.withFaceLandmarks(true);` }
|
if (with_landmark) { code_detect_face += `.withFaceLandmarks(true);` }
|
||||||
else { code_detect_face += `;` }
|
else { code_detect_face += `;` }
|
||||||
var code_rect;
|
var code_rect;
|
||||||
if (with_landmark) {
|
if (with_landmark) {
|
||||||
code_rect = [
|
code_rect = [
|
||||||
` ${variable_x} = Math.round(result.detection.box.x);`,
|
` ${variable_x} = Math.round(_result.detection.box.x);`,
|
||||||
` ${variable_y} = Math.round(result.detection.box.y);`,
|
` ${variable_y} = Math.round(_result.detection.box.y);`,
|
||||||
` ${variable_w} = Math.round(result.detection.box.width);`,
|
` ${variable_w} = Math.round(_result.detection.box.width);`,
|
||||||
` ${variable_h} = Math.round(result.detection.box.height);`,
|
` ${variable_h} = Math.round(_result.detection.box.height);`,
|
||||||
].join('\n');
|
].join('\n');
|
||||||
} else {
|
} else {
|
||||||
code_rect = [
|
code_rect = [
|
||||||
` ${variable_x} = Math.round(result.box.x);`,
|
` ${variable_x} = Math.round(_result.box.x);`,
|
||||||
` ${variable_y} = Math.round(result.box.y);`,
|
` ${variable_y} = Math.round(_result.box.y);`,
|
||||||
` ${variable_w} = Math.round(result.box.width);`,
|
` ${variable_w} = Math.round(_result.box.width);`,
|
||||||
` ${variable_h} = Math.round(result.box.height);`,
|
` ${variable_h} = Math.round(_result.box.height);`,
|
||||||
].join('\n');
|
].join('\n');
|
||||||
}
|
}
|
||||||
var code = [
|
var code = [
|
||||||
code_model,
|
code_model,
|
||||||
"const options = new faceapi.TinyFaceDetectorOptions({ inputSize: 128, scoreThreshold : 0.3 });",
|
"const _options = new _faceapi.TinyFaceDetectorOptions({ inputSize: 128, scoreThreshold : 0.3 });",
|
||||||
`const onPlay = async () => {`,
|
// `const _onPlay = async () => {`,
|
||||||
// ` const detectInterval = setInterval(async () => {`,
|
` const _detectInterval = setInterval(async () => {`,
|
||||||
code_detect_face,
|
code_detect_face,
|
||||||
" if (result) {",
|
" if (_result) {",
|
||||||
code_rect,
|
code_rect,
|
||||||
statements_do,
|
statements_do,
|
||||||
" }",
|
" }",
|
||||||
// ` }, 500);`,
|
` }, _interval_sec);`,
|
||||||
" setTimeout(() => onPlay())",
|
// " setTimeout(() => onPlay())",
|
||||||
"}",
|
// "}",
|
||||||
"videoEl.onplay = onPlay;",
|
// "_videoEl.onplay = _onPlay;",
|
||||||
""
|
""
|
||||||
].join('\n');
|
].join('\n');
|
||||||
return code;
|
return code;
|
||||||
@ -1525,11 +1548,11 @@ Blockly.Blocks['ugj_face_drawrect'] = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
Blockly.JavaScript['ugj_face_drawrect'] = function (block) {
|
Blockly.JavaScript['ugj_face_drawrect'] = function (block) {
|
||||||
var code_draw = ` faceapi.draw.drawDetections(overlay, resizedDetections);`;
|
var code_draw = ` _faceapi.draw.drawDetections(_overlay, _resizedDetections);`;
|
||||||
if (with_landmark) { code_draw += `\n faceapi.draw.drawFaceLandmarks(overlay, resizedDetections);`; }
|
if (with_landmark) { code_draw += `\n faceapi.draw.drawFaceLandmarks(overlay, resizedDetections);`; }
|
||||||
var code = [
|
var code = [
|
||||||
` faceapi.matchDimensions(overlay, displaySize);`,
|
` _faceapi.matchDimensions(_overlay, _displaySize);`,
|
||||||
` const resizedDetections = faceapi.resizeResults(result, displaySize);`,
|
` const _resizedDetections = _faceapi.resizeResults(_result, _displaySize);`,
|
||||||
code_draw,
|
code_draw,
|
||||||
""
|
""
|
||||||
].join('\n');
|
].join('\n');
|
||||||
@ -1599,9 +1622,9 @@ Blockly.Blocks['ugj_canvas_init'] = {
|
|||||||
};
|
};
|
||||||
Blockly.JavaScript['ugj_canvas_init'] = function (block) {
|
Blockly.JavaScript['ugj_canvas_init'] = function (block) {
|
||||||
var code = [
|
var code = [
|
||||||
`let canvas = document.getElementById('gcanvas');`,
|
`let _canvas = document.getElementById('gcanvas');`,
|
||||||
`canvas.style.display = 'inline-block';`,
|
`_canvas.style.display = 'inline-block';`,
|
||||||
"let ctx = canvas.getContext('2d');",
|
"let _ctx = _canvas.getContext('2d');",
|
||||||
''
|
''
|
||||||
].join('\n');
|
].join('\n');
|
||||||
|
|
||||||
@ -1649,9 +1672,9 @@ Blockly.Blocks['ugj_canvas_loadimg'] = {
|
|||||||
Blockly.JavaScript['ugj_canvas_loadimg'] = function (block) {
|
Blockly.JavaScript['ugj_canvas_loadimg'] = function (block) {
|
||||||
var value_imgfilename = Blockly.JavaScript.valueToCode(block, 'imgfilename', Blockly.JavaScript.ORDER_ATOMIC);
|
var value_imgfilename = Blockly.JavaScript.valueToCode(block, 'imgfilename', Blockly.JavaScript.ORDER_ATOMIC);
|
||||||
var code = [
|
var code = [
|
||||||
`let img = new Image();`,
|
`let _img = new Image();`,
|
||||||
`img.src = '${ugj_const.doc_root}' + ${value_imgfilename};`,
|
`_img.src = '${ugj_const.doc_root}' + ${value_imgfilename};`,
|
||||||
`img.onload = () => ctx.drawImage(img,0,0);`,
|
`_img.onload = () => _ctx.drawImage(img,0,0);`,
|
||||||
// `ugj_canvasImg('${ugj_const.doc_root}' + ${value_imgfilename});`,
|
// `ugj_canvasImg('${ugj_const.doc_root}' + ${value_imgfilename});`,
|
||||||
''
|
''
|
||||||
].join('\n');
|
].join('\n');
|
||||||
@ -1689,7 +1712,7 @@ Blockly.JavaScript['ugj_canvas_clearrect'] = function (block) {
|
|||||||
var value_y = Blockly.JavaScript.valueToCode(block, 'y', Blockly.JavaScript.ORDER_ATOMIC);
|
var value_y = Blockly.JavaScript.valueToCode(block, 'y', Blockly.JavaScript.ORDER_ATOMIC);
|
||||||
var value_w = Blockly.JavaScript.valueToCode(block, 'w', Blockly.JavaScript.ORDER_ATOMIC);
|
var value_w = Blockly.JavaScript.valueToCode(block, 'w', Blockly.JavaScript.ORDER_ATOMIC);
|
||||||
var value_h = Blockly.JavaScript.valueToCode(block, 'h', Blockly.JavaScript.ORDER_ATOMIC);
|
var value_h = Blockly.JavaScript.valueToCode(block, 'h', Blockly.JavaScript.ORDER_ATOMIC);
|
||||||
var code = `ctx.clearRect(${value_x},${value_y}, ${value_w}, ${value_h});\n`;
|
var code = `_ctx.clearRect(${value_x},${value_y}, ${value_w}, ${value_h});\n`;
|
||||||
return code;
|
return code;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1710,7 +1733,7 @@ Blockly.Blocks['ugj_canvas_width'] = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
Blockly.JavaScript['ugj_canvas_width'] = function (block) {
|
Blockly.JavaScript['ugj_canvas_width'] = function (block) {
|
||||||
var code = 'canvas.width';
|
var code = '_canvas.width';
|
||||||
return [code, Blockly.JavaScript.ORDER_NONE];
|
return [code, Blockly.JavaScript.ORDER_NONE];
|
||||||
};
|
};
|
||||||
/*********************** */
|
/*********************** */
|
||||||
@ -1729,7 +1752,7 @@ Blockly.Blocks['ugj_canvas_height'] = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
Blockly.JavaScript['ugj_canvas_height'] = function (block) {
|
Blockly.JavaScript['ugj_canvas_height'] = function (block) {
|
||||||
var code = 'canvas.height';
|
var code = '_canvas.height';
|
||||||
return [code, Blockly.JavaScript.ORDER_NONE];
|
return [code, Blockly.JavaScript.ORDER_NONE];
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1768,11 +1791,11 @@ Blockly.JavaScript['ugj_canvas_drawcircle'] = function (block) {
|
|||||||
var value_r = Blockly.JavaScript.valueToCode(block, 'r', Blockly.JavaScript.ORDER_ATOMIC);
|
var value_r = Blockly.JavaScript.valueToCode(block, 'r', Blockly.JavaScript.ORDER_ATOMIC);
|
||||||
var value_color = Blockly.JavaScript.valueToCode(block, 'color', Blockly.JavaScript.ORDER_ATOMIC);
|
var value_color = Blockly.JavaScript.valueToCode(block, 'color', Blockly.JavaScript.ORDER_ATOMIC);
|
||||||
var code = [
|
var code = [
|
||||||
'ctx.beginPath();',
|
'_ctx.beginPath();',
|
||||||
`ctx.arc(${value_x}, ${value_y}, ${value_r}, 0, Math.PI*2);`,
|
`_ctx.arc(${value_x}, ${value_y}, ${value_r}, 0, Math.PI*2);`,
|
||||||
`ctx.fillStyle = ${value_color};`,
|
`_ctx.fillStyle = ${value_color};`,
|
||||||
'ctx.fill();',
|
'_ctx.fill();',
|
||||||
'ctx.closePath();',
|
'_ctx.closePath();',
|
||||||
''
|
''
|
||||||
].join('\n');
|
].join('\n');
|
||||||
return code;
|
return code;
|
||||||
@ -1815,11 +1838,11 @@ Blockly.JavaScript['ugj_canvas_drawrect'] = function (block) {
|
|||||||
var value_h = Blockly.JavaScript.valueToCode(block, 'h', Blockly.JavaScript.ORDER_ATOMIC);
|
var value_h = Blockly.JavaScript.valueToCode(block, 'h', Blockly.JavaScript.ORDER_ATOMIC);
|
||||||
var value_color = Blockly.JavaScript.valueToCode(block, 'color', Blockly.JavaScript.ORDER_ATOMIC);
|
var value_color = Blockly.JavaScript.valueToCode(block, 'color', Blockly.JavaScript.ORDER_ATOMIC);
|
||||||
var code = [
|
var code = [
|
||||||
`ctx.beginPath();`,
|
`_ctx.beginPath();`,
|
||||||
`ctx.rect(${value_x}, ${value_y}, ${value_w}, ${value_h});`,
|
`_ctx.rect(${value_x}, ${value_y}, ${value_w}, ${value_h});`,
|
||||||
`ctx.fillStyle = ${value_color};`,
|
`_ctx.fillStyle = ${value_color};`,
|
||||||
`ctx.fill();`,
|
`_ctx.fill();`,
|
||||||
`ctx.closePath();`,
|
`_ctx.closePath();`,
|
||||||
''
|
''
|
||||||
].join('\n');
|
].join('\n');
|
||||||
return code;
|
return code;
|
||||||
@ -1914,7 +1937,7 @@ Blockly.JavaScript['ugj_draw_grideyedata'] = function (block) {
|
|||||||
var colour_color_low = block.getFieldValue('color_low');
|
var colour_color_low = block.getFieldValue('color_low');
|
||||||
var value_temp_low = Blockly.JavaScript.valueToCode(block, 'temp_low', Blockly.JavaScript.ORDER_ATOMIC);
|
var value_temp_low = Blockly.JavaScript.valueToCode(block, 'temp_low', Blockly.JavaScript.ORDER_ATOMIC);
|
||||||
var functionName = Blockly.JavaScript.provideFunction_(
|
var functionName = Blockly.JavaScript.provideFunction_(
|
||||||
'mapVal',
|
'_mapVal',
|
||||||
['const ' + Blockly.JavaScript.FUNCTION_NAME_PLACEHOLDER_ + ' = (val, inMin, inMax, outMin, outMax) => {',
|
['const ' + Blockly.JavaScript.FUNCTION_NAME_PLACEHOLDER_ + ' = (val, inMin, inMax, outMin, outMax) => {',
|
||||||
`return (val - inMin) * (outMax - outMin) / (inMax - inMin) + outMin;`,
|
`return (val - inMin) * (outMax - outMin) / (inMax - inMin) + outMin;`,
|
||||||
'}'
|
'}'
|
||||||
@ -2132,8 +2155,8 @@ Blockly.JavaScript['ugj_event_key'] = function (block) {
|
|||||||
var dropdown_updown = block.getFieldValue('updown');
|
var dropdown_updown = block.getFieldValue('updown');
|
||||||
var statements_do = Blockly.JavaScript.statementToCode(block, 'do');
|
var statements_do = Blockly.JavaScript.statementToCode(block, 'do');
|
||||||
var code = [
|
var code = [
|
||||||
`document.addEventListener('${dropdown_updown}', async (e) => {`,
|
`document.addEventListener('${dropdown_updown}', async (_e) => {`,
|
||||||
` ${variable_key} = e.key;`,
|
` ${variable_key} = _e.key;`,
|
||||||
statements_do,
|
statements_do,
|
||||||
`}, false);`,
|
`}, false);`,
|
||||||
''
|
''
|
||||||
@ -2201,14 +2224,14 @@ Blockly.JavaScript['ugj_socket'] = function (block) {
|
|||||||
var variable_data = Blockly.JavaScript.nameDB_.getName(block.getFieldValue('data'), Blockly.Variables.NAME_TYPE);
|
var variable_data = Blockly.JavaScript.nameDB_.getName(block.getFieldValue('data'), Blockly.Variables.NAME_TYPE);
|
||||||
var statements_data = Blockly.JavaScript.statementToCode(block, 'data');
|
var statements_data = Blockly.JavaScript.statementToCode(block, 'data');
|
||||||
Blockly.JavaScript.provideFunction_(
|
Blockly.JavaScript.provideFunction_(
|
||||||
'require_net', [`const net = require('net');`]
|
'require_net', [`const _net = require('net');`]
|
||||||
);
|
);
|
||||||
var code = [
|
var code = [
|
||||||
`var client = net.connect(${value_port}, ${value_host});`,
|
`var _client = _net.connect(${value_port}, ${value_host});`,
|
||||||
`client.on('connect', async ()=>{`,
|
`_client.on('connect', async ()=>{`,
|
||||||
statements_connect,
|
statements_connect,
|
||||||
`}).on('data', async data=>{`,
|
`}).on('data', async _data=>{`,
|
||||||
`${variable_data} = data.toString('utf-8', 0, data.length);`,
|
`${variable_data} = _data.toString('utf-8', 0, _data.length);`,
|
||||||
statements_data,
|
statements_data,
|
||||||
`}).on('close', ()=>{`,
|
`}).on('close', ()=>{`,
|
||||||
`console.log('Connection closed.');`,
|
`console.log('Connection closed.');`,
|
||||||
@ -2238,7 +2261,7 @@ Blockly.Blocks['ugj_socket_write'] = {
|
|||||||
Blockly.JavaScript['ugj_socket_write'] = function (block) {
|
Blockly.JavaScript['ugj_socket_write'] = function (block) {
|
||||||
var value_cmd = Blockly.JavaScript.valueToCode(block, 'cmd', Blockly.JavaScript.ORDER_ATOMIC);
|
var value_cmd = Blockly.JavaScript.valueToCode(block, 'cmd', Blockly.JavaScript.ORDER_ATOMIC);
|
||||||
var code = [
|
var code = [
|
||||||
`client.write(${value_cmd});`,
|
`_client.write(${value_cmd});`,
|
||||||
''
|
''
|
||||||
].join('\n');
|
].join('\n');
|
||||||
return code;
|
return code;
|
||||||
@ -2272,16 +2295,16 @@ Blockly.JavaScript['ugj_network_httpserver'] = function (block) {
|
|||||||
var statements_do = Blockly.JavaScript.statementToCode(block, 'do');
|
var statements_do = Blockly.JavaScript.statementToCode(block, 'do');
|
||||||
var value_response = Blockly.JavaScript.valueToCode(block, 'response', Blockly.JavaScript.ORDER_ATOMIC);
|
var value_response = Blockly.JavaScript.valueToCode(block, 'response', Blockly.JavaScript.ORDER_ATOMIC);
|
||||||
Blockly.JavaScript.provideFunction_(
|
Blockly.JavaScript.provideFunction_(
|
||||||
'require_http', [`const http = require('http');`]
|
'require_http', [`const _http = require('http');`]
|
||||||
);
|
);
|
||||||
var code = [
|
var code = [
|
||||||
`let req, res;`,
|
`let _req, _res;`,
|
||||||
`http.createServer(async (req, res) => {`,
|
`_http.createServer(async (_req, _res) => {`,
|
||||||
`res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' });`,
|
`_res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' });`,
|
||||||
`${variable_url} = req.url;`,
|
`${variable_url} = _req.url;`,
|
||||||
statements_do,
|
statements_do,
|
||||||
// `res.write('<!DOCTYPE html><html lang="ja"><head><meta charset="UTF-8"></head><body>');`,
|
// `_res.write('<!DOCTYPE html><html lang="ja"><head><meta charset="UTF-8"></head><body>');`,
|
||||||
`res.end(${value_response});`,
|
`_res.end(${value_response});`,
|
||||||
`}).listen(3000);`,
|
`}).listen(3000);`,
|
||||||
''
|
''
|
||||||
].join('\n');
|
].join('\n');
|
||||||
@ -2310,7 +2333,7 @@ Blockly.Blocks['ugj_network_axios_geturl'] = {
|
|||||||
Blockly.JavaScript['ugj_network_axios_geturl'] = function (block) {
|
Blockly.JavaScript['ugj_network_axios_geturl'] = function (block) {
|
||||||
var value_url = Blockly.JavaScript.valueToCode(block, 'url', Blockly.JavaScript.ORDER_ATOMIC);
|
var value_url = Blockly.JavaScript.valueToCode(block, 'url', Blockly.JavaScript.ORDER_ATOMIC);
|
||||||
var functionName = Blockly.JavaScript.provideFunction_(
|
var functionName = Blockly.JavaScript.provideFunction_(
|
||||||
'getUrl',
|
'_getUrl',
|
||||||
[
|
[
|
||||||
`const axios = require('axios');`,
|
`const axios = require('axios');`,
|
||||||
'const ' + Blockly.JavaScript.FUNCTION_NAME_PLACEHOLDER_ + ' = async url => {',
|
'const ' + Blockly.JavaScript.FUNCTION_NAME_PLACEHOLDER_ + ' = async url => {',
|
||||||
@ -2359,28 +2382,28 @@ Blockly.JavaScript['ugj_network_sendmail'] = function (block) {
|
|||||||
var value_subject = Blockly.JavaScript.valueToCode(block, 'subject', Blockly.JavaScript.ORDER_ATOMIC);
|
var value_subject = Blockly.JavaScript.valueToCode(block, 'subject', Blockly.JavaScript.ORDER_ATOMIC);
|
||||||
var value_text = Blockly.JavaScript.valueToCode(block, 'text', Blockly.JavaScript.ORDER_ATOMIC);
|
var value_text = Blockly.JavaScript.valueToCode(block, 'text', Blockly.JavaScript.ORDER_ATOMIC);
|
||||||
Blockly.JavaScript.provideFunction_(
|
Blockly.JavaScript.provideFunction_(
|
||||||
'require_sendmail', [`const nodemailer = require('nodemailer');`]
|
'require_sendmail', [`const _nodemailer = require('nodemailer');`]
|
||||||
);
|
);
|
||||||
var code = [
|
var code = [
|
||||||
`let smtp = nodemailer.createTransport({`,
|
`let _smtp = _nodemailer.createTransport({`,
|
||||||
`host: '192.168.0.201',`,
|
`host: '192.168.0.201',`,
|
||||||
`port: 25`,
|
`port: 25`,
|
||||||
`});`,
|
`});`,
|
||||||
`let message = {`,
|
`let _message = {`,
|
||||||
`from: 'no-reply@oc.x0.to',`,
|
`from: 'no-reply@oc.x0.to',`,
|
||||||
`to: ${value_to},`,
|
`to: ${value_to},`,
|
||||||
`subject: ${value_subject},`,
|
`subject: ${value_subject},`,
|
||||||
`text: ${value_text}`,
|
`text: ${value_text}`,
|
||||||
`};`,
|
`};`,
|
||||||
`try{`,
|
`try{`,
|
||||||
`smtp.sendMail(message, function(error, info){`,
|
`_smtp.sendMail(_message, function(_error, _info){`,
|
||||||
`if(error){`,
|
`if(_error){`,
|
||||||
`alert('送信エラー:' + error.message);`,
|
`alert('送信エラー:' + _error.message);`,
|
||||||
`return;`,
|
`return;`,
|
||||||
`}`,
|
`}`,
|
||||||
`console.log('send successfully');`,
|
`console.log('send successfully');`,
|
||||||
`});`,
|
`});`,
|
||||||
`} catch(e) {alert('Error: ',e);}`,
|
`} catch(_e) {alert('Error: ',_e);}`,
|
||||||
''
|
''
|
||||||
].join('\n');
|
].join('\n');
|
||||||
return code;
|
return code;
|
||||||
@ -2423,17 +2446,17 @@ Blockly.Blocks['ugj_webchat'] = {
|
|||||||
};
|
};
|
||||||
Blockly.JavaScript['ugj_webchat'] = function (block) {
|
Blockly.JavaScript['ugj_webchat'] = function (block) {
|
||||||
var code = [
|
var code = [
|
||||||
`const blackboard = document.getElementById('blackboard');`,
|
`const _blackboard = document.getElementById('blackboard');`,
|
||||||
"blackboard.style.display = 'inline-block';",
|
"_blackboard.style.display = 'inline-block';",
|
||||||
`const inputForm = document.getElementById('inputForm');`,
|
`const _inputForm = document.getElementById('inputForm');`,
|
||||||
"inputForm.style.display = 'inline-block';",
|
"_inputForm.style.display = 'inline-block';",
|
||||||
`const inputBox = document.getElementById('inputBox');`,
|
`const _inputBox = document.getElementById('inputBox');`,
|
||||||
"inputBox.focus();",
|
"_inputBox.focus();",
|
||||||
"const remoteVideo = document.getElementById('maindisplay');",
|
"const _remoteVideo = document.getElementById('maindisplay');",
|
||||||
`remoteVideo.style.display = 'inline-block';`,
|
`_remoteVideo.style.display = 'inline-block';`,
|
||||||
"const localVideo = document.getElementById('subdisplay');",
|
"const _localVideo = document.getElementById('subdisplay');",
|
||||||
`localVideo.style.display = 'inline-block';`,
|
`_localVideo.style.display = 'inline-block';`,
|
||||||
`var localStream;`,
|
`var _localStream;`,
|
||||||
''
|
''
|
||||||
].join('\n');
|
].join('\n');
|
||||||
return code;
|
return code;
|
||||||
@ -2454,11 +2477,11 @@ Blockly.Blocks['ugj_getusermedia'] = {
|
|||||||
Blockly.JavaScript['ugj_getusermedia'] = function (block) {
|
Blockly.JavaScript['ugj_getusermedia'] = function (block) {
|
||||||
var code = [
|
var code = [
|
||||||
`navigator.mediaDevices.getUserMedia({video: true, audio: false})`,
|
`navigator.mediaDevices.getUserMedia({video: true, audio: false})`,
|
||||||
' .then(stream => {',
|
' .then(_stream => {',
|
||||||
' localVideo.srcObject = stream;',
|
' _localVideo.srcObject = _stream;',
|
||||||
' localStream = stream;',
|
' _localStream = _stream;',
|
||||||
' }).catch( error => {',
|
' }).catch( _error => {',
|
||||||
' console.error(\'mediaDevice.getUserMedia() error:\', error);',
|
' console.error(\'mediaDevice.getUserMedia() error:\', _error);',
|
||||||
' return;',
|
' return;',
|
||||||
' });',
|
' });',
|
||||||
''
|
''
|
||||||
@ -2489,24 +2512,24 @@ Blockly.JavaScript['ugj_skyway_newpeer'] = function (block) {
|
|||||||
// var text_name = block.getFieldValue('NAME');
|
// var text_name = block.getFieldValue('NAME');
|
||||||
var statements_do = Blockly.JavaScript.statementToCode(block, 'do');
|
var statements_do = Blockly.JavaScript.statementToCode(block, 'do');
|
||||||
var code = [
|
var code = [
|
||||||
`const peer = new Peer(${variable_my_id}, {`,
|
`const _peer = new Peer(${variable_my_id}, {`,
|
||||||
" key: window.__SKYWAY_KEY__,",
|
" key: window.__SKYWAY_KEY__,",
|
||||||
" debug: 3",
|
" debug: 3",
|
||||||
"});",
|
"});",
|
||||||
"peer.on('open', () => {",
|
"_peer.on('open', () => {",
|
||||||
// ' ugj_blackboardWrite(`SkyWay: "${peer.id}" OK`)',
|
// ' ugj_blackboardWrite(`SkyWay: "${peer.id}" OK`)',
|
||||||
`${variable_my_id} = peer.id;`,
|
`${variable_my_id} = _peer.id;`,
|
||||||
"inputForm.addEventListener('submit', onMakeCall);",
|
"_inputForm.addEventListener('submit', _onMakeCall);",
|
||||||
statements_do,
|
statements_do,
|
||||||
"});",
|
"});",
|
||||||
"peer.on('error', err => alert(err.message));",
|
"_peer.on('error', _err => alert(_err.message));",
|
||||||
"const onMakeCall = e => {",
|
"const _onMakeCall = _e => {",
|
||||||
" e.preventDefault();",
|
" _e.preventDefault();",
|
||||||
" const call = peer.call(inputBox.value, localStream);",
|
" const _call = _peer.call(_inputBox.value, _localStream);",
|
||||||
" setupCallEventHandlers(call);",
|
" setupCallEventHandlers(_call);",
|
||||||
" const connect = peer.connect(inputBox.value);",
|
" const _connect = peer.connect(_inputBox.value);",
|
||||||
" setupConnectEventHandlers(connect);",
|
" setupConnectEventHandlers(_connect);",
|
||||||
" inputBox.value = '';",
|
" _inputBox.value = '';",
|
||||||
"}",
|
"}",
|
||||||
''
|
''
|
||||||
].join('\n');
|
].join('\n');
|
||||||
@ -2527,12 +2550,12 @@ Blockly.Blocks['ugj_skyway_called'] = {
|
|||||||
};
|
};
|
||||||
Blockly.JavaScript['ugj_skyway_called'] = function (block) {
|
Blockly.JavaScript['ugj_skyway_called'] = function (block) {
|
||||||
var code = [
|
var code = [
|
||||||
"peer.on('call', call => {",
|
"_peer.on('call', _call => {",
|
||||||
" call.answer(localStream);",
|
" _call.answer(_localStream);",
|
||||||
" setupCallEventHandlers(call);",
|
" _setupCallEventHandlers(_call);",
|
||||||
"});",
|
"});",
|
||||||
"peer.on('connection', connect => {",
|
"_peer.on('connection', _connect => {",
|
||||||
" setupConnectEventHandlers(connect);",
|
" _setupConnectEventHandlers(_connect);",
|
||||||
"});",
|
"});",
|
||||||
''
|
''
|
||||||
].join('\n');
|
].join('\n');
|
||||||
@ -2558,10 +2581,10 @@ Blockly.JavaScript['ugj_skyway_events'] = function (block) {
|
|||||||
var variable_remote_id = Blockly.JavaScript.nameDB_.getName(block.getFieldValue('remote_id'), Blockly.Variables.NAME_TYPE);
|
var variable_remote_id = Blockly.JavaScript.nameDB_.getName(block.getFieldValue('remote_id'), Blockly.Variables.NAME_TYPE);
|
||||||
var statements_do = Blockly.JavaScript.statementToCode(block, 'do');
|
var statements_do = Blockly.JavaScript.statementToCode(block, 'do');
|
||||||
var code = [
|
var code = [
|
||||||
"const setupCallEventHandlers = call => call.on('stream', stream => remoteVideo.srcObject = stream);",
|
"const _setupCallEventHandlers = _call => _call.on('stream', _stream => _remoteVideo.srcObject = _stream);",
|
||||||
"const setupConnectEventHandlers = connect => {",
|
"const _setupConnectEventHandlers = _connect => {",
|
||||||
" inputForm.removeEventListener('submit', onMakeCall);",
|
" _inputForm.removeEventListener('submit', _onMakeCall);",
|
||||||
` ${variable_remote_id} = connect.remoteId;`,
|
` ${variable_remote_id} = _connect.remoteId;`,
|
||||||
statements_do,
|
statements_do,
|
||||||
"}",
|
"}",
|
||||||
''
|
''
|
||||||
@ -2586,8 +2609,8 @@ Blockly.Blocks['ugj_skyway_eventopen'] = {
|
|||||||
Blockly.JavaScript['ugj_skyway_eventopen'] = function (block) {
|
Blockly.JavaScript['ugj_skyway_eventopen'] = function (block) {
|
||||||
var statements_do = Blockly.JavaScript.statementToCode(block, 'do');
|
var statements_do = Blockly.JavaScript.statementToCode(block, 'do');
|
||||||
var code = [
|
var code = [
|
||||||
" connect.on('open', () => {",
|
" _connect.on('open', () => {",
|
||||||
" inputForm.addEventListener('submit', onSendMsg)",
|
" _inputForm.addEventListener('submit', _onSendMsg)",
|
||||||
statements_do,
|
statements_do,
|
||||||
" });",
|
" });",
|
||||||
''
|
''
|
||||||
@ -2615,8 +2638,8 @@ Blockly.JavaScript['ugj_skyway_eventdata'] = function (block) {
|
|||||||
var variable_data = Blockly.JavaScript.nameDB_.getName(block.getFieldValue('data'), Blockly.Variables.NAME_TYPE);
|
var variable_data = Blockly.JavaScript.nameDB_.getName(block.getFieldValue('data'), Blockly.Variables.NAME_TYPE);
|
||||||
var statements_do = Blockly.JavaScript.statementToCode(block, 'do');
|
var statements_do = Blockly.JavaScript.statementToCode(block, 'do');
|
||||||
var code = [
|
var code = [
|
||||||
" connect.on('data', data => {",
|
" _connect.on('data', _data => {",
|
||||||
` ${variable_data} = data;`,
|
` ${variable_data} = _data;`,
|
||||||
statements_do,
|
statements_do,
|
||||||
" });",
|
" });",
|
||||||
''
|
''
|
||||||
@ -2644,10 +2667,10 @@ Blockly.JavaScript['ugj_skyway_eventsend'] = function (block) {
|
|||||||
var variable_data = Blockly.JavaScript.nameDB_.getName(block.getFieldValue('data'), Blockly.Variables.NAME_TYPE);
|
var variable_data = Blockly.JavaScript.nameDB_.getName(block.getFieldValue('data'), Blockly.Variables.NAME_TYPE);
|
||||||
var statements_do = Blockly.JavaScript.statementToCode(block, 'do');
|
var statements_do = Blockly.JavaScript.statementToCode(block, 'do');
|
||||||
var code = [
|
var code = [
|
||||||
" const onSendMsg = () => {",
|
" const _onSendMsg = () => {",
|
||||||
` ${variable_data} = inputBox.value;`,
|
` ${variable_data} = _inputBox.value;`,
|
||||||
` connect.send(${variable_data});`,
|
` _connect.send(${variable_data});`,
|
||||||
" inputBox.value = '';",
|
" _inputBox.value = '';",
|
||||||
statements_do,
|
statements_do,
|
||||||
" }",
|
" }",
|
||||||
''
|
''
|
||||||
@ -2683,9 +2706,9 @@ Blockly.JavaScript['ugj_file_readsync'] = function (block) {
|
|||||||
var dropdown_encoding = block.getFieldValue('encoding');
|
var dropdown_encoding = block.getFieldValue('encoding');
|
||||||
let filepath = ugj_const.doc_root + value_filename.replace(/\'/g, '');
|
let filepath = ugj_const.doc_root + value_filename.replace(/\'/g, '');
|
||||||
Blockly.JavaScript.provideFunction_(
|
Blockly.JavaScript.provideFunction_(
|
||||||
'require_fs', [`const fs = require('fs');`]
|
'require_fs', [`const _fs = require('fs');`]
|
||||||
);
|
);
|
||||||
var code = `fs.readFileSync('${filepath}', '${dropdown_encoding}')`;
|
var code = `_fs.readFileSync('${filepath}', '${dropdown_encoding}')`;
|
||||||
return [code, Blockly.JavaScript.ORDER_ATOMIC];
|
return [code, Blockly.JavaScript.ORDER_ATOMIC];
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -2787,22 +2810,22 @@ Blockly.JavaScript['ugj_event_answer'] = function (block) {
|
|||||||
var statements_do = Blockly.JavaScript.statementToCode(block, 'do');
|
var statements_do = Blockly.JavaScript.statementToCode(block, 'do');
|
||||||
var code = [
|
var code = [
|
||||||
`ugj_fukidashi(${value_question}, 0);`,
|
`ugj_fukidashi(${value_question}, 0);`,
|
||||||
`inputForm = document.getElementById('inputForm');`,
|
`_inputForm = document.getElementById('inputForm');`,
|
||||||
`inputBox = document.getElementById('inputBox');`,
|
`_inputBox = document.getElementById('inputBox');`,
|
||||||
"inputForm.style.display = 'inline-block'",
|
"_inputForm.style.display = 'inline-block'",
|
||||||
"inputBox.focus();",
|
"_inputBox.focus();",
|
||||||
"const inputFunc = async () => { ",
|
"const _inputFunc = async () => { ",
|
||||||
" if (inputBox.value.length > 0) {",
|
" if (_inputBox.value.length > 0) {",
|
||||||
` ${variable_answer} = inputBox.value;`,
|
` ${variable_answer} = _inputBox.value;`,
|
||||||
' inputForm.style.display = "none"',
|
' _inputForm.style.display = "none"',
|
||||||
" inputBox.value = '';",
|
" _inputBox.value = '';",
|
||||||
" document.getElementById('canvas').getContext('2d').clearRect(ugj_fdRecentBox.x,ugj_fdRecentBox.y,ugj_fdRecentBox.w,ugj_fdRecentBox.h);",
|
" document.getElementById('canvas').getContext('2d').clearRect(ugj_fdRecentBox.x,ugj_fdRecentBox.y,ugj_fdRecentBox.w,ugj_fdRecentBox.h);",
|
||||||
statements_do,
|
statements_do,
|
||||||
" console.log('Removing listener...');",
|
" console.log('Removing listener...');",
|
||||||
" inputForm.removeEventListener('submit', inputFunc );",
|
" _inputForm.removeEventListener('submit', _inputFunc );",
|
||||||
" }",
|
" }",
|
||||||
"}",
|
"}",
|
||||||
"inputForm.addEventListener('submit', inputFunc );",
|
"_inputForm.addEventListener('submit', _inputFunc );",
|
||||||
''
|
''
|
||||||
].join('\n');
|
].join('\n');
|
||||||
return code;
|
return code;
|
||||||
@ -2863,14 +2886,14 @@ Blockly.JavaScript['ugj_spawn'] = function (block) {
|
|||||||
var variable_data = Blockly.JavaScript.nameDB_.getName(block.getFieldValue('data'), Blockly.Variables.NAME_TYPE);
|
var variable_data = Blockly.JavaScript.nameDB_.getName(block.getFieldValue('data'), Blockly.Variables.NAME_TYPE);
|
||||||
var statements_do = Blockly.JavaScript.statementToCode(block, 'do');
|
var statements_do = Blockly.JavaScript.statementToCode(block, 'do');
|
||||||
var code = [
|
var code = [
|
||||||
`let child = require('child_process').spawn(${value_childprocess});`,
|
`let _child = require('child_process').spawn(${value_childprocess});`,
|
||||||
`elutil.addChild(child);`,
|
`elutil.addChild(_child);`,
|
||||||
"child.stderr.on('data', data => { console.error(data.toString()) })",
|
"_child.stderr.on('data', _data => { console.error(_data.toString()) })",
|
||||||
"child.stdout.on('data', async data => {",
|
"_child.stdout.on('data', async _data => {",
|
||||||
`${variable_data} = data.toString();`,
|
`${variable_data} = _data.toString();`,
|
||||||
statements_do,
|
statements_do,
|
||||||
"})",
|
"})",
|
||||||
"child.on('close', (code, signal) => { if (code !== 0) { console.error(`process exited with code ${code}, signal ${signal}`)}",
|
"_child.on('close', (_code, _signal) => { if (_code !== 0) { console.error(`process exited with code ${_code}, signal ${_signal}`)}",
|
||||||
"})",
|
"})",
|
||||||
''
|
''
|
||||||
].join("\n");
|
].join("\n");
|
||||||
@ -3114,7 +3137,7 @@ Blockly.JavaScript['ugj_blackboard_write'] = function (block) {
|
|||||||
var dropdown_style = block.getFieldValue('style');
|
var dropdown_style = block.getFieldValue('style');
|
||||||
var dropdown_line = block.getFieldValue('line');
|
var dropdown_line = block.getFieldValue('line');
|
||||||
var funcAppendDivName = Blockly.JavaScript.provideFunction_(
|
var funcAppendDivName = Blockly.JavaScript.provideFunction_(
|
||||||
'appendDiv',
|
'_appendDiv',
|
||||||
['const ' + Blockly.JavaScript.FUNCTION_NAME_PLACEHOLDER_ + ' = termEl => {',
|
['const ' + Blockly.JavaScript.FUNCTION_NAME_PLACEHOLDER_ + ' = termEl => {',
|
||||||
`let el = document.createElement('div');`,
|
`let el = document.createElement('div');`,
|
||||||
`termEl.appendChild(el);`,
|
`termEl.appendChild(el);`,
|
||||||
@ -3122,7 +3145,7 @@ Blockly.JavaScript['ugj_blackboard_write'] = function (block) {
|
|||||||
'}']
|
'}']
|
||||||
);
|
);
|
||||||
var funcTermWriteName = Blockly.JavaScript.provideFunction_(
|
var funcTermWriteName = Blockly.JavaScript.provideFunction_(
|
||||||
'blackboardWrite',
|
'_blackboardWrite',
|
||||||
['const ' + Blockly.JavaScript.FUNCTION_NAME_PLACEHOLDER_ + ' = (text, color, style, line) => {',
|
['const ' + Blockly.JavaScript.FUNCTION_NAME_PLACEHOLDER_ + ' = (text, color, style, line) => {',
|
||||||
`let termEl = document.getElementById('blackboard')`,
|
`let termEl = document.getElementById('blackboard')`,
|
||||||
'let el = null;',
|
'let el = null;',
|
||||||
@ -3217,7 +3240,7 @@ Blockly.Blocks['ugj_sleep'] = {
|
|||||||
Blockly.JavaScript['ugj_sleep'] = function (block) {
|
Blockly.JavaScript['ugj_sleep'] = function (block) {
|
||||||
var value_sec = Blockly.JavaScript.valueToCode(block, 'sec', Blockly.JavaScript.ORDER_ATOMIC);
|
var value_sec = Blockly.JavaScript.valueToCode(block, 'sec', Blockly.JavaScript.ORDER_ATOMIC);
|
||||||
var functionName = Blockly.JavaScript.provideFunction_(
|
var functionName = Blockly.JavaScript.provideFunction_(
|
||||||
'sleep',
|
'_sleep',
|
||||||
['const ' + Blockly.JavaScript.FUNCTION_NAME_PLACEHOLDER_ + ' = sec =>',
|
['const ' + Blockly.JavaScript.FUNCTION_NAME_PLACEHOLDER_ + ' = sec =>',
|
||||||
'new Promise(r => setTimeout(r, sec * 1000));']
|
'new Promise(r => setTimeout(r, sec * 1000));']
|
||||||
);
|
);
|
||||||
@ -3333,7 +3356,7 @@ Blockly.JavaScript['ugj_set_interval'] = function (block) {
|
|||||||
var value_sec = Blockly.JavaScript.valueToCode(block, 'sec', Blockly.JavaScript.ORDER_ATOMIC);
|
var value_sec = Blockly.JavaScript.valueToCode(block, 'sec', Blockly.JavaScript.ORDER_ATOMIC);
|
||||||
var statements_do = Blockly.JavaScript.statementToCode(block, 'do');
|
var statements_do = Blockly.JavaScript.statementToCode(block, 'do');
|
||||||
var code = [
|
var code = [
|
||||||
'let interval = setInterval( async () => {',
|
'let _interval = setInterval( async () => {',
|
||||||
statements_do,
|
statements_do,
|
||||||
`}, ${value_sec}*1000);`,
|
`}, ${value_sec}*1000);`,
|
||||||
''
|
''
|
||||||
@ -3356,7 +3379,7 @@ Blockly.Blocks['ugj_special_clearinterval'] = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
Blockly.JavaScript['ugj_special_clearinterval'] = function (block) {
|
Blockly.JavaScript['ugj_special_clearinterval'] = function (block) {
|
||||||
var code = 'clearInterval(interval);\n';
|
var code = 'clearInterval(_interval);\n';
|
||||||
return code;
|
return code;
|
||||||
};
|
};
|
||||||
/********+********/
|
/********+********/
|
||||||
@ -3383,7 +3406,7 @@ Blockly.Blocks['ugj_set_timeout'] = {
|
|||||||
Blockly.JavaScript['ugj_set_timeout'] = function (block) {
|
Blockly.JavaScript['ugj_set_timeout'] = function (block) {
|
||||||
var value_sec = Blockly.JavaScript.valueToCode(block, 'sec', Blockly.JavaScript.ORDER_ATOMIC);
|
var value_sec = Blockly.JavaScript.valueToCode(block, 'sec', Blockly.JavaScript.ORDER_ATOMIC);
|
||||||
var statements_do = Blockly.JavaScript.statementToCode(block, 'do');
|
var statements_do = Blockly.JavaScript.statementToCode(block, 'do');
|
||||||
var code = `let interval = setTimeout(async () => {\n${statements_do}}, ${value_sec}*1000);\n`;
|
var code = `let _interval = setTimeout(async () => {\n${statements_do}}, ${value_sec}*1000);\n`;
|
||||||
return code;
|
return code;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -3407,12 +3430,12 @@ Blockly.JavaScript['ugj_library_load'] = function (block) {
|
|||||||
var value_lib = Blockly.JavaScript.valueToCode(block, 'lib', Blockly.JavaScript.ORDER_ATOMIC);
|
var value_lib = Blockly.JavaScript.valueToCode(block, 'lib', Blockly.JavaScript.ORDER_ATOMIC);
|
||||||
var statements_do = Blockly.JavaScript.statementToCode(block, 'do');
|
var statements_do = Blockly.JavaScript.statementToCode(block, 'do');
|
||||||
var code = [
|
var code = [
|
||||||
`let scriptEl = document.createElement('script');`,
|
`let _scriptEl = document.createElement('script');`,
|
||||||
`scriptEl.onload = async ev => {`,
|
`_scriptEl.onload = async _ev => {`,
|
||||||
`${statements_do}`,
|
`${statements_do}`,
|
||||||
`};`,
|
`};`,
|
||||||
`scriptEl.src = ${value_lib};`,
|
`_scriptEl.src = ${value_lib};`,
|
||||||
`document.getElementsByTagName('head')[0].appendChild(scriptEl);`,
|
`document.getElementsByTagName('head')[0].appendChild(_scriptEl);`,
|
||||||
''
|
''
|
||||||
].join('\n');
|
].join('\n');
|
||||||
return code;
|
return code;
|
||||||
|
Loading…
Reference in New Issue
Block a user