From ba1fadf4c25857c778860cb37b10232de631dfe4 Mon Sep 17 00:00:00 2001 From: ocogeclub Date: Thu, 9 Sep 2021 23:38:25 +0900 Subject: [PATCH] =?UTF-8?q?i2c=20=E3=83=96=E3=83=AD=E3=83=83=E3=82=AF?= =?UTF-8?q?=E3=81=8C=E7=94=9F=E6=88=90=E3=81=99=E3=82=8B=E3=82=B3=E3=83=BC?= =?UTF-8?q?=E3=83=89=E3=81=8C=E9=96=93=E9=81=95=E3=81=A3=E3=81=A6=E3=81=84?= =?UTF-8?q?=E3=81=9F=E3=81=AE=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.html | 7 +++++++ installer/install.sh | 1 + ugj_blocks.js | 44 ++++++++++++++++++++++++++++++++++++++++---- ugj_script.js | 2 ++ 4 files changed, 50 insertions(+), 4 deletions(-) diff --git a/index.html b/index.html index 6324495..c84cb51 100644 --- a/index.html +++ b/index.html @@ -255,6 +255,13 @@ + + + + 97 + + + diff --git a/installer/install.sh b/installer/install.sh index 9213c8b..fdeb3ad 100644 --- a/installer/install.sh +++ b/installer/install.sh @@ -12,6 +12,7 @@ rm lg.zip cd lg make sudo make install +cd .. # install node.js (=electron node version) via n (https://github.com/tj/n) curl -L https://raw.githubusercontent.com/tj/n/master/bin/n -o n diff --git a/ugj_blocks.js b/ugj_blocks.js index 4bf0879..41043fa 100644 --- a/ugj_blocks.js +++ b/ugj_blocks.js @@ -144,6 +144,38 @@ Blockly.Python['ugj_controls_forEach'] = function (block) { }; /** Additional Basic Blocks********************************************************************************* */ +var ugjCodecharDefinition = { + "type": "ugj_codechar", + "message0": "%{BKY_UGJ_CODECHAR_TITLE}", + "args0": [ + { + "type": "input_value", + "name": "code", + "check": "Number" + } + ], + "inputsInline": true, + "output": "String", + "tooltip": "%{BKY_UGJ_CODECHAR_TOOLTIP}", + "helpUrl": "", + "style": "text_blocks" +}; +Blockly.Blocks['ugj_codechar'] = { + init: function () { + this.jsonInit(ugjCodecharDefinition); + } +}; +Blockly.JavaScript['ugj_codechar'] = function(block) { + var value_code = Blockly.JavaScript.valueToCode(block, 'code', Blockly.JavaScript.ORDER_ATOMIC); + var code = `String.fromCharCode(${value_code})`; + return [code, Blockly.JavaScript.ORDER_NONE]; +}; +Blockly.Python['ugj_codechar'] = function(block) { + var value_code = Blockly.Python.valueToCode(block, 'code', Blockly.Python.ORDER_ATOMIC); + var code = `chr(${value_code})`; + return [code, Blockly.Python.ORDER_NONE]; +}; + var ugjCharcodeDefinition = { "type": "ugj_charcode", "message0": "%{BKY_UGJ_CHARCODE_TITLE}", @@ -812,12 +844,12 @@ Blockly.Blocks['ugj_i2c_write_byte'] = { }; Blockly.JavaScript['ugj_i2c_write_byte'] = function(block) { var value_byte_val = Blockly.JavaScript.valueToCode(block, 'byte_val', Blockly.JavaScript.ORDER_ATOMIC); - var code = `i2c_write_byte(i2c_hand);\n`; + var code = `pi.i2c_write_byte(i2c_hand, ${value_byte_val});\n`; return code; }; Blockly.Python['ugj_i2c_write_byte'] = function(block) { var value_byte_val = Blockly.Python.valueToCode(block, 'byte_val', Blockly.Python.ORDER_ATOMIC); - var code = `i2c_write_byte(i2c_hand);\n`; + var code = `pi.i2c_write_byte(i2c_hand, ${value_byte_val});\n`; return code; }; @@ -839,11 +871,11 @@ Blockly.Blocks['ugj_i2c_read_byte'] = { } }; Blockly.JavaScript['ugj_i2c_read_byte'] = function(block) { - var code = `i2c_read_byte(i2c_hand)`; + var code = `pi.i2c_read_byte(i2c_hand)`; return [code, Blockly.JavaScript.ORDER_NONE]; }; Blockly.Python['ugj_i2c_read_byte'] = function(block) { - var code = `i2c_read_byte(i2c_hand)`; + var code = `pi.i2c_read_byte(i2c_hand)`; return [code, Blockly.Python.ORDER_NONE]; }; @@ -2735,6 +2767,10 @@ Blockly.JavaScript['ugj_text_cr'] = function (block) { var code = "'\\r'"; return [code, Blockly.JavaScript.ORDER_ATOMIC]; }; +Blockly.Python['ugj_text_cr'] = function (block) { + var code = "'\\r'"; + return [code, Blockly.Python.ORDER_ATOMIC]; +}; /*************** */ /** Line Feed ** */ /*************** */ diff --git a/ugj_script.js b/ugj_script.js index 25c7565..0a688f5 100644 --- a/ugj_script.js +++ b/ugj_script.js @@ -114,6 +114,8 @@ Blockly.Msg["I2C_WRITE_BYTE_DATA_TOOLTIP"] = "デバイスの指定されたレ Blockly.Msg["I2C_READ_BYTE_DATA_TITLE"] = "レジスタ %1 の値"; Blockly.Msg["I2C_READ_BYTE_DATA_TOOLTIP"] = "デバイスの指定されたレジスタから1バイトを読み込みます。"; +Blockly.Msg["UGJ_CODECHAR_TITLE"] = "コード %1 の文字"; +Blockly.Msg["UGJ_CODECHAR_TOOLTIP"] = "文字コードを文字に変換します。"; Blockly.Msg["UGJ_CHARCODE_TITLE"] = "%1 の文字コード"; Blockly.Msg["UGJ_CHARCODE_TOOLTIP"] = "入力テキストの1文字目の文字コードを返します。"; Blockly.Msg["UGJ_HEXTODEC_TITLE"] = "0x %1";