mirror of
https://github.com/ocogeclub/ocoge.git
synced 2024-11-24 08:29:48 +00:00
[update] いくつかのクラスの名前を変更
This commit is contained in:
parent
a37760af85
commit
49f3712704
@ -21,9 +21,9 @@ const ugj_const = {
|
|||||||
dev_hash: '4e9205f9b7e571bec1aa52ab7871f420684fcf96149672a4d550a95863d6b072'
|
dev_hash: '4e9205f9b7e571bec1aa52ab7871f420684fcf96149672a4d550a95863d6b072'
|
||||||
}
|
}
|
||||||
|
|
||||||
/** クラス elUtil ****************************************************************** */
|
/** クラス appTool ****************************************************************** */
|
||||||
// Electron 動作用
|
// Electron 動作用
|
||||||
class elUtil {
|
class appTool {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.path = require('path') //window.ocogeapi.path
|
this.path = require('path') //window.ocogeapi.path
|
||||||
this.fs = require('fs') //window.ocogeapi.fs
|
this.fs = require('fs') //window.ocogeapi.fs
|
||||||
@ -316,7 +316,7 @@ class elUtil {
|
|||||||
|
|
||||||
// PyBfm を起動
|
// PyBfm を起動
|
||||||
launchPyBfm() {
|
launchPyBfm() {
|
||||||
let script_path = this.path.join(elutil.library_path, 'pybfm.py');
|
let script_path = this.path.join(apptool.library_path, 'pybfm.py');
|
||||||
require('child_process').spawn('python3', [script_path]);
|
require('child_process').spawn('python3', [script_path]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -327,7 +327,7 @@ class elUtil {
|
|||||||
|
|
||||||
}
|
}
|
||||||
// ブラウザ動作用
|
// ブラウザ動作用
|
||||||
class brUtil {
|
class webTool {
|
||||||
constructor() {
|
constructor() {
|
||||||
// GPIOブロックは使えません
|
// GPIOブロックは使えません
|
||||||
this.gpio_backend = ugj_const.pig;
|
this.gpio_backend = ugj_const.pig;
|
||||||
@ -385,24 +385,24 @@ class brUtil {
|
|||||||
|
|
||||||
// Electron 動作 / ブラウザ動作自動判別
|
// Electron 動作 / ブラウザ動作自動判別
|
||||||
// const is_el = (typeof window.ocogeapi !== 'undefined')
|
// const is_el = (typeof window.ocogeapi !== 'undefined')
|
||||||
const is_el = (typeof require === 'function');
|
const is_app = (typeof require === 'function');
|
||||||
|
|
||||||
// utilクラスのインスタンスを返す
|
// utilクラスのインスタンスを返す
|
||||||
const elUtil_new = () => {
|
const appTool_new = () => {
|
||||||
if (is_el) {
|
if (is_app) {
|
||||||
let el = new elUtil;
|
let ap = new appTool;
|
||||||
el.init();
|
ap.init();
|
||||||
return el;
|
return ap;
|
||||||
}
|
}
|
||||||
else return new brUtil;
|
else return new webTool;
|
||||||
}
|
}
|
||||||
|
|
||||||
// "require" for web browsers if contextIsolation is false && nodeIntegration is true:
|
// "require" for web browsers if contextIsolation is false && nodeIntegration is true:
|
||||||
if (!is_el) {
|
if (!is_app) {
|
||||||
var require = module_name => {
|
var require = module_name => {
|
||||||
let block;
|
let block;
|
||||||
switch (module_name) {
|
switch (module_name) {
|
||||||
case '@tensorflow/tfjs':
|
case '@tensorflow/tfjs-node':
|
||||||
block = 'TensorFlow';
|
block = 'TensorFlow';
|
||||||
break;
|
break;
|
||||||
case '@tensorflow-models/blazeface':
|
case '@tensorflow-models/blazeface':
|
@ -185,7 +185,7 @@ 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('@ocoge.club/` + elutil.gpio_backend + `');`]
|
'require_gpio', [`const _pi = require('@ocoge.club/` + apptool.gpio_backend + `');`]
|
||||||
);
|
);
|
||||||
var code = `await _pi.gpio_open();\n`; //
|
var code = `await _pi.gpio_open();\n`; //
|
||||||
return code;
|
return code;
|
||||||
@ -540,7 +540,7 @@ 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('@ocoge.club/` + elutil.gpio_backend + `');`]
|
'require_gpio', [`const _pi = require('@ocoge.club/` + apptool.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;
|
||||||
@ -680,9 +680,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('@ocoge.club/` + elutil.gpio_backend + `');`]
|
'require_gpio', [`const _pi = require('@ocoge.club/` + apptool.gpio_backend + `');`]
|
||||||
);
|
);
|
||||||
var code = `await _pi.i2c_open(${elutil.i2c_bus}, ${value_i2c_address});\n`;
|
var code = `await _pi.i2c_open(${apptool.i2c_bus}, ${value_i2c_address});\n`;
|
||||||
return code;
|
return code;
|
||||||
};
|
};
|
||||||
Blockly.Python['ugj_i2c_open'] = function (block) {
|
Blockly.Python['ugj_i2c_open'] = function (block) {
|
||||||
@ -1106,8 +1106,8 @@ Blockly.JavaScript['oc_speechcommands_init'] = function (block) {
|
|||||||
let cp = undefined, md = undefined;
|
let cp = undefined, md = undefined;
|
||||||
if (value_custom_model != "''") {
|
if (value_custom_model != "''") {
|
||||||
let cm = value_custom_model.replace(/(^'|'$)/g, '');
|
let cm = value_custom_model.replace(/(^'|'$)/g, '');
|
||||||
cp = `'file://${elutil.path.join(cm, 'model.json')}'`;
|
cp = `'file://${apptool.path.join(cm, 'model.json')}'`;
|
||||||
md = `'file://${elutil.path.join(cm, 'metadata.json')}'`;
|
md = `'file://${apptool.path.join(cm, 'metadata.json')}'`;
|
||||||
}
|
}
|
||||||
var code = `const _checkpointURL = ${cp};
|
var code = `const _checkpointURL = ${cp};
|
||||||
const _metadataURL = ${md};
|
const _metadataURL = ${md};
|
||||||
@ -1262,7 +1262,7 @@ 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 = '${elutil.doc_root}' + ${value_imgfilename};`,
|
`_img.src = '${apptool.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});`,
|
||||||
''
|
''
|
||||||
@ -1739,7 +1739,7 @@ Blockly.Blocks['ugj_library_skyway'] = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
Blockly.JavaScript['ugj_library_skyway'] = function (block) {
|
Blockly.JavaScript['ugj_library_skyway'] = function (block) {
|
||||||
var code = `'${elutil.path.join(elutil.library_path, 'skyway.min.js')}'`;
|
var code = `'${apptool.path.join(apptool.library_path, 'skyway.min.js')}'`;
|
||||||
return [code, Blockly.JavaScript.ORDER_NONE];
|
return [code, Blockly.JavaScript.ORDER_NONE];
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -2044,7 +2044,7 @@ Blockly.Blocks['ugj_file_readsync'] = {
|
|||||||
Blockly.JavaScript['ugj_file_readsync'] = function (block) {
|
Blockly.JavaScript['ugj_file_readsync'] = function (block) {
|
||||||
var value_filename = Blockly.JavaScript.valueToCode(block, 'filename', Blockly.JavaScript.ORDER_ATOMIC);
|
var value_filename = Blockly.JavaScript.valueToCode(block, 'filename', Blockly.JavaScript.ORDER_ATOMIC);
|
||||||
var dropdown_encoding = block.getFieldValue('encoding');
|
var dropdown_encoding = block.getFieldValue('encoding');
|
||||||
let filepath = elutil.path.join(elutil.doc_root, value_filename.replace(/\'/g, ''));
|
let filepath = apptool.path.join(apptool.doc_root, value_filename.replace(/\'/g, ''));
|
||||||
Blockly.JavaScript.provideFunction_(
|
Blockly.JavaScript.provideFunction_(
|
||||||
'require_fs', [`const _fs = require('fs');`]
|
'require_fs', [`const _fs = require('fs');`]
|
||||||
);
|
);
|
||||||
@ -2270,7 +2270,7 @@ Blockly.Blocks['aquestalk_pi'] = {
|
|||||||
};
|
};
|
||||||
Blockly.JavaScript['aquestalk_pi'] = function (block) {
|
Blockly.JavaScript['aquestalk_pi'] = function (block) {
|
||||||
var value_talk = Blockly.JavaScript.valueToCode(block, 'talk', Blockly.JavaScript.ORDER_ATOMIC);
|
var value_talk = Blockly.JavaScript.valueToCode(block, 'talk', Blockly.JavaScript.ORDER_ATOMIC);
|
||||||
var code = `'${elutil.path.join(elutil.executable_path, 'aquestalkpi/AquesTalkPi')} -g 50 ' + ${value_talk} + ' | aplay', { shell: true }`;
|
var code = `'${apptool.path.join(apptool.executable_path, 'aquestalkpi/AquesTalkPi')} -g 50 ' + ${value_talk} + ' | aplay', { shell: true }`;
|
||||||
return [code, Blockly.JavaScript.ORDER_NONE];
|
return [code, Blockly.JavaScript.ORDER_NONE];
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -2292,7 +2292,7 @@ Blockly.Blocks['ugj_child_fswebcam'] = {
|
|||||||
};
|
};
|
||||||
Blockly.JavaScript['ugj_child_fswebcam'] = function (block) {
|
Blockly.JavaScript['ugj_child_fswebcam'] = function (block) {
|
||||||
var value_filename = Blockly.JavaScript.valueToCode(block, 'filename', Blockly.JavaScript.ORDER_ATOMIC);
|
var value_filename = Blockly.JavaScript.valueToCode(block, 'filename', Blockly.JavaScript.ORDER_ATOMIC);
|
||||||
var code = `'fswebcam', ['-r', '480x360', '${elutil.doc_root}' + ${value_filename}]`;
|
var code = `'fswebcam', ['-r', '480x360', '${apptool.doc_root}' + ${value_filename}]`;
|
||||||
return [code, Blockly.JavaScript.ORDER_NONE];
|
return [code, Blockly.JavaScript.ORDER_NONE];
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -2310,7 +2310,7 @@ Blockly.Blocks['ugj_child_julius'] = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
Blockly.JavaScript['ugj_child_julius'] = function (block) {
|
Blockly.JavaScript['ugj_child_julius'] = function (block) {
|
||||||
var code = `'${elutil.path.join(elutil.executable_path, 'julius/julius-simple')}', ['-C', '${elutil.path.join(elutil.executable_path, 'julius/dictation-kit/am-gmm.jconf')}', '-gram', '${elutil.path.join(elutil.executable_path, 'julius/dic/assistant')}', '-nostrip']`;
|
var code = `'${apptool.path.join(apptool.executable_path, 'julius/julius-simple')}', ['-C', '${apptool.path.join(apptool.executable_path, 'julius/dictation-kit/am-gmm.jconf')}', '-gram', '${apptool.path.join(apptool.executable_path, 'julius/dic/assistant')}', '-nostrip']`;
|
||||||
return [code, Blockly.JavaScript.ORDER_NONE];
|
return [code, Blockly.JavaScript.ORDER_NONE];
|
||||||
};
|
};
|
||||||
// irrp.py - pigpioによる赤外線リモコンの学習
|
// irrp.py - pigpioによる赤外線リモコンの学習
|
||||||
@ -2331,7 +2331,7 @@ Blockly.Blocks['ugj_child_irrecord'] = {
|
|||||||
};
|
};
|
||||||
Blockly.JavaScript['ugj_child_irrecord'] = function (block) {
|
Blockly.JavaScript['ugj_child_irrecord'] = 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 = `'python3', ['${elutil.path.join(elutil.library_path, 'irrp.py')}', '-r', '-g', '${value_gpio}', 'signal', '--post', '130']`;
|
var code = `'python3', ['${apptool.path.join(apptool.library_path, 'irrp.py')}', '-r', '-g', '${value_gpio}', 'signal', '--post', '130']`;
|
||||||
return [code, Blockly.JavaScript.ORDER_NONE];
|
return [code, Blockly.JavaScript.ORDER_NONE];
|
||||||
};
|
};
|
||||||
// 送信
|
// 送信
|
||||||
@ -2356,7 +2356,7 @@ Blockly.Blocks['ugj_child_irplayback'] = {
|
|||||||
Blockly.JavaScript['ugj_child_irplayback'] = function (block) {
|
Blockly.JavaScript['ugj_child_irplayback'] = 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_signal = Blockly.JavaScript.valueToCode(block, 'signal', Blockly.JavaScript.ORDER_ATOMIC);//.replace('{','\\{').replace('}','\\}').replace(/"/g,'\\"').replace(/ /g,'\\ ')
|
var value_signal = Blockly.JavaScript.valueToCode(block, 'signal', Blockly.JavaScript.ORDER_ATOMIC);//.replace('{','\\{').replace('}','\\}').replace(/"/g,'\\"').replace(/ /g,'\\ ')
|
||||||
var code = `'python3', ['${elutil.path.join(elutil.library_path, 'irrp.py')}', '-p', '-g', '${value_gpio}', '--irdata', ${value_signal}, 'signal']`;
|
var code = `'python3', ['${apptool.path.join(apptool.library_path, 'irrp.py')}', '-p', '-g', '${value_gpio}', '--irdata', ${value_signal}, 'signal']`;
|
||||||
return [code, Blockly.JavaScript.ORDER_NONE];
|
return [code, Blockly.JavaScript.ORDER_NONE];
|
||||||
};
|
};
|
||||||
// ハッシュ生成
|
// ハッシュ生成
|
||||||
@ -2378,7 +2378,7 @@ Blockly.Blocks['ugj_child_irrcvr'] = {
|
|||||||
Blockly.JavaScript['ugj_child_irrcvr'] = function (block) {
|
Blockly.JavaScript['ugj_child_irrcvr'] = 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 = `'python3', ['./scripts/irrcvr.py', '-g', '${value_gpio}']`;
|
// var code = `'python3', ['./scripts/irrcvr.py', '-g', '${value_gpio}']`;
|
||||||
var code = `'${elutil.path.join(elutil.executable_path, 'ir_hash/ir_hash')}', ['${value_gpio}']`;
|
var code = `'${apptool.path.join(apptool.executable_path, 'ir_hash/ir_hash')}', ['${value_gpio}']`;
|
||||||
return [code, Blockly.JavaScript.ORDER_NONE];
|
return [code, Blockly.JavaScript.ORDER_NONE];
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -2398,7 +2398,7 @@ Blockly.Blocks['ugj_child_pyscript'] = {
|
|||||||
Blockly.JavaScript['ugj_child_pyscript'] = function (block) {
|
Blockly.JavaScript['ugj_child_pyscript'] = function (block) {
|
||||||
var value_script_path = Blockly.JavaScript.valueToCode(block, 'script_path', Blockly.JavaScript.ORDER_ATOMIC);
|
var value_script_path = Blockly.JavaScript.valueToCode(block, 'script_path', Blockly.JavaScript.ORDER_ATOMIC);
|
||||||
// TODO: Assemble JavaScript into code variable.
|
// TODO: Assemble JavaScript into code variable.
|
||||||
var code = `'python3', ['${elutil.doc_root}/' + ${value_script_path}]`;
|
var code = `'python3', ['${apptool.doc_root}/' + ${value_script_path}]`;
|
||||||
// TODO: Change ORDER_NONE to the correct strength.
|
// TODO: Change ORDER_NONE to the correct strength.
|
||||||
return [code, Blockly.JavaScript.ORDER_NONE];
|
return [code, Blockly.JavaScript.ORDER_NONE];
|
||||||
};
|
};
|
||||||
|
@ -59,13 +59,13 @@ Blockly.Blocks['ugj_grideye_init'] = {
|
|||||||
Blockly.JavaScript['ugj_grideye_init'] = function (block) {
|
Blockly.JavaScript['ugj_grideye_init'] = function (block) {
|
||||||
var dropdown_addr = block.getFieldValue('addr');
|
var dropdown_addr = block.getFieldValue('addr');
|
||||||
Blockly.JavaScript.provideFunction_(
|
Blockly.JavaScript.provideFunction_(
|
||||||
'require_gpio', [`const _pi = require('@ocoge.club/` + elutil.gpio_backend + `');`]
|
'require_gpio', [`const _pi = require('@ocoge.club/` + apptool.gpio_backend + `');`]
|
||||||
);
|
);
|
||||||
let modpath = elutil.path.join(elutil.blocks_sensors_dir, 'amg8833', 'AMG8833x.js');
|
let modpath = apptool.path.join(apptool.blocks_sensors_dir, 'amg8833', 'AMG8833x.js');
|
||||||
Blockly.JavaScript.provideFunction_(
|
Blockly.JavaScript.provideFunction_(
|
||||||
'require_amg8833', [`const _amg8833 = require('${modpath}');`]
|
'require_amg8833', [`const _amg8833 = require('${modpath}');`]
|
||||||
);
|
);
|
||||||
var code = `await _amg8833.init(${elutil.i2c_bus}, ${dropdown_addr}, window.addEventListener);\n`;
|
var code = `await _amg8833.init(${apptool.i2c_bus}, ${dropdown_addr}, window.addEventListener);\n`;
|
||||||
return code;//
|
return code;//
|
||||||
};
|
};
|
||||||
/********************** */
|
/********************** */
|
||||||
|
@ -18,14 +18,14 @@ Blockly.Blocks['ugj_bme280'] = {
|
|||||||
Blockly.JavaScript['ugj_bme280'] = function (block) {
|
Blockly.JavaScript['ugj_bme280'] = function (block) {
|
||||||
var dropdown_addr = block.getFieldValue('addr');
|
var dropdown_addr = block.getFieldValue('addr');
|
||||||
Blockly.JavaScript.provideFunction_(
|
Blockly.JavaScript.provideFunction_(
|
||||||
'require_gpio', [`const _pi = require('@ocoge.club/` + elutil.gpio_backend + `');`]
|
'require_gpio', [`const _pi = require('@ocoge.club/` + apptool.gpio_backend + `');`]
|
||||||
);
|
);
|
||||||
let modpath = elutil.path.join(elutil.blocks_sensors_dir, 'bme280', 'BME280x.js');
|
let modpath = apptool.path.join(apptool.blocks_sensors_dir, 'bme280', 'BME280x.js');
|
||||||
Blockly.JavaScript.provideFunction_(
|
Blockly.JavaScript.provideFunction_(
|
||||||
'require_bme280', [`const _bme280 = require('${modpath}');`]
|
'require_bme280', [`const _bme280 = require('${modpath}');`]
|
||||||
);
|
);
|
||||||
var code = `const options = {
|
var code = `const options = {
|
||||||
i2cBusNo: ${elutil.i2c_bus},
|
i2cBusNo: ${apptool.i2c_bus},
|
||||||
i2cAddress: ${dropdown_addr}
|
i2cAddress: ${dropdown_addr}
|
||||||
};
|
};
|
||||||
await _bme280.init(options);
|
await _bme280.init(options);
|
||||||
|
@ -15,7 +15,7 @@ Blockly.Blocks['ugj_dht11'] = {
|
|||||||
};
|
};
|
||||||
Blockly.JavaScript['ugj_dht11'] = function (block) {
|
Blockly.JavaScript['ugj_dht11'] = function (block) {
|
||||||
var value_pin = Blockly.JavaScript.valueToCode(block, 'pin', Blockly.JavaScript.ORDER_ATOMIC);
|
var value_pin = Blockly.JavaScript.valueToCode(block, 'pin', Blockly.JavaScript.ORDER_ATOMIC);
|
||||||
let pypath = elutil.path.join(elutil.blocks_sensors_dir, 'dht11', 'dht11.py');
|
let pypath = apptool.path.join(apptool.blocks_sensors_dir, 'dht11', 'dht11.py');
|
||||||
var code = `let _th = require('child_process').spawnSync('python3', ['${pypath}', '${value_pin}'], {timeout: 5000}).stdout.toString();
|
var code = `let _th = require('child_process').spawnSync('python3', ['${pypath}', '${value_pin}'], {timeout: 5000}).stdout.toString();
|
||||||
let _dhtdata = JSON.parse(_th);`;
|
let _dhtdata = JSON.parse(_th);`;
|
||||||
// let _dht11data[0] =
|
// let _dht11data[0] =
|
||||||
|
@ -33,13 +33,13 @@ 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_gpio', [`const _pi = require('@ocoge.club/` + elutil.gpio_backend + `');`]
|
'require_gpio', [`const _pi = require('@ocoge.club/` + apptool.gpio_backend + `');`]
|
||||||
);
|
);
|
||||||
let modpath = elutil.path.join(elutil.blocks_sensors_dir, 'paj7620', 'PAJ7620x.js');
|
let modpath = apptool.path.join(apptool.blocks_sensors_dir, 'paj7620', 'PAJ7620x.js');
|
||||||
Blockly.JavaScript.provideFunction_(
|
Blockly.JavaScript.provideFunction_(
|
||||||
'require_paj7620', [`const _paj7620 = require('${modpath}');`]
|
'require_paj7620', [`const _paj7620 = require('${modpath}');`]
|
||||||
);
|
);
|
||||||
var code = `await _paj7620.init(${elutil.i2c_bus}, ${value_i2c_addr}, window.addEventListener);
|
var code = `await _paj7620.init(${apptool.i2c_bus}, ${value_i2c_addr}, window.addEventListener);
|
||||||
`;
|
`;
|
||||||
return code;
|
return code;
|
||||||
};
|
};
|
||||||
|
@ -1044,7 +1044,7 @@
|
|||||||
<script src="./node_modules/@blockly/field-slider/dist/index.js"></script>
|
<script src="./node_modules/@blockly/field-slider/dist/index.js"></script>
|
||||||
<script src="./lib/custom-dialog.js"></script>
|
<script src="./lib/custom-dialog.js"></script>
|
||||||
<script src="./blocks/blocks.js"></script>
|
<script src="./blocks/blocks.js"></script>
|
||||||
<script src="./apptools.js"></script>
|
<script src="./apptool.js"></script>
|
||||||
<script src="./index.js"></script>
|
<script src="./index.js"></script>
|
||||||
<script src="./node_modules/js-beautify/js/lib/beautify.js"></script>
|
<script src="./node_modules/js-beautify/js/lib/beautify.js"></script>
|
||||||
<script src="./node_modules/prismjs/prism.js"></script>
|
<script src="./node_modules/prismjs/prism.js"></script>
|
||||||
|
50
index.js
50
index.js
@ -2,12 +2,12 @@
|
|||||||
|
|
||||||
const { checkPrimeSync } = require('crypto');
|
const { checkPrimeSync } = require('crypto');
|
||||||
|
|
||||||
let elutil = elUtil_new();
|
let apptool = appTool_new();
|
||||||
|
|
||||||
|
|
||||||
const testfunc = async () => {
|
const testfunc = async () => {
|
||||||
elutil.openURL('http://ocoge.club');
|
apptool.openURL('http://ocoge.club');
|
||||||
// console.log(elutil.app_path);
|
// console.log(apptool.app_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
//============ User Customize Start ===============
|
//============ User Customize Start ===============
|
||||||
@ -258,10 +258,10 @@ let ugj_sounds = (names => { // サウンドファイルのいろいろの配列
|
|||||||
|
|
||||||
// マスコット選択
|
// マスコット選択
|
||||||
const ugj_selectMascot = async () => {
|
const ugj_selectMascot = async () => {
|
||||||
let fname = await elutil.selectMascotFile();
|
let fname = await apptool.selectMascotFile();
|
||||||
if (fname) {
|
if (fname) {
|
||||||
ugj_canvasBgImg(fname, -1, -1);
|
ugj_canvasBgImg(fname, -1, -1);
|
||||||
elutil.setMascotFilePath(fname);
|
apptool.setMascotFilePath(fname);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -289,7 +289,7 @@ const ugj_newWorkspace = () => {
|
|||||||
ugj_confirm('新規ワークスペース', '保存していない内容はすべて破棄されます。よろしいですか?', okey => {
|
ugj_confirm('新規ワークスペース', '保存していない内容はすべて破棄されます。よろしいですか?', okey => {
|
||||||
if (okey) {
|
if (okey) {
|
||||||
workspace.clear();
|
workspace.clear();
|
||||||
elutil.newFile();
|
apptool.newFile();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -298,12 +298,12 @@ const ugj_newWorkspace = () => {
|
|||||||
const ugj_saveWorkspaceToFile = async () => {
|
const ugj_saveWorkspaceToFile = async () => {
|
||||||
let xml = Blockly.Xml.workspaceToDom(workspace);
|
let xml = Blockly.Xml.workspaceToDom(workspace);
|
||||||
let xml_text = Blockly.Xml.domToText(xml);
|
let xml_text = Blockly.Xml.domToText(xml);
|
||||||
if (await elutil.saveWsFile(xml_text) === false) {
|
if (await apptool.saveWsFile(xml_text) === false) {
|
||||||
window.alert('保存できませんでした。');
|
window.alert('保存できませんでした。');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const ugj_loadWorkspaceFromFile = async () => {
|
const ugj_loadWorkspaceFromFile = async () => {
|
||||||
let xml_text = await elutil.loadWsFile();
|
let xml_text = await apptool.loadWsFile();
|
||||||
if (xml_text.length > 0) {
|
if (xml_text.length > 0) {
|
||||||
let xml = Blockly.Xml.textToDom(xml_text);
|
let xml = Blockly.Xml.textToDom(xml_text);
|
||||||
Blockly.Xml.domToWorkspace(xml, workspace);
|
Blockly.Xml.domToWorkspace(xml, workspace);
|
||||||
@ -312,7 +312,7 @@ const ugj_loadWorkspaceFromFile = async () => {
|
|||||||
|
|
||||||
// ワークスペースを別名で保存
|
// ワークスペースを別名で保存
|
||||||
const ugj_saveWorkspaceAs = () => {
|
const ugj_saveWorkspaceAs = () => {
|
||||||
elutil.newFile();
|
apptool.newFile();
|
||||||
ugj_saveWorkspaceToFile();
|
ugj_saveWorkspaceToFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -337,7 +337,7 @@ const ugj_loadWorkspace = () => {
|
|||||||
// コード生成
|
// コード生成
|
||||||
const ugj_generateCode = () => {
|
const ugj_generateCode = () => {
|
||||||
let code;
|
let code;
|
||||||
if (elutil.lang == 'py') { // Python コード出力
|
if (apptool.lang == 'py') { // Python コード出力
|
||||||
try {
|
try {
|
||||||
code = Blockly.Python.workspaceToCode(workspace);
|
code = Blockly.Python.workspaceToCode(workspace);
|
||||||
} catch (e) { // Pythonコードを持たないブロックがある場合
|
} catch (e) { // Pythonコードを持たないブロックがある場合
|
||||||
@ -372,7 +372,7 @@ const ugj_pyBeautify = (code) => {
|
|||||||
|
|
||||||
// コードフォーマッティング
|
// コードフォーマッティング
|
||||||
const ugj_formatCode = code => {
|
const ugj_formatCode = code => {
|
||||||
if (elutil.lang == 'py') // フォーマッティング
|
if (apptool.lang == 'py') // フォーマッティング
|
||||||
code = ugj_pyBeautify(code);
|
code = ugj_pyBeautify(code);
|
||||||
else
|
else
|
||||||
code = js_beautify(code, { indent_size: 2 });
|
code = js_beautify(code, { indent_size: 2 });
|
||||||
@ -385,12 +385,12 @@ const ugj_runCode = async () => {
|
|||||||
let btnel = document.getElementById('runbtn');
|
let btnel = document.getElementById('runbtn');
|
||||||
btnel.disabled = true;
|
btnel.disabled = true;
|
||||||
let code = ugj_generateCode();
|
let code = ugj_generateCode();
|
||||||
if (elutil.lang == 'js') {
|
if (apptool.lang == 'js') {
|
||||||
let AsyncFunction = Object.getPrototypeOf(async function () { }).constructor
|
let AsyncFunction = Object.getPrototypeOf(async function () { }).constructor
|
||||||
let ocogeFunc = new AsyncFunction(code);
|
let ocogeFunc = new AsyncFunction(code);
|
||||||
await ocogeFunc().catch(e => { window.alert(e); });
|
await ocogeFunc().catch(e => { window.alert(e); });
|
||||||
console.log('Code Execution done.');
|
console.log('Code Execution done.');
|
||||||
} else if (elutil.lang == 'py') {
|
} else if (apptool.lang == 'py') {
|
||||||
if (code) ugj_spawnPyboard(code, 'r');
|
if (code) ugj_spawnPyboard(code, 'r');
|
||||||
}
|
}
|
||||||
btnel.disabled = false;
|
btnel.disabled = false;
|
||||||
@ -398,7 +398,7 @@ const ugj_runCode = async () => {
|
|||||||
|
|
||||||
// Pyboard ocoge
|
// Pyboard ocoge
|
||||||
const ugj_spawnPyboard = (code, mode) => {
|
const ugj_spawnPyboard = (code, mode) => {
|
||||||
let script_path = elutil.path.join(elutil.library_path, 'pybtool.py');
|
let script_path = apptool.path.join(apptool.library_path, 'pybtool.py');
|
||||||
let p = require('child_process').spawn('python3', [script_path, mode], { env: { "PYTHONUTF8": "1" } });
|
let p = require('child_process').spawn('python3', [script_path, mode], { env: { "PYTHONUTF8": "1" } });
|
||||||
p.stdin.write(code);
|
p.stdin.write(code);
|
||||||
p.stdin.end();
|
p.stdin.end();
|
||||||
@ -420,14 +420,14 @@ const ugj_showCode = () => {
|
|||||||
let code = ugj_generateCode(); // コード生成
|
let code = ugj_generateCode(); // コード生成
|
||||||
|
|
||||||
content.innerHTML = ugj_htmlEntities(ugj_formatCode(code));
|
content.innerHTML = ugj_htmlEntities(ugj_formatCode(code));
|
||||||
if (elutil.lang == 'py') content.setAttribute('class', 'language-python');
|
if (apptool.lang == 'py') content.setAttribute('class', 'language-python');
|
||||||
else content.setAttribute('class', 'language-javascript');
|
else content.setAttribute('class', 'language-javascript');
|
||||||
Prism.highlightElement(content);
|
Prism.highlightElement(content);
|
||||||
|
|
||||||
dialog.showModal();
|
dialog.showModal();
|
||||||
|
|
||||||
const save_to_file = code => {
|
const save_to_file = code => {
|
||||||
if (elutil.saveFile(code, elutil.lang) === false) window.alert('保存できませんでした。');
|
if (apptool.saveFile(code, apptool.lang) === false) window.alert('保存できませんでした。');
|
||||||
}
|
}
|
||||||
|
|
||||||
const close_cb = () => {
|
const close_cb = () => {
|
||||||
@ -437,7 +437,7 @@ const ugj_showCode = () => {
|
|||||||
document.removeEventListener('keyup', keyev_cb);
|
document.removeEventListener('keyup', keyev_cb);
|
||||||
}
|
}
|
||||||
const export_cb = () => {
|
const export_cb = () => {
|
||||||
if (elutil.lang == 'js') {
|
if (apptool.lang == 'js') {
|
||||||
save_to_file(ugj_formatCode(ugj_asyncIife(code)));
|
save_to_file(ugj_formatCode(ugj_asyncIife(code)));
|
||||||
} else {
|
} else {
|
||||||
ugj_spawnPyboard(ugj_formatCode(code), 'd');
|
ugj_spawnPyboard(ugj_formatCode(code), 'd');
|
||||||
@ -446,12 +446,12 @@ const ugj_showCode = () => {
|
|||||||
}
|
}
|
||||||
const keyev_cb = ev => {
|
const keyev_cb = ev => {
|
||||||
if (ev.key == 's' && ev.ctrlKey) {
|
if (ev.key == 's' && ev.ctrlKey) {
|
||||||
if (elutil.lang == 'js') {
|
if (apptool.lang == 'js') {
|
||||||
// JS-CLI モード
|
// JS-CLI モード
|
||||||
// blackboardWrite()とwindow.alert()、fukidashi()をconsole.log()に書き換え、
|
// blackboardWrite()とwindow.alert()、fukidashi()をconsole.log()に書き換え、
|
||||||
// document... と ugj_... と elutil... をコメントアウト(ブラウザ関連部分の追放という意味では不完全なので注意)
|
// document... と ugj_... と apptool... をコメントアウト(ブラウザ関連部分の追放という意味では不完全なので注意)
|
||||||
// あと正規表現もいい加減
|
// あと正規表現もいい加減
|
||||||
code = code.replace(/const appendDiv[^#]*\/\/#/gm, 'const blackboardWrite = text => console.log(text);').replace('window.alert', 'console.log').replace(/_fukidashi(.*), \d+(\);)/gm, 'console.log$1$2').replace(/(^(?=.*document.)[^;]*;)/gm, '/* $1 */').replace(/(^(?=.*ugj_)[^;]*;)/gm, '/* $1 */').replace(/(^(?=.*elutil.)[^;]*;)/gm, '/* $1 */');
|
code = code.replace(/const appendDiv[^#]*\/\/#/gm, 'const blackboardWrite = text => console.log(text);').replace('window.alert', 'console.log').replace(/_fukidashi(.*), \d+(\);)/gm, 'console.log$1$2').replace(/(^(?=.*document.)[^;]*;)/gm, '/* $1 */').replace(/(^(?=.*ugj_)[^;]*;)/gm, '/* $1 */').replace(/(^(?=.*apptool.)[^;]*;)/gm, '/* $1 */');
|
||||||
}
|
}
|
||||||
save_to_file(ugj_formatCode(ugj_asyncIife(code)));
|
save_to_file(ugj_formatCode(ugj_asyncIife(code)));
|
||||||
close_cb();
|
close_cb();
|
||||||
@ -623,7 +623,7 @@ Blockly.svgResize(workspace);
|
|||||||
// ワークスペースの未保存の変更のフラグ
|
// ワークスペースの未保存の変更のフラグ
|
||||||
const ugj_wsUpdateCB = event => {
|
const ugj_wsUpdateCB = event => {
|
||||||
if (event.type != Blockly.Events.UI) {
|
if (event.type != Blockly.Events.UI) {
|
||||||
elutil.setWsChanged(true);
|
apptool.setWsChanged(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -648,17 +648,17 @@ window.onload = () => {
|
|||||||
|
|
||||||
// ワークスペースといくつかの環境のオートリストア
|
// ワークスペースといくつかの環境のオートリストア
|
||||||
ugj_loadWorkspace();
|
ugj_loadWorkspace();
|
||||||
elutil.loadPrefsFromLS();
|
apptool.loadPrefsFromLS();
|
||||||
setTimeout(() => { // 環境設定のロードが終わってからイベントリスナを作成
|
setTimeout(() => { // 環境設定のロードが終わってからイベントリスナを作成
|
||||||
workspace.addChangeListener(ugj_wsUpdateCB);
|
workspace.addChangeListener(ugj_wsUpdateCB);
|
||||||
}, 100);
|
}, 100);
|
||||||
// 背景canvas
|
// 背景canvas
|
||||||
ugj_canvasBgImg(elutil.getMascotFilePath(), -1, -1);
|
ugj_canvasBgImg(apptool.getMascotFilePath(), -1, -1);
|
||||||
}
|
}
|
||||||
window.addEventListener('beforeunload', () => {
|
window.addEventListener('beforeunload', () => {
|
||||||
// window.onbeforeunload = () => {
|
// window.onbeforeunload = () => {
|
||||||
ugj_saveWorkspace();
|
ugj_saveWorkspace();
|
||||||
elutil.savePrefsToLS();
|
apptool.savePrefsToLS();
|
||||||
elutil.cleanupGPIO();
|
apptool.cleanupGPIO();
|
||||||
// }
|
// }
|
||||||
});
|
});
|
||||||
|
10
main.js
10
main.js
@ -166,7 +166,7 @@ let template = [
|
|||||||
click: (item, focusedWindow) => {
|
click: (item, focusedWindow) => {
|
||||||
if (focusedWindow) {
|
if (focusedWindow) {
|
||||||
toggleCheck_i2c("i2c-1");
|
toggleCheck_i2c("i2c-1");
|
||||||
focusedWindow.webContents.executeJavaScript('elutil.setI2cbusNo("1")');
|
focusedWindow.webContents.executeJavaScript('apptool.setI2cbusNo("1")');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -177,7 +177,7 @@ let template = [
|
|||||||
click: (item, focusedWindow) => {
|
click: (item, focusedWindow) => {
|
||||||
if (focusedWindow) {
|
if (focusedWindow) {
|
||||||
toggleCheck_i2c("i2c-6");
|
toggleCheck_i2c("i2c-6");
|
||||||
focusedWindow.webContents.executeJavaScript('elutil.setI2cbusNo("6")');
|
focusedWindow.webContents.executeJavaScript('apptool.setI2cbusNo("6")');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -196,7 +196,7 @@ let template = [
|
|||||||
if (focusedWindow) {
|
if (focusedWindow) {
|
||||||
// menu.getMenuItemById('py').checked = false;
|
// menu.getMenuItemById('py').checked = false;
|
||||||
toggleCheck_lang("js");
|
toggleCheck_lang("js");
|
||||||
focusedWindow.webContents.executeJavaScript('elutil.setLang("js")');
|
focusedWindow.webContents.executeJavaScript('apptool.setLang("js")');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -208,7 +208,7 @@ let template = [
|
|||||||
if (focusedWindow) {
|
if (focusedWindow) {
|
||||||
// menu.getMenuItemById('js').checked = false;
|
// menu.getMenuItemById('js').checked = false;
|
||||||
toggleCheck_lang("py");
|
toggleCheck_lang("py");
|
||||||
focusedWindow.webContents.executeJavaScript('elutil.setLang("py")');
|
focusedWindow.webContents.executeJavaScript('apptool.setLang("py")');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -224,7 +224,7 @@ let template = [
|
|||||||
{
|
{
|
||||||
label: "Launch PyBfm",
|
label: "Launch PyBfm",
|
||||||
click: (item, focusedWindow) => {
|
click: (item, focusedWindow) => {
|
||||||
focusedWindow.webContents.executeJavaScript('elutil.launchPyBfm()');
|
focusedWindow.webContents.executeJavaScript('apptool.launchPyBfm()');
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "ocoge",
|
"name": "ocoge",
|
||||||
"version": "0.1.9",
|
"version": "0.1.10",
|
||||||
"description": "ブロックベースビジュアルプログラム開発・実行環境",
|
"description": "ブロックベースビジュアルプログラム開発・実行環境",
|
||||||
"main": "main.js",
|
"main": "main.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@ -62,4 +62,4 @@
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user