diff --git a/2021-07-07-21-48-14.js b/2021-07-07-21-48-14.js deleted file mode 100644 index 9502a56..0000000 --- a/2021-07-07-21-48-14.js +++ /dev/null @@ -1,10 +0,0 @@ -(async () => { - var _E7_95_AA_E5_8F_B7; - - - for (_E7_95_AA_E5_8F_B7 = 3; _E7_95_AA_E5_8F_B7 >= 1; _E7_95_AA_E5_8F_B7 -= 1) { - console.log(_E7_95_AA_E5_8F_B7); - - } - -})(); \ No newline at end of file diff --git a/index.html b/index.html index da642e5..f9397c8 100644 --- a/index.html +++ b/index.html @@ -290,9 +290,9 @@ - - - + + + 5 @@ -300,19 +300,15 @@ - + 5 - - - 1 - - + 1 - - pi.PUD_DOWN + + pi.SET_PULL_DOWN 6 @@ -327,27 +323,24 @@ - - 50 + 5 - - - + - 0 + 50 - + - 5 + 30 - + 12 @@ -360,7 +353,7 @@ - + 9600 @@ -368,7 +361,8 @@ - + + 1 @@ -391,27 +385,27 @@ - - + + 0 - - + + 0 - + 0 - + 0 @@ -420,12 +414,6 @@ - - - - - 1 - @@ -599,14 +587,6 @@ - - - - - 192.168.0.229 - - - diff --git a/installer/install.sh b/installer/install.sh index 8e6dcfa..c61af0d 100644 --- a/installer/install.sh +++ b/installer/install.sh @@ -4,10 +4,8 @@ # install node.js (=electron node version) via n (https://github.com/tj/n) curl -L https://raw.githubusercontent.com/tj/n/master/bin/n -o n sudo bash n 14.16.0 -# Install latest version of n via npm globally -# sudo npm install -g n # install python code formatter -python3 -m pip install yapf +python3 -m pip install black # install desktop entry cp -r ./files/share ~/.local/ # install binary files if exists @@ -19,8 +17,8 @@ else fi # build ocoge -# prepare for installation electron -echo 'arch=armv7l' > ~/.npmrc +# uncomment if electron will be installed on RPi OS +# echo 'arch=armv7l' > ~/.npmrc cd .. npm install diff --git a/local_modules/ocoge_pigpiod/binding.gyp b/local_modules/ocoge_lgpio/binding.gyp similarity index 62% rename from local_modules/ocoge_pigpiod/binding.gyp rename to local_modules/ocoge_lgpio/binding.gyp index fe79d75..1d66252 100644 --- a/local_modules/ocoge_pigpiod/binding.gyp +++ b/local_modules/ocoge_lgpio/binding.gyp @@ -1,10 +1,10 @@ { "targets": - [ { "target_name" : "ocoge_pigpiod" - , "sources" : [ "ocoge_pigpiod.cpp" ] + [ { "target_name" : "ocoge_lgpio" + , "sources" : [ "ocoge_lgpio.cpp" ] , "defines" : [ "NAPI_DISABLE_CPP_EXCEPTIONS" ] , "include_dirs" : [ " -#include +#include #include #include using namespace Napi; -int pi = 0; - -Value Usleep(const CallbackInfo& info) +// gpiochipデバイスを開く +Value gpiochipOpen(const CallbackInfo& info) { Env env = info.Env(); if (info.Length() < 1) @@ -24,78 +23,12 @@ Value Usleep(const CallbackInfo& info) TypeError::New(env, "Wrong arguments").ThrowAsJavaScriptException(); return env.Null(); } - - usleep(info[0].As().DoubleValue()); - - return env.Null(); + unsigned int gpioDev = info[0].As().DoubleValue(); + return Number::New(env, lgGpiochipOpen(gpioDev)); } - -// pigpio 初期化 -Value Start(const CallbackInfo& info) -{ - Env env = info.Env(); - pi = pigpio_start(0, 0); - return env.Null(); -} -// リモート -Value StartRemote(const CallbackInfo& info) -{ - Env env = info.Env(); - if (info.Length() < 2) - { - TypeError::New(env, "Wrong number of arguments") - .ThrowAsJavaScriptException(); - return env.Null(); - } - if (!info[0].IsString() || !info[1].IsString()) - { - TypeError::New(env, "Wrong arguments").ThrowAsJavaScriptException(); - return env.Null(); - } - - std::string addrStr = info[0].As().Utf8Value(); - std::string portStr = info[1].As().Utf8Value(); - - pi = pigpio_start(&addrStr[0], &portStr[0]); - - return env.Null(); -} - -// pigpio 後始末 -Value Stop(const CallbackInfo& info) -{ - Env env = info.Env(); - pigpio_stop(pi); - return env.Null(); -} - -// GPIO 端子のモードを設定 -Value SetMode(const CallbackInfo& info) -{ - Env env = info.Env(); - if (info.Length() < 2) - { - TypeError::New(env, "Wrong number of arguments") - .ThrowAsJavaScriptException(); - return env.Null(); - } - if (!info[0].IsNumber() || !info[1].IsNumber()) - { - TypeError::New(env, "Wrong arguments").ThrowAsJavaScriptException(); - return env.Null(); - } - - unsigned int gpio = info[0].As().DoubleValue(); - unsigned int mode = info[1].As().DoubleValue(); - - return Number::New(env, - set_mode(pi, gpio, mode) - ); -} - -// GPIO 端子のモードを取得 -Value GetMode(const CallbackInfo& info) +// gpiochipデバイスを閉じる +Value gpiochipClose(const CallbackInfo& info) { Env env = info.Env(); if (info.Length() < 1) @@ -109,16 +42,12 @@ Value GetMode(const CallbackInfo& info) TypeError::New(env, "Wrong arguments").ThrowAsJavaScriptException(); return env.Null(); } - - unsigned int gpio = info[0].As().DoubleValue(); - - return Number::New(env, - get_mode(pi, gpio) - ); + unsigned int handle = info[0].As().DoubleValue(); + return Number::New(env, lgGpiochipClose(handle)); } -// GPIOの内部プルアップ/ダウン抵抗の設定/クリア -Value SetPullUpDown(const CallbackInfo& info) +// GPIO のモードを出力にする(ことを要求?) +Value gpioClaimOutput(const CallbackInfo& info) { Env env = info.Env(); if (info.Length() < 2) @@ -133,160 +62,16 @@ Value SetPullUpDown(const CallbackInfo& info) return env.Null(); } - unsigned int gpio = info[0].As().DoubleValue(); - unsigned int pud = info[1].As().DoubleValue(); + unsigned int handle = info[0].As().DoubleValue(); + unsigned int gpio = info[1].As().DoubleValue(); return Number::New(env, - set_pull_up_down(pi, gpio, pud) + lgGpioClaimOutput(handle, 0, gpio, 0) ); } -// GPIOの電圧を読む -Value Read(const CallbackInfo& info) -{ - Env env = info.Env(); - if (info.Length() < 1) - { - TypeError::New(env, "Wrong number of arguments") - .ThrowAsJavaScriptException(); - return env.Null(); - } - if (!info[0].IsNumber()) - { - TypeError::New(env, "Wrong arguments").ThrowAsJavaScriptException(); - return env.Null(); - } - - unsigned int gpio = info[0].As().DoubleValue(); - - return Number::New(env, - gpio_read(pi, gpio) - ); -} - -// GPIO の電圧をセットする -Value Write(const CallbackInfo& info) -{ - Env env = info.Env(); - if (info.Length() < 2) - { - TypeError::New(env, "Wrong number of arguments") - .ThrowAsJavaScriptException(); - return env.Null(); - } - if (!info[0].IsNumber() || !info[1].IsNumber()) - { - TypeError::New(env, "Wrong arguments").ThrowAsJavaScriptException(); - return env.Null(); - } - - unsigned int gpio = info[0].As().DoubleValue(); - unsigned int value = info[1].As().DoubleValue(); - - return Number::New(env, - gpio_write(pi, gpio, value) - ); - -} - -// サーボパルス幅をセットする -Value SetServoPulsewidth(const CallbackInfo& info) -{ - Env env = info.Env(); - if (info.Length() < 2) - { - TypeError::New(env, "Wrong number of arguments") - .ThrowAsJavaScriptException(); - return env.Null(); - } - if (!info[0].IsNumber() || !info[1].IsNumber()) - { - TypeError::New(env, "Wrong arguments").ThrowAsJavaScriptException(); - return env.Null(); - } - - unsigned int user_gpio = info[0].As().DoubleValue(); - unsigned int pulsewidth = info[1].As().DoubleValue(); - - return Number::New(env, - set_servo_pulsewidth(pi, user_gpio, pulsewidth) - ); -} - -// PWM周波数を設定する -Value SetPwmFrequency(const CallbackInfo& info) -{ - Env env = info.Env(); - if (info.Length() < 2) - { - TypeError::New(env, "Wrong number of arguments") - .ThrowAsJavaScriptException(); - return env.Null(); - } - if (!info[0].IsNumber() || !info[1].IsNumber()) - { - TypeError::New(env, "Wrong arguments").ThrowAsJavaScriptException(); - return env.Null(); - } - - unsigned int user_gpio = info[0].As().DoubleValue(); - unsigned int frequency = info[1].As().DoubleValue(); - - return Number::New(env, - set_PWM_frequency(pi, user_gpio, frequency) - ); -} - -// PWMのレンジを設定する -Value SetPwmRange(const CallbackInfo& info) -{ - Env env = info.Env(); - if (info.Length() < 2) - { - TypeError::New(env, "Wrong number of arguments") - .ThrowAsJavaScriptException(); - return env.Null(); - } - if (!info[0].IsNumber() || !info[1].IsNumber()) - { - TypeError::New(env, "Wrong arguments").ThrowAsJavaScriptException(); - return env.Null(); - } - - unsigned int user_gpio = info[0].As().DoubleValue(); - unsigned int range = info[1].As().DoubleValue(); - - return Number::New(env, - set_PWM_range(pi, user_gpio, range) - ); -} - -// PWMのデューティ比を指定して出力を開始する -Value SetPwmDutycycle(const CallbackInfo& info) -{ - Env env = info.Env(); - if (info.Length() < 2) - { - TypeError::New(env, "Wrong number of arguments") - .ThrowAsJavaScriptException(); - return env.Null(); - } - if (!info[0].IsNumber() || !info[1].IsNumber()) - { - TypeError::New(env, "Wrong arguments").ThrowAsJavaScriptException(); - return env.Null(); - } - - unsigned int user_gpio = info[0].As().DoubleValue(); - unsigned int dutycycle = info[1].As().DoubleValue(); - - return Number::New(env, - set_PWM_dutycycle(pi, user_gpio, dutycycle) - ); -} - -// シリアルポートを開く -Value SerialOpen(const CallbackInfo& info) +// GPIO のモードを入力にする(ことを要求?) +Value gpioClaimInput(const CallbackInfo& info) { Env env = info.Env(); if (info.Length() < 3) @@ -295,27 +80,152 @@ Value SerialOpen(const CallbackInfo& info) .ThrowAsJavaScriptException(); return env.Null(); } - if (!info[0].IsString() || !info[1].IsNumber() || !info[2].IsNumber()) + if (!info[0].IsNumber() || !info[1].IsNumber() || !info[2].IsNumber()) { TypeError::New(env, "Wrong arguments").ThrowAsJavaScriptException(); return env.Null(); } - std::string ser_tty = info[0].As().Utf8Value(); + unsigned int handle = info[0].As().DoubleValue(); + unsigned int gpio = info[1].As().DoubleValue(); + unsigned int lflag = info[2].As().DoubleValue(); + + return Number::New(env, + lgGpioClaimInput(handle, lflag, gpio) + ); +} + +// GPIOの電圧を読む +Value gpioRead(const CallbackInfo& info) +{ + Env env = info.Env(); + if (info.Length() < 2) + { + TypeError::New(env, "Wrong number of arguments") + .ThrowAsJavaScriptException(); + return env.Null(); + } + if (!info[0].IsNumber() || !info[1].IsNumber()) + { + TypeError::New(env, "Wrong arguments").ThrowAsJavaScriptException(); + return env.Null(); + } + + unsigned int handle = info[0].As().DoubleValue(); + unsigned int gpio = info[1].As().DoubleValue(); + + return Number::New(env, + lgGpioRead(handle, gpio) + ); +} + +// GPIO の電圧をセットする +Value gpioWrite(const CallbackInfo& info) +{ + Env env = info.Env(); + if (info.Length() < 3) + { + TypeError::New(env, "Wrong number of arguments") + .ThrowAsJavaScriptException(); + return env.Null(); + } + if (!info[0].IsNumber() || !info[1].IsNumber() || !info[2].IsNumber()) + { + TypeError::New(env, "Wrong arguments").ThrowAsJavaScriptException(); + return env.Null(); + } + + unsigned int handle = info[0].As().DoubleValue(); + unsigned int gpio = info[1].As().DoubleValue(); + unsigned int level = info[2].As().DoubleValue(); + + return Number::New(env, + lgGpioWrite(handle, gpio, level) + ); + +} + +// サーボパルス幅をセットする +Value txServo(const CallbackInfo& info) +{ + Env env = info.Env(); + if (info.Length() < 3) + { + TypeError::New(env, "Wrong number of arguments") + .ThrowAsJavaScriptException(); + return env.Null(); + } + if (!info[0].IsNumber() || !info[1].IsNumber() || !info[2].IsNumber()) + { + TypeError::New(env, "Wrong arguments").ThrowAsJavaScriptException(); + return env.Null(); + } + + unsigned int handle = info[0].As().DoubleValue(); + unsigned int gpio = info[1].As().DoubleValue(); + unsigned int pulseWidth = info[2].As().DoubleValue(); + + return Number::New(env, + lgTxServo(handle, gpio, pulseWidth, 50, 0, 0) + ); +} + +// PWMを設定して出力 +Value txPwm(const CallbackInfo& info) +{ + Env env = info.Env(); + if (info.Length() < 4) + { + TypeError::New(env, "Wrong number of arguments") + .ThrowAsJavaScriptException(); + return env.Null(); + } + if (!info[0].IsNumber() || !info[1].IsNumber() || !info[2].IsNumber() || !info[3].IsNumber()) + { + TypeError::New(env, "Wrong arguments").ThrowAsJavaScriptException(); + return env.Null(); + } + + unsigned int handle = info[0].As().DoubleValue(); + unsigned int gpio = info[1].As().DoubleValue(); + unsigned int pwmFrequency = info[2].As().DoubleValue(); + unsigned int pwmDutyCycle = info[3].As().DoubleValue(); + + return Number::New(env, + lgTxPwm(handle, gpio, pwmFrequency, pwmDutyCycle, 0,0) + ); +} + +// シリアルポートを開く +Value serialOpen(const CallbackInfo& info) +{ + Env env = info.Env(); + if (info.Length() < 2) + { + TypeError::New(env, "Wrong number of arguments") + .ThrowAsJavaScriptException(); + return env.Null(); + } + if (!info[0].IsString() || !info[1].IsNumber()) + { + TypeError::New(env, "Wrong arguments").ThrowAsJavaScriptException(); + return env.Null(); + } + + std::string tty = info[0].As().Utf8Value(); // char *c = new char[ser_tty.size()+1]; // std::strcpy(c, ser_tty.c_str()); // &ser_tty[0] で参照できるらしいけど危険? unsigned int baud = info[1].As().DoubleValue(); - unsigned int ser_flags = info[2].As().DoubleValue(); return Number::New(env, - serial_open(pi, &ser_tty[0], baud, ser_flags) + lgSerialOpen(&tty[0], baud, 0) ); } // シリアルポートを閉じる -Value SerialClose(const CallbackInfo& info) +Value serialClose(const CallbackInfo& info) { Env env = info.Env(); if (info.Length() < 1) @@ -333,11 +243,11 @@ Value SerialClose(const CallbackInfo& info) unsigned int handle = info[0].As().DoubleValue(); return Number::New(env, - serial_close(pi, handle) + lgSerialClose(handle) ); } -// シリアルデバイスからデータを読む +// シリアルデバイスからデータを受け取る Value SerialRead(const CallbackInfo& info) { Env env = info.Env(); @@ -355,19 +265,19 @@ Value SerialRead(const CallbackInfo& info) unsigned int handle = info[0].As().DoubleValue(); unsigned int count = info[1].As().DoubleValue(); - char buf[count+1]; + char rxBuf[count+1]; for (unsigned int i = 0; i <= count; i++) { - buf[i] = 0; + rxBuf[i] = 0; } - serial_read(pi, handle, buf, count); + lgSerialRead(handle, rxBuf, count); return String::New(env, - buf + rxBuf ); } -// シリアルデバイスにバイト列を書き込む(data: string) -Value SerialWrite(const CallbackInfo& info) +// シリアルデバイスにバイト列を送る(data: string) +Value serialWrite(const CallbackInfo& info) { Env env = info.Env(); if (info.Length() < 2) @@ -383,42 +293,41 @@ Value SerialWrite(const CallbackInfo& info) } unsigned int handle = info[0].As().DoubleValue(); - std::string buf = info[1].As().Utf8Value(); + std::string txBuf = info[1].As().Utf8Value(); - unsigned int count = buf.length(); + unsigned int count = txBuf.length(); return Number::New(env, - serial_write(pi, handle, &buf[0], count) + lgSerialWrite(handle, &txBuf[0], count) ); } // I2Cバスアドレスのデバイスのハンドルを返す -Value I2cOpen(const CallbackInfo& info) +Value i2cOpen(const CallbackInfo& info) { Env env = info.Env(); - if (info.Length() < 3) + if (info.Length() < 2) { TypeError::New(env, "Wrong number of arguments") .ThrowAsJavaScriptException(); return env.Null(); } - if (!info[0].IsNumber() || !info[1].IsNumber() || !info[2].IsNumber()) + if (!info[0].IsNumber() || !info[1].IsNumber()) { TypeError::New(env, "Wrong arguments").ThrowAsJavaScriptException(); return env.Null(); } - unsigned int i2c_bus = info[0].As().DoubleValue(); - unsigned int i2c_addr = info[1].As().DoubleValue(); - unsigned int i2c_flags = info[2].As().DoubleValue(); + unsigned int i2cDev = info[0].As().DoubleValue(); + unsigned int i2cAddr = info[1].As().DoubleValue(); return Number::New(env, - i2c_open(pi, i2c_bus, i2c_addr, i2c_flags) + lgI2cOpen(i2cDev, i2cAddr, 0) ); } // オープン済みI2Cハンドルを閉じる -Value I2cClose(const CallbackInfo& info) +Value i2cClose(const CallbackInfo& info) { Env env = info.Env(); if (info.Length() < 1) @@ -436,12 +345,12 @@ Value I2cClose(const CallbackInfo& info) unsigned int handle = info[0].As().DoubleValue(); return Number::New(env, - i2c_close(pi, handle) + lgI2cClose(handle) ); } // I2Cハンドルに関連付けられているデバイスの指定されたレジスタに1バイトを書き込む -Value I2cWriteByteData(const CallbackInfo& info) +Value i2cWriteByteData(const CallbackInfo& info) { Env env = info.Env(); if (info.Length() < 3) @@ -457,16 +366,16 @@ Value I2cWriteByteData(const CallbackInfo& info) } unsigned int handle = info[0].As().DoubleValue(); - unsigned int i2c_reg = info[1].As().DoubleValue(); - unsigned int bVal = info[2].As().DoubleValue(); + unsigned int i2cReg = info[1].As().DoubleValue(); + unsigned int byteVal = info[2].As().DoubleValue(); return Number::New(env, - i2c_write_byte_data(pi, handle, i2c_reg, bVal) + lgI2cWriteByteData(handle, i2cReg, byteVal) ); } // I2Cハンドルに関連付けられているデバイスの指定されたレジスタから1バイトを読み込む -Value I2cReadByteData(const CallbackInfo& info) +Value i2cReadByteData(const CallbackInfo& info) { Env env = info.Env(); if (info.Length() < 2) @@ -482,13 +391,13 @@ Value I2cReadByteData(const CallbackInfo& info) } unsigned int handle = info[0].As().DoubleValue(); - unsigned int i2c_reg = info[1].As().DoubleValue(); + unsigned int i2cReg = info[1].As().DoubleValue(); return Number::New(env, - i2c_read_byte_data(pi, handle, i2c_reg) + lgI2cReadByteData(handle, i2cReg) ); } - +/* // I2Cハンドルに関連付けられているデバイスの指定されたレジスタから単一の16ビットワードを読み取る Value I2cReadWordData(const CallbackInfo& info) { @@ -512,33 +421,30 @@ Value I2cReadWordData(const CallbackInfo& info) i2c_read_word_data(pi, handle, i2c_reg) ); } - +*/ Object Init(Env env, Object exports) { - exports.Set(String::New(env, "usleep"), Function::New(env, Usleep)); - exports.Set(String::New(env, "start"), Function::New(env, Start)); - exports.Set(String::New(env, "start_remote"), Function::New(env, StartRemote)); - exports.Set(String::New(env, "stop"), Function::New(env, Stop)); - exports.Set(String::New(env, "set_mode"), Function::New(env, SetMode)); - exports.Set(String::New(env, "get_mode"), Function::New(env, GetMode)); - exports.Set(String::New(env, "set_pull_up_down"), Function::New(env, SetPullUpDown)); - exports.Set(String::New(env, "read"), Function::New(env, Read)); - exports.Set(String::New(env, "write"), Function::New(env, Write)); - exports.Set(String::New(env, "set_servo_pulsewidth"), Function::New(env, SetServoPulsewidth)); - exports.Set(String::New(env, "set_PWM_frequency"), Function::New(env, SetPwmFrequency)); - exports.Set(String::New(env, "set_PWM_range"), Function::New(env, SetPwmRange)); - exports.Set(String::New(env, "set_PWM_dutycycle"), Function::New(env, SetPwmDutycycle)); - exports.Set(String::New(env, "serial_open"), Function::New(env, SerialOpen)); - exports.Set(String::New(env, "serial_close"), Function::New(env, SerialClose)); + exports.Set(String::New(env, "gpiochip_open"), Function::New(env, gpiochipOpen)); + exports.Set(String::New(env, "gpiochip_close"), Function::New(env, gpiochipClose)); + exports.Set(String::New(env, "gpio_claim_input"), Function::New(env, gpioClaimInput)); + exports.Set(String::New(env, "gpio_claim_output"), Function::New(env, gpioClaimOutput)); + exports.Set(String::New(env, "gpio_read"), Function::New(env, gpioRead)); + exports.Set(String::New(env, "gpio_write"), Function::New(env, gpioWrite)); + exports.Set(String::New(env, "tx_servo"), Function::New(env, txServo)); + exports.Set(String::New(env, "tx_pwm"), Function::New(env, txPwm)); + exports.Set(String::New(env, "serial_open"), Function::New(env, serialOpen)); + exports.Set(String::New(env, "serial_close"), Function::New(env, serialClose)); exports.Set(String::New(env, "serial_read"), Function::New(env, SerialRead)); - exports.Set(String::New(env, "serial_write"), Function::New(env, SerialWrite)); - exports.Set(String::New(env, "i2c_open"), Function::New(env, I2cOpen)); - exports.Set(String::New(env, "i2c_close"), Function::New(env, I2cClose)); - exports.Set(String::New(env, "i2c_write_byte_data"), Function::New(env, I2cWriteByteData)); - exports.Set(String::New(env, "i2c_read_byte_data"), Function::New(env, I2cReadByteData)); - exports.Set(String::New(env, "i2c_read_word_data"), Function::New(env, I2cReadWordData)); + exports.Set(String::New(env, "serial_write"), Function::New(env, serialWrite)); + exports.Set(String::New(env, "i2c_open"), Function::New(env, i2cOpen)); + exports.Set(String::New(env, "i2c_close"), Function::New(env, i2cClose)); + exports.Set(String::New(env, "i2c_write_byte_data"), Function::New(env, i2cWriteByteData)); + exports.Set(String::New(env, "i2c_read_byte_data"), Function::New(env, i2cReadByteData)); + + // exports.Set(String::New(env, "i2c_read_word_data"), Function::New(env, I2cReadWordData)); + return exports; } -NODE_API_MODULE( ocoge_pigpiod, Init ) \ No newline at end of file +NODE_API_MODULE( ocoge_lgpio, Init ) \ No newline at end of file diff --git a/local_modules/ocoge_pigpiod/package.json b/local_modules/ocoge_lgpio/package.json similarity index 86% rename from local_modules/ocoge_pigpiod/package.json rename to local_modules/ocoge_lgpio/package.json index 057c637..99b6dd3 100644 --- a/local_modules/ocoge_pigpiod/package.json +++ b/local_modules/ocoge_lgpio/package.json @@ -1,5 +1,5 @@ { - "name": "ocoge_pigpiod", + "name": "ocoge_lgpio", "version": "0.0.1", "main": "index.js", "private": true, diff --git a/local_modules/ocoge_pigpiod/index.js b/local_modules/ocoge_pigpiod/index.js deleted file mode 100644 index 6aaaadb..0000000 --- a/local_modules/ocoge_pigpiod/index.js +++ /dev/null @@ -1,7 +0,0 @@ -module.exports = require('bindings')('ocoge_pigpiod'); - -module.exports.INPUT = 0; -module.exports.OUTPUT = 1; -module.exports.PUD_OFF = 0; -module.exports.PUD_DOWN = 1; -module.exports.PUD_UP = 2; diff --git a/package-lock.json b/package-lock.json index 4603fa3..873413c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,13 +1,13 @@ { "name": "ocoge", - "version": "0.1.2", + "version": "0.1.3", "lockfileVersion": 1, "requires": true, "dependencies": { "@electron/get": { - "version": "1.12.4", - "resolved": "https://registry.npmjs.org/@electron/get/-/get-1.12.4.tgz", - "integrity": "sha512-6nr9DbJPUR9Xujw6zD3y+rS95TyItEVM0NVjt1EehY2vUWfIgPiIPVHxCvaTS0xr2B+DRxovYVKbuOWqC35kjg==", + "version": "1.13.0", + "resolved": "https://registry.npmjs.org/@electron/get/-/get-1.13.0.tgz", + "integrity": "sha512-+SjZhRuRo+STTO1Fdhzqnv9D2ZhjxXP6egsJ9kiO8dtP68cDx7dFCwWi64dlMQV7sWcfW1OYCW4wviEBzmRsfQ==", "dev": true, "requires": { "debug": "^4.1.1", @@ -237,9 +237,9 @@ } }, "boolean": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/boolean/-/boolean-3.0.4.tgz", - "integrity": "sha512-5pyOr+w2LNN72F2mAq6J0ckHUfJYSgRKma7e/wlcMMhgOLV9OI0ERhERYXxUqo+dPyVxcbXKy9n+wg13+LpNnA==", + "version": "3.1.4", + "resolved": "https://registry.npmjs.org/boolean/-/boolean-3.1.4.tgz", + "integrity": "sha512-3hx0kwU3uzG6ReQ3pnaFQPSktpBw6RHN3/ivDKEuU8g1XSfafowyvDnadjv1xp8IZqhtSukxlwv9bF6FhX8m0w==", "dev": true, "optional": true }, @@ -270,9 +270,9 @@ "dev": true }, "buffer-from": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.1.tgz", - "integrity": "sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==", + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz", + "integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==", "dev": true }, "cacheable-lookup": { @@ -465,9 +465,9 @@ } }, "config-chain": { - "version": "1.1.12", - "resolved": "https://registry.npmjs.org/config-chain/-/config-chain-1.1.12.tgz", - "integrity": "sha512-a1eOIcu8+7lUInge4Rpf/n4Krkf3Dd9lqhljRzII1/Zno/kRtUWnznPO3jOKBmTEktkt3fkxisUcivoj0ebzoA==", + "version": "1.1.13", + "resolved": "https://registry.npmjs.org/config-chain/-/config-chain-1.1.13.tgz", + "integrity": "sha512-qj+f8APARXHrM0hraqXYb2/bOVSV4PvJQlNZ/DVj0QrmNM2q2euizkeuVckQ57J+W0mRH6Hvi+k50M4Jul2VRQ==", "dev": true, "optional": true, "requires": { @@ -482,9 +482,9 @@ "dev": true }, "core-js": { - "version": "3.12.1", - "resolved": "https://registry.npmjs.org/core-js/-/core-js-3.12.1.tgz", - "integrity": "sha512-Ne9DKPHTObRuB09Dru5AjwKjY4cJHVGu+y5f7coGn1E9Grkc3p2iBwE9AI/nJzsE29mQF7oq+mhYYRqOMFN1Bw==", + "version": "3.16.3", + "resolved": "https://registry.npmjs.org/core-js/-/core-js-3.16.3.tgz", + "integrity": "sha512-lM3GftxzHNtPNUJg0v4pC2RC6puwMd6VZA7vXUczi+SKmCWSf4JwO89VJGMqbzmB7jlK7B5hr3S64PqwFL49cA==", "dev": true, "optional": true }, @@ -605,9 +605,9 @@ } }, "electron": { - "version": "12.0.8", - "resolved": "https://registry.npmjs.org/electron/-/electron-12.0.8.tgz", - "integrity": "sha512-bN2wYNnnma7ugBsiwysO1LI6oTTV1lDHOXuWip+OGjDUiz0IiJmZ+r0gAIMMeypVohZh7AA1ftnKad7tJ8sH4A==", + "version": "13.2.3", + "resolved": "https://registry.npmjs.org/electron/-/electron-13.2.3.tgz", + "integrity": "sha512-FzWhbKHjq7ZTpPQFaYiLPL64erC8/BOsu5NlNN9nQ6f7rIP8ygKlNAlQit3vbOcksQAwItDUCIw4sW0mcaRpCA==", "dev": true, "requires": { "@electron/get": "^1.0.1", @@ -616,9 +616,9 @@ }, "dependencies": { "@types/node": { - "version": "14.17.0", - "resolved": "https://registry.npmjs.org/@types/node/-/node-14.17.0.tgz", - "integrity": "sha512-w8VZUN/f7SSbvVReb9SWp6cJFevxb4/nkG65yLAya//98WgocKm5PLDAtSs5CtJJJM+kHmJjO/6mmYW4MHShZA==", + "version": "14.17.12", + "resolved": "https://registry.npmjs.org/@types/node/-/node-14.17.12.tgz", + "integrity": "sha512-vhUqgjJR1qxwTWV5Ps5txuy2XMdf7Fw+OrdChRboy8BmWUPkckOhphaohzFG6b8DW7CrxaBMdrdJ47SYFq1okw==", "dev": true } } @@ -1651,8 +1651,8 @@ "dev": true, "optional": true }, - "ocoge_pigpiod": { - "version": "file:local_modules/ocoge_pigpiod", + "ocoge_lgpio": { + "version": "file:local_modules/ocoge_lgpio", "requires": { "bindings": "^1.5.0", "node-addon-api": "^1.7.1" diff --git a/package.json b/package.json index 7b14ed8..9af6fed 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ocoge", - "version": "0.1.2", + "version": "0.1.3", "description": "\"大岩産 Code Generator\" は、Google Blockly ライブラリを使用した、Raspberry Pi 上で動作するブロックプログラム開発・実行環境です。", "main": "index.js", "scripts": { @@ -19,12 +19,12 @@ }, "homepage": "https://github.com/ocogeclub/ocoge#readme", "devDependencies": { - "electron": "^13.1.5", + "electron": "^13.2.2", "electron-rebuild": "^2.3.5" }, "dependencies": { "axios": "^0.21.1", "nodemailer": "^6.6.0", - "ocoge_pigpiod": "file:local_modules/ocoge_pigpiod" + "ocoge_lgpio": "file:local_modules/ocoge_lgpio" } -} \ No newline at end of file +} diff --git a/scripts/ugj_blocks.js b/scripts/ugj_blocks.js index 3117ee5..f3c747c 100644 --- a/scripts/ugj_blocks.js +++ b/scripts/ugj_blocks.js @@ -146,507 +146,629 @@ Blockly.Python['ugj_controls_forEach'] = function (block) { /** GPIO *****************************************************************************************************/ -/************* */ -/** GPIO Start */ -/************* */ -var ugjGpioStartDefinition = { - "type": "ugj_gpio_start", - "message0": "%{BKY_GPIO_START_TITLE}", +/************ */ +/** GPIO Open */ +/************ */ +var ugjGpiochipOpenDefinition = { + "type": "ugj_gpiochip_open", + "message0": "%{BKY_GPIOCHIP_OPEN_TITLE}", "previousStatement": null, "nextStatement": null, - "tooltip": "%{BKY_GPIO_START_TOOLTIP}", + "tooltip": "%{BKY_GPIOCHIP_OPEN_TOOLTIP}", "helpUrl": "", "style": "gpio_blocks" }; -Blockly.Blocks['ugj_gpio_start'] = { +Blockly.Blocks['ugj_gpiochip_open'] = { init: function () { - this.jsonInit(ugjGpioStartDefinition); + this.jsonInit(ugjGpiochipOpenDefinition); } }; -Blockly.JavaScript['ugj_gpio_start'] = function (block) { +Blockly.JavaScript['ugj_gpiochip_open'] = function (block) { Blockly.JavaScript.provideFunction_( - 'require_ocpig', [`const pi = require('ocoge_pigpiod');\n`] + 'require_oclg', [`const pi = require('ocoge_lgpio');\n`] ) - var code = `pi.start();\n`; // + var code = `var lgHand = pi.gpiochip_open(0);\n`; // return code; }; -Blockly.Python['ugj_gpio_start'] = function (block) { +Blockly.Python['ugj_gpiochip_open'] = function (block) { Blockly.Python.provideFunction_( - 'import_pigpio', ['import pigpio'] + 'import_lgpio', ['import lgpio as pi'] ) - var code = `pi = pigpio.pi()\n`; // + var code = `lgHand = pi.gpiochip_open(0)\n`; // return code; }; -// remote gpio -var ugjGpioStartRemoteDefinition = { - "type": "ugj_gpio_start_remote", - "message0": "%{BKY_GPIO_START_REMOTE_TITLE}", + +/************* */ +/** GPIO Close */ +/************* */ +var ugjGpiochipCloseDefinition = { + "type": "ugj_gpiochip_close", + "message0": "%{BKY_GPIOCHIP_CLOSE_TITLE}", + "previousStatement": null, + "nextStatement": null, + "tooltip": "%{BKY_GPIOCHIP_CLOSE_TOOLTIP}", + "helpUrl": "", + "style": "gpio_blocks" +}; +Blockly.Blocks['ugj_gpiochip_close'] = { + init: function () { + this.jsonInit(ugjGpiochipCloseDefinition); + } +}; +Blockly.JavaScript['ugj_gpiochip_close'] = function (block) { + var code = 'pi.gpiochip_close(lgHand);\n'; + return code; +}; +Blockly.Python['ugj_gpiochip_close'] = function (block) { + var code = 'pi.gpiochip_close(lgHand)\n'; + return code; +}; + +/*********************** */ +/** GPIO Claim Output ** */ +/*********************** */ +var ugjGpioClaimOutputDefinition = { + "type": "ugj_gpio_claim_output", + "message0": "%{BKY_GPIO_CLAIM_OUTPUT_TITLE}", "args0": [ { "type": "input_value", - "name": "host", - "check": "String" + "name": "gpio", + "check": "Number" } ], "inputsInline": true, "previousStatement": null, "nextStatement": null, - "tooltip": "%{BKY_GPIO_START_REMOTE_TOOLTIP}", + "tooltip": "%{BKY_GPIO_CLAIM_OUTPUT_TOOLTIP}", "helpUrl": "", "style": "gpio_blocks" }; -Blockly.Blocks['ugj_gpio_start_remote'] = { +Blockly.Blocks['ugj_gpio_claim_output'] = { init: function () { - this.jsonInit(ugjGpioStartRemoteDefinition); + this.jsonInit(ugjGpioClaimOutputDefinition); } }; -Blockly.JavaScript['ugj_gpio_start_remote'] = function (block) { - var value_host = Blockly.JavaScript.valueToCode(block, 'host', Blockly.JavaScript.ORDER_ATOMIC); - var code = `pi.start_remote(${value_host}, '8888');\n`; // +Blockly.JavaScript['ugj_gpio_claim_output'] = function (block) { + var value_gpio = Blockly.JavaScript.valueToCode(block, 'gpio', Blockly.JavaScript.ORDER_ATOMIC); + var code = `pi.gpio_claim_output(lgHand, ${value_gpio});\n`; return code; }; -Blockly.Python['ugj_gpio_start_remote'] = function (block) { - Blockly.Python.provideFunction_( - 'import_pigpio', ['import pigpio'] - ) - var value_host = Blockly.Python.valueToCode(block, 'host', Blockly.Python.ORDER_ATOMIC); - var code = `pi = pigpio.pi(${value_host}, '8888')\n`; +Blockly.Python['ugj_gpio_claim_output'] = function (block) { + var value_gpio = Blockly.Python.valueToCode(block, 'gpio', Blockly.Python.ORDER_ATOMIC); + var code = `pi.gpio_claim_output(lgHand, ${value_gpio})\n`; return code; }; -/************ */ -/** GPIO Stop */ -/************ */ -var ugjGpioStopDefinition = { - "type": "ugj_gpio_stop", - "message0": "%{BKY_GPIO_STOP_TITLE}", +/********************** */ +/** GPIO Claim Input ** */ +/********************** */ +var ugjGpioClaimInputDefinition = { + "type": "ugj_gpio_claim_input", + "message0": "%{BKY_GPIO_CLAIM_INPUT_TITLE}", + "args0": [ + { + "type": "input_value", + "name": "gpio", + "check": "Number" + }, + { + "type": "field_dropdown", + "name": "lflag", + "options": [ + [ + "プルアップ", + "pi.SET_PULL_UP" + ], + [ + "プルダウン", + "pi.SET_PULL_DOWN" + ], + [ + "プル無し", + "pi.SET_PULL_NONE" + ] + ] + } + ], + "inputsInline": true, "previousStatement": null, "nextStatement": null, - "tooltip": "%{BKY_GPIO_STOP_TOOLTIP}", + "tooltip": "%{BKY_GPIO_CLAIM_INPUT_TOOLTIP}", "helpUrl": "", "style": "gpio_blocks" }; -Blockly.Blocks['ugj_gpio_stop'] = { +Blockly.Blocks['ugj_gpio_claim_input'] = { init: function () { - this.jsonInit(ugjGpioStopDefinition); + this.jsonInit(ugjGpioClaimInputDefinition); } }; -Blockly.JavaScript['ugj_gpio_stop'] = function (block) { - var code = 'pi.stop();\n'; - return code; -}; -Blockly.Python['ugj_gpio_stop'] = function (block) { - var code = `pi.stop()\n`; - return code; -}; - -/********************* */ -/** GPIO Set Output ** */ -/********************* */ -Blockly.Blocks['ugj_gpio_setoutput'] = { - init: function () { - this.appendValueInput("gpio") - .setCheck("Number") - .appendField("GPIO"); - this.appendDummyInput() - .appendField("を出力モードにする"); - this.setInputsInline(true); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setStyle('gpio_blocks') - this.setTooltip("GPIO端子のモードを出力に設定します。"); - this.setHelpUrl(""); - } -}; -Blockly.JavaScript['ugj_gpio_setoutput'] = function (block) { +Blockly.JavaScript['ugj_gpio_claim_input'] = function (block) { var value_gpio = Blockly.JavaScript.valueToCode(block, 'gpio', Blockly.JavaScript.ORDER_ATOMIC); - var code = `pi.set_mode(${value_gpio}, pi.OUTPUT);\n`; + var dropdown_lflag = block.getFieldValue('lflag'); + var code = `pi.gpio_claim_input(lgHand, ${value_gpio}, ${dropdown_lflag});\n`; return code; }; - -/*********************************** */ -/** GPIO Set Input and PullupDown ** */ -/*********************************** */ -Blockly.Blocks['ugj_gpio_setinput'] = { - init: function () { - this.appendValueInput("gpio") - .setCheck("Number") - .appendField("GPIO"); - this.appendDummyInput() - .appendField("を入力モードにして") - .appendField(new Blockly.FieldDropdown([["プルアップ", "pi.PUD_UP"], ["プルダウン", "pi.PUD_DOWN"]]), "updown"); - this.setInputsInline(true); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setStyle('gpio_blocks') - this.setTooltip("GPIO端子を入力モードにして、プルアップ・プルダウンを設定します。"); - this.setHelpUrl(""); - } -}; -Blockly.JavaScript['ugj_gpio_setinput'] = function (block) { - var value_gpio = Blockly.JavaScript.valueToCode(block, 'gpio', Blockly.JavaScript.ORDER_ATOMIC); - var dropdown_updown = block.getFieldValue('updown'); - var code = `pi.set_mode(${value_gpio}, pi.INPUT);\n`; - code += `pi.set_pull_up_down(${value_gpio}, ${dropdown_updown});\n`; +Blockly.Python['ugj_gpio_claim_input'] = function (block) { + var value_gpio = Blockly.Python.valueToCode(block, 'gpio', Blockly.Python.ORDER_ATOMIC); + var dropdown_lflag = block.getFieldValue('lflag'); + var code = `pi.gpio_claim_input(lgHand, ${value_gpio}, ${dropdown_lflag})\n`; return code; }; /********************* */ /** Read GPIO Value ** */ /***********************/ +var ugjGpioReadDefinition = { + "type": "ugj_gpio_read", + "message0": "%{BKY_GPIO_READ_TITLE}", + "args0": [ + { + "type": "input_value", + "name": "gpio", + "check": "Number" + } + ], + "inputsInline": true, + "output": "Number", + "tooltip": "%{BKY_GPIO_READ_TOOLTIP", + "helpUrl": "", + "style": "gpio_blocks" +}; Blockly.Blocks['ugj_gpio_read'] = { init: function () { - this.appendValueInput("gpio") - .setCheck("Number") - .appendField("GPIO"); - this.appendDummyInput() - .appendField("の値"); - this.setInputsInline(true); - this.setOutput(true, "Number"); - this.setOutputShape(Blockly.OUTPUT_SHAPE_ROUND); - this.setStyle('gpio_blocks') - this.setTooltip("GPIO端子の値をデジタル値(0または1)で読み取ります。"); - this.setHelpUrl(""); + this.jsonInit(ugjGpioReadDefinition); } }; Blockly.JavaScript['ugj_gpio_read'] = function (block) { var value_gpio = Blockly.JavaScript.valueToCode(block, 'gpio', Blockly.JavaScript.ORDER_ATOMIC); - var code = `pi.read(${value_gpio})`; + var code = `pi.gpio_read(lgHand, ${value_gpio})`; return [code, Blockly.JavaScript.ORDER_NONE]; }; +Blockly.Python['ugj_gpio_read'] = function (block) { + var value_gpio = Blockly.Python.valueToCode(block, 'gpio', Blockly.Python.ORDER_ATOMIC); + var code = `pi.gpio_read(lgHand, ${value_gpio})`; + return [code, Blockly.Python.ORDER_NONE]; +}; /*******************************************/ /** GPIO Write Value - Common GPIO on/off **/ /*******************************************/ +var ugjGpioWriteDefinition = { + "type": "ugj_gpio_write", + "message0": "%{BKY_GPIO_WRITE_TITLE}", + "args0": [ + { + "type": "input_value", + "name": "gpio", + "check": "Number" + }, + { + "type": "field_dropdown", + "name": "level", + "options": [ + [ + "0", + "0" + ], + [ + "1", + "1" + ] + ] + } + ], + "inputsInline": true, + "previousStatement": null, + "nextStatement": null, + "tooltip": "%{BKY_GPIO_WRITE_TOOLTIP}", + "helpUrl": "", + "style": "gpio_blocks" +}; Blockly.Blocks['ugj_gpio_write'] = { init: function () { - this.appendValueInput("ugj_gpio_num") - .setCheck("Number") - .appendField("GPIO"); - this.appendValueInput("ugj_gpio_value") - .setCheck("Number") - .appendField("を"); - this.appendDummyInput() - .appendField("にする"); - this.setInputsInline(true); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setStyle('gpio_blocks') - this.setTooltip("GPIO端子の値をデジタル値(0または1)で出力します。"); - this.setHelpUrl(""); + this.jsonInit(ugjGpioWriteDefinition); } }; Blockly.JavaScript['ugj_gpio_write'] = function (block) { - var value_ugj_gpio_num = Blockly.JavaScript.valueToCode(block, 'ugj_gpio_num', Blockly.JavaScript.ORDER_ATOMIC); - var value_ugj_gpio_value = Blockly.JavaScript.valueToCode(block, 'ugj_gpio_value', Blockly.JavaScript.ORDER_ATOMIC); - var code = `pi.write(${value_ugj_gpio_num}, ${value_ugj_gpio_value});\n`; + var value_gpio = Blockly.JavaScript.valueToCode(block, 'gpio', Blockly.JavaScript.ORDER_ATOMIC); + var dropdown_level = block.getFieldValue('level'); + var code = `pi.gpio_write(lgHand, ${value_gpio}, ${dropdown_level});\n`; + return code; +}; +Blockly.Python['ugj_gpio_write'] = function (block) { + var value_gpio = Blockly.Python.valueToCode(block, 'gpio', Blockly.Python.ORDER_ATOMIC); + var dropdown_level = block.getFieldValue('level'); + var code = `pi.gpio_write(lgHand, ${value_gpio}, ${dropdown_level})\n`; return code; }; /*****************/ /** Servo motor **/ /*****************/ -Blockly.Blocks['ugj_gpio_servo'] = { +var ugjTxServoDefinition = { + "type": "ugj_tx_servo", + "message0": "%{BKY_TX_SERVO_TITLE}", + "args0": [ + { + "type": "input_value", + "name": "gpio", + "check": "Number" + }, + { + "type": "input_value", + "name": "pulsewidth", + "check": "Number" + } + ], + "inputsInline": true, + "previousStatement": null, + "nextStatement": null, + "tooltip": "%{BKY_TX_SERVO_TOOLTIP}", + "helpUrl": "", + "style": "gpio_blocks" +}; +Blockly.Blocks['ugj_tx_servo'] = { init: function () { - this.appendValueInput("gpio") - .setCheck("Number") - .appendField("GPIO"); - this.appendValueInput("pulsewidth") - .setCheck("Number") - .appendField("のサーボモータの回転を"); - this.appendDummyInput() - .appendField("にする"); - this.setInputsInline(true); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setStyle('gpio_blocks') - this.setTooltip("サーボモータの回転をパルス幅(1000~2000μsec)までの数値で指定します。"); - this.setHelpUrl(""); + this.jsonInit(ugjTxServoDefinition); } }; -Blockly.JavaScript['ugj_gpio_servo'] = function (block) { +Blockly.JavaScript['ugj_tx_servo'] = function (block) { 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 code = `pi.set_servo_pulsewidth(${value_gpio}, ${value_pulsewidth});\n`; + var code = `pi.tx_servo(lgHand, ${value_gpio}, ${value_pulsewidth});\n`; + return code; +}; +Blockly.Python['ugj_tx_servo'] = function (block) { + var value_gpio = Blockly.Python.valueToCode(block, 'gpio', Blockly.Python.ORDER_ATOMIC); + var value_pulsewidth = Blockly.Python.valueToCode(block, 'pulsewidth', Blockly.Python.ORDER_ATOMIC); + var code = `pi.tx_servo(lgHand, ${value_gpio}, ${value_pulsewidth})\n`; return code; }; -/********************************* */ -/** Set PWM Frequency and Range ** */ -/********************************* */ -Blockly.Blocks['ugj_gpio_setpwmfreqrange'] = { +/************************************************* */ +/** starts software timed PWM on an output GPIO ** */ +/************************************************* */ +var ugjTxPwmDefinition = { + "type": "ugj_tx_pwm", + "message0": "%{BKY_TX_PWM_TITLE}", + "args0": [ + { + "type": "input_value", + "name": "gpio", + "check": "Number" + }, + { + "type": "input_value", + "name": "pwm_frequency", + "check": "Number" + }, + { + "type": "input_value", + "name": "pwm_duty_cycle", + "check": "Number" + } + ], + "inputsInline": true, + "previousStatement": null, + "nextStatement": null, + "tooltip": "%{BKY_TX_PWM_TOOLTIP}", + "helpUrl": "", + "style": "gpio_blocks" +}; +Blockly.Blocks['ugj_tx_pwm'] = { init: function () { - this.appendValueInput("gpio") - .setCheck("Number") - .appendField("GPIO"); - this.appendDummyInput() - .appendField("のパルス周波数を") - .appendField(new Blockly.FieldDropdown([["10", "10"], ["20", "20"], ["40", "40"], ["50", "50"], ["80", "80"], ["100", "100"], ["200", "200"], ["400", "400"], ["800", "800"], ["8000", "8000"]]), "pwmfreq") - .appendField("Hzにする"); - this.setInputsInline(true); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setStyle('gpio_blocks') - this.setTooltip("パルス周波数をセットして、GPIO端子がPWM出力できるようにします。レンジは100固定です。"); - this.setHelpUrl(""); + this.jsonInit(ugjTxPwmDefinition); } }; -Blockly.JavaScript['ugj_gpio_setpwmfreqrange'] = function (block) { +Blockly.JavaScript['ugj_tx_pwm'] = function(block) { var value_gpio = Blockly.JavaScript.valueToCode(block, 'gpio', Blockly.JavaScript.ORDER_ATOMIC); - var dropdown_pwmfreq = block.getFieldValue('pwmfreq'); - var code = [ - `pi.set_PWM_frequency(${value_gpio}, ${dropdown_pwmfreq});`, - // `pi.set_PWM_range(${value_gpio}, 100);`, - "" - ].join('\n'); + 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 code = `pi.tx_pwm(lgHand, ${value_gpio}, ${value_pwm_frequency}, ${value_pwm_duty_cycle});\n`; return code; }; - -/******************************************** */ -/** Starts or stops PWM pulses on the GPIO ** */ -/******************************************** */ -Blockly.Blocks['ugj_gpio_setpwmdutycycle'] = { - init: function () { - this.appendValueInput("dutycycle") - .setCheck("Number") - .appendField("デューティ比"); - this.appendValueInput("gpio") - .setCheck("Number") - .appendField("% のパルスを GPIO"); - this.appendDummyInput() - .appendField("から出力する"); - this.setInputsInline(true); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setStyle('gpio_blocks') - this.setTooltip("デューティ比(1~100%)を指定して出力を開始します。0を指定すると出力を停止します。事前に必ずパルス周波数ブロックが実行されるようにしてください。"); - this.setHelpUrl("https://ja.wikipedia.org/wiki/%E3%83%87%E3%83%A5%E3%83%BC%E3%83%86%E3%82%A3%E6%AF%94"); - } -}; -Blockly.JavaScript['ugj_gpio_setpwmdutycycle'] = function (block) { - var value_dutycycle = Blockly.JavaScript.valueToCode(block, 'dutycycle', Blockly.JavaScript.ORDER_ATOMIC); - var value_gpio = Blockly.JavaScript.valueToCode(block, 'gpio', Blockly.JavaScript.ORDER_ATOMIC); - var code = `pi.set_PWM_dutycycle(${value_gpio}, ${value_dutycycle});\n`; +Blockly.Python['ugj_tx_pwm'] = function(block) { + var value_gpio = Blockly.Python.valueToCode(block, 'gpio', Blockly.Python.ORDER_ATOMIC); + var value_pwm_frequency = Blockly.Python.valueToCode(block, 'pwm_frequency', Blockly.Python.ORDER_ATOMIC); + var value_pwm_duty_cycle = Blockly.Python.valueToCode(block, 'pwm_duty_cycle', Blockly.Python.ORDER_ATOMIC); + var code = `pi.tx_pwm(lgHand, ${value_gpio}, ${value_pwm_frequency}, ${value_pwm_duty_cycle})\n`; return code; }; - /********************** */ /** Open Serial Port ** */ /********************** */ -Blockly.Blocks['ugj_gpio_serialopen'] = { +var ugjSerialOpenDefinition = { + "type": "ugj_serial_open", + "message0": "%{BKY_SERIAL_OPEN_TITLE}", + "args0": [ + { + "type": "input_value", + "name": "tty", + "check": "String" + }, + { + "type": "field_dropdown", + "name": "baud", + "options": [ + [ + "9600", + "9600" + ], + [ + "19200", + "19200" + ], + [ + "115200", + "115200" + ] + ] + } + ], + "inputsInline": true, + "previousStatement": null, + "nextStatement": null, + "tooltip": "%{BKY_SERIAL_OPEN_TOOLTIP}", + "helpUrl": "", + "style": "gpio_blocks" +}; +Blockly.Blocks['ugj_serial_open'] = { init: function () { - this.appendValueInput("tty") - .setCheck("String") - .appendField("シリアルポート"); - this.appendDummyInput() - .appendField("を速度") - .appendField(new Blockly.FieldDropdown([["9600", "9600"], ["19200", "19200"], ["115200", "115200"]]), "baud") - .appendField("bpsで開く"); - this.setInputsInline(true); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setStyle('gpio_blocks') - this.setTooltip("シリアルデバイスとの接続を開きます。"); - this.setHelpUrl(""); + this.jsonInit(ugjSerialOpenDefinition); } }; -Blockly.JavaScript['ugj_gpio_serialopen'] = function (block) { +Blockly.JavaScript['ugj_serial_open'] = function (block) { var value_tty = Blockly.JavaScript.valueToCode(block, 'tty', Blockly.JavaScript.ORDER_ATOMIC); var dropdown_baud = block.getFieldValue('baud'); - var code = `let serhand = pi.serial_open(${value_tty}, ${dropdown_baud}, 0);`; + var code = `let ser_hand = pi.serial_open(${value_tty}, ${dropdown_baud}, 0);\n`; return code; }; -/********************** */ +Blockly.Python['ugj_serial_open'] = function (block) { + var value_tty = Blockly.Python.valueToCode(block, 'tty', Blockly.Python.ORDER_ATOMIC); + var dropdown_baud = block.getFieldValue('baud'); + var code = `ser_hand = pi.serial_open(${value_tty}, ${dropdown_baud}, 0)\n`; + return code; +}; +/*********************** */ /** Close Serial Port ** */ -/********************** */ +/*********************** */ +var ugjSerialCloseDefinition = { + "type": "ugj_serial_close", + "message0": "%{BKY_SERIAL_CLOSE_TITLE}", + "inputsInline": true, + "previousStatement": null, + "nextStatement": null, + "tooltip": "%{BKY_SERIAL_CLOSE_TOOLTIP}", + "helpUrl": "", + "style": "gpio_blocks" +}; Blockly.Blocks['ugj_serial_close'] = { init: function () { - this.appendDummyInput() - .appendField("シリアルポートを閉じる"); - this.setInputsInline(true); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setStyle('gpio_blocks') - this.setTooltip("シリアルデバイスとの接続を閉じます。"); - this.setHelpUrl(""); + this.jsonInit(ugjSerialCloseDefinition); } }; Blockly.JavaScript['ugj_serial_close'] = function (block) { - var code = 'pi.serial_close(serhand);'; + var code = 'pi.serial_close(ser_hand);\n'; + return code; +}; +Blockly.Python['ugj_serial_close'] = function (block) { + var code = 'pi.serial_close(ser_hand)\n'; return code; }; /************************** */ /** Write Data to Serial ** */ /************************** */ +var ugjSerialWriteDefinition = { + "type": "ugj_serial_write", + "message0": "%{BKY_SERIAL_WRITE_TITLE}", + "args0": [ + { + "type": "input_value", + "name": "data", + "check": "String" + } + ], + "inputsInline": true, + "previousStatement": null, + "nextStatement": null, + "tooltip": "%{BKY_SERIAL_WRITE_TOOLTIP}", + "helpUrl": "", + "style": "gpio_blocks" +}; Blockly.Blocks['ugj_serial_write'] = { init: function () { - this.appendValueInput("data") - .setCheck("String") - .appendField("シリアルポートに"); - this.appendDummyInput() - .appendField("を送信する"); - this.setInputsInline(true); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setStyle('gpio_blocks') - this.setTooltip("シリアル接続されたデバイスにデータを送信します。シリアルポートは開かれていなくてはいけません。"); - this.setHelpUrl(""); + this.jsonInit(ugjSerialWriteDefinition); } }; Blockly.JavaScript['ugj_serial_write'] = function (block) { var value_data = Blockly.JavaScript.valueToCode(block, 'data', Blockly.JavaScript.ORDER_ATOMIC); - var code = `pi.serial_write(serhand, ${value_data});\n`; + var code = `pi.serial_write(ser_hand, ${value_data});\n`; + return code; +}; +Blockly.Python['ugj_serial_write'] = function (block) { + var value_data = Blockly.Python.valueToCode(block, 'data', Blockly.Python.ORDER_ATOMIC); + var code = `pi.serial_write(ser_hand, ${value_data})\n`; return code; }; /************************ */ /** Read Data from Serial */ /************************ */ -Blockly.Blocks['ugj_gpio_serialread'] = { +var ugjSerialReadDefinition = { + "type": "ugj_serial_read", + "message0": "%{BKY_SERIAL_READ_TITLE}", + "args0": [ + { + "type": "input_value", + "name": "count", + "check": "Number" + } + ], + "inputsInline": true, + "output": null, + "tooltip": "%{BKY_SERIAL_READ_TOOLTIP}", + "helpUrl": "", + "style": "gpio_blocks" +}; +Blockly.Blocks['ugj_serial_read'] = { init: function () { - this.appendValueInput("count") - .setCheck("Number") - .appendField("シリアルポートから"); - this.appendDummyInput() - .appendField("文字読み込む"); - this.setInputsInline(true); - this.setOutput(true, null); - this.setOutputShape(Blockly.OUTPUT_SHAPE_ROUND); - this.setStyle('gpio_blocks') - this.setTooltip("オープン済みシリアルポートから、指定のバイト数だけデータを読み込みます。"); - this.setHelpUrl(""); + this.jsonInit(ugjSerialReadDefinition); } }; -Blockly.JavaScript['ugj_gpio_serialread'] = function (block) { +Blockly.JavaScript['ugj_serial_read'] = function (block) { var value_count = Blockly.JavaScript.valueToCode(block, 'count', Blockly.JavaScript.ORDER_ATOMIC); - var code = `pi.serial_read(serhand, ${value_count})`; + var code = `pi.serial_read(ser_hand, ${value_count});\n`; return [code, Blockly.JavaScript.ORDER_NONE]; }; +Blockly.Python['ugj_serial_read'] = function (block) { + var value_count = Blockly.Python.valueToCode(block, 'count', Blockly.Python.ORDER_ATOMIC); + var code = `pi.serial_read(ser_hand, ${value_count})\n`; + return [code, Blockly.Python.ORDER_NONE]; +}; /********************* */ /** Open I2C Device ** */ /********************* */ -Blockly.Blocks['ugj_gpio_i2copen'] = { +var ugjI2cOpenDefinition = { + "type": "ugj_i2c_open", + "message0": "%{BKY_I2C_OPEN_TITLE}", + "args0": [ + { + "type": "input_value", + "name": "i2c_address", + "check": "Number" + } + ], + "inputsInline": true, + "previousStatement": null, + "nextStatement": null, + "tooltip": "%{BKY_I2C_OPEN_TOOLTIP}", + "helpUrl": "", + "style": "gpio_blocks" +}; +Blockly.Blocks['ugj_i2c_open'] = { init: function () { - this.appendValueInput("i2c_addr") - .setCheck("Number") - .appendField("アドレス"); - this.appendDummyInput() - .appendField("の I2C デバイスを開く"); - this.setInputsInline(true); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setStyle('gpio_blocks') - this.setTooltip("I2C接続されたデバイスとの通信を開始します。一度にオープンできるI2Cデバイスはひとつだけです。"); - this.setHelpUrl(""); + this.jsonInit(ugjI2cOpenDefinition); } }; -Blockly.JavaScript['ugj_gpio_i2copen'] = function (block) { - var value_i2c_addr = Blockly.JavaScript.valueToCode(block, 'i2c_addr', Blockly.JavaScript.ORDER_ATOMIC); - var code = `let i2cHand = pi.i2c_open(1, ${value_i2c_addr}, 0);`; +Blockly.JavaScript['ugj_i2c_open'] = function (block) { + var value_i2c_address = Blockly.JavaScript.valueToCode(block, 'i2c_address', Blockly.JavaScript.ORDER_ATOMIC); + var code = `let i2c_hand = pi.i2c_open(1, ${value_i2c_address});\n`; + return code; +}; +Blockly.Python['ugj_i2c_open'] = function (block) { + var value_i2c_address = Blockly.Python.valueToCode(block, 'i2c_address', Blockly.Python.ORDER_ATOMIC); + var code = `i2c_hand = pi.i2c_open(1, ${value_i2c_address})\n`; return code; }; /********************** */ /** Close I2C Device ** */ /********************** */ -Blockly.Blocks['ugj_gpio_i2cclose'] = { +var ugjI2cCloseDefinition = { + "type": "ugj_i2c_close", + "message0": "%{BKY_I2C_CLOSE_TITLE}", + "inputsInline": true, + "previousStatement": null, + "nextStatement": null, + "tooltip": "%{BKY_I2C_CLOSE_TOOLTIP}", + "helpUrl": "", + "style": "gpio_blocks" +}; +Blockly.Blocks['ugj_i2c_close'] = { init: function () { - this.appendDummyInput() - .appendField("I2C デバイスを閉じる"); - this.setInputsInline(true); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setStyle('gpio_blocks') - this.setTooltip("I2C接続されたデバイスと通信を切断します。"); - this.setHelpUrl(""); + this.jsonInit(ugjI2cCloseDefinition); } }; -Blockly.JavaScript['ugj_gpio_i2cclose'] = function (block) { - var code = `pi.i2c_close(i2cHand);`; +Blockly.JavaScript['ugj_i2c_close'] = function (block) { + var code = `pi.i2c_close(i2c_hand);\n`; + return code; +}; +Blockly.Python['ugj_i2c_close'] = function (block) { + var code = `pi.i2c_close(i2c_hand)\n`; return code; }; /****************************************************************** */ /** Writes a single byte to the specified register of the device ** */ /****************************************************************** */ - -Blockly.Blocks['ugj_gpio_i2cwritebyte'] = { +var ugjI2cWriteByteDataDefinition = { + "type": "ugj_i2c_write_byte_data", + "message0": "%{BKY_I2C_WRITE_BYTE_DATA_TITLE}", + "args0": [ + { + "type": "input_value", + "name": "reg", + "check": "Number" + }, + { + "type": "input_value", + "name": "byte_val", + "check": "Number" + } + ], + "inputsInline": true, + "previousStatement": null, + "nextStatement": null, + "tooltip": "%{BKY_I2C_WRITE_BYTE_DATA_TOOLTIP}", + "helpUrl": "", + "style": "gpio_blocks" +}; +Blockly.Blocks['ugj_i2c_write_byte_data'] = { init: function () { - this.appendValueInput("reg") - .setCheck("Number") - .appendField("レジスタ"); - this.appendValueInput("byteData") - .setCheck("Number") - .appendField("に"); - this.appendDummyInput() - .appendField("を書き込む"); - this.setInputsInline(true); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setStyle('gpio_blocks') - this.setTooltip("デバイスの指定されたレジスタに1バイトを書き込みます。"); - this.setHelpUrl(""); + this.jsonInit(ugjI2cWriteByteDataDefinition); } }; -Blockly.JavaScript['ugj_gpio_i2cwritebyte'] = 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_bytedata = Blockly.JavaScript.valueToCode(block, 'byteData', Blockly.JavaScript.ORDER_ATOMIC); - var code = `pi.i2c_write_byte_data(i2cHand, ${value_reg}, ${value_bytedata});\n`; + var value_byte_val = Blockly.JavaScript.valueToCode(block, 'byte_val', Blockly.JavaScript.ORDER_ATOMIC); + var code = `pi.i2c_write_byte_data(i2c_hand, ${value_reg}, ${value_byte_val});\n`; + return code; +}; +Blockly.Python['ugj_i2c_write_byte_data'] = function (block) { + var value_reg = Blockly.Python.valueToCode(block, 'reg', Blockly.Python.ORDER_ATOMIC); + var value_byte_val = Blockly.Python.valueToCode(block, 'byte_val', Blockly.Python.ORDER_ATOMIC); + var code = `pi.i2c_write_byte_data(i2c_hand, ${value_reg}, ${value_byte_val})\n`; return code; }; /****************************************************************** */ /** Read a single byte from the specified resister of the device ** */ /****************************************************************** */ -Blockly.Blocks['ugj_gpio_i2creadbyte'] = { +var ugjI2cReadByteDataDefinition = { + "type": "ugj_i2c_read_byte_data", + "message0": "%{BKY_I2C_READ_BYTE_DATA_TITLE}", + "args0": [ + { + "type": "input_value", + "name": "reg", + "check": "Number" + } + ], + "inputsInline": true, + "output": null, + "tooltip": "%{BKY_I2C_READ_BYTE_DATA_TOOLTIP}", + "helpUrl": "", + "style": "gpio_blocks" +}; +Blockly.Blocks['ugj_i2c_read_byte_data'] = { init: function () { - this.appendValueInput("reg") - .setCheck("Number") - .appendField("レジスタ"); - this.appendDummyInput() - .appendField("の値"); - this.setInputsInline(true); - this.setOutput(true, null); - this.setOutputShape(Blockly.OUTPUT_SHAPE_ROUND); - this.setStyle('gpio_blocks') - this.setTooltip("デバイスの指定されたレジスタから1バイトを読み込みます。"); - this.setHelpUrl(""); + this.jsonInit(ugjI2cReadByteDataDefinition); } }; -Blockly.JavaScript['ugj_gpio_i2creadbyte'] = function (block) { +Blockly.JavaScript['ugj_i2c_read_byte_data'] = function (block) { var value_reg = Blockly.JavaScript.valueToCode(block, 'reg', Blockly.JavaScript.ORDER_ATOMIC); - var code = `pi.i2c_read_byte_data(i2cHand, ${value_reg})`; + var code = `pi.i2c_read_byte_data(i2c_hand, ${value_reg});\n`; return [code, Blockly.JavaScript.ORDER_NONE]; }; - - - - - -/********************************************************************************** */ -/** Extra Method : Sleep with C++ Native Module *************************************/ -/** Warning: This block freezes the whole application. Cannot terminate, exit, etc. */ -/********************************************************************************** */ -Blockly.Blocks['ugj_gpio_sleep'] = { - init: function () { - this.appendDummyInput() - .appendField(new Blockly.FieldDropdown([["1", "1"], ["3", "3"], ["5", "5"], ["10", "10"]]), "sec") - .appendField("秒間プログラムを強制的に停止する"); - this.setInputsInline(true); - this.setPreviousStatement(true, null); - this.setNextStatement(true, null); - this.setStyle('gpio_blocks') - this.setTooltip("実行環境全体を完全に一時停止します。停止中はすべての操作ができなくなります。※実験用"); - this.setHelpUrl(""); - } -}; -Blockly.JavaScript['ugj_gpio_sleep'] = function (block) { - var dropdown_sec = block.getFieldValue('sec'); - var code = `pi.usleep(${dropdown_sec} * 1000000);\n`; - return code; +Blockly.Python['ugj_i2c_read_byte_data'] = function (block) { + var value_reg = Blockly.Python.valueToCode(block, 'reg', Blockly.Python.ORDER_ATOMIC); + var code = `pi.i2c_read_byte_data(i2c_hand, ${value_reg})\n`; + return [code, Blockly.Python.ORDER_NONE]; }; + /** Multimedia *****************************************************************************************************/ /******************* */ diff --git a/scripts/ugj_script.js b/scripts/ugj_script.js index 1ad17ed..591f157 100644 --- a/scripts/ugj_script.js +++ b/scripts/ugj_script.js @@ -76,12 +76,39 @@ Blockly.Msg["UGJ_FOREACH_TITLE"] = "リスト %1 の各 %2 について %3 %4"; Blockly.Msg["UGJ_FOREACH_ITEM"] = "項目"; Blockly.Msg["UGJ_FOREACH_TOOLTIP"] = "リストの各項目について、その項目を変数「項目」としてステートメントを実行します。"; -Blockly.Msg["GPIO_START_TITLE"] = "GPIO を使えるようにする"; -Blockly.Msg["GPIO_START_TOOLTIP"] = "GPIOを初期化して接続します。"; -Blockly.Msg["GPIO_STOP_TITLE"] = "GPIO の後片付けをする"; -Blockly.Msg["GPIO_STOP_TOOLTIP"] = "GPIOとの接続を終了します。"; -Blockly.Msg["GPIO_START_REMOTE_TITLE"] = "ホスト %1 のGPIO を使えるようにする"; -Blockly.Msg["GPIO_START_REMOTE_TOOLTIP"] = "他のマシンのリモートGPIOに接続します。"; +Blockly.Msg["GPIOCHIP_OPEN_TITLE"] = "GPIO を使えるようにする"; +Blockly.Msg["GPIOCHIP_OPEN_TOOLTIP"] = "GPIOを初期化して接続します。"; +Blockly.Msg["GPIOCHIP_CLOSE_TITLE"] = "GPIO の後片付けをする"; +Blockly.Msg["GPIOCHIP_CLOSE_TOOLTIP"] = "GPIOとの接続を終了します。"; +Blockly.Msg["GPIOCHIP_CLOSE_TITLE"] = "GPIO の後片付けをする"; +Blockly.Msg["GPIO_CLAIM_INPUT_TITLE"] = "GPIO %1 を入力モードにして %2"; +Blockly.Msg["GPIO_CLAIM_INPUT_TOOLTIP"] = "GPIO端子を入力モードにして、プルアップ・プルダウン・無しを設定します。"; +Blockly.Msg["GPIO_CLAIM_OUTPUT_TITLE"] = "GPIO %1 を出力モードにする"; +Blockly.Msg["GPIO_CLAIM_OUTPUT_TOOLTIP"] = "GPIO端子のモードを出力に設定します。"; +Blockly.Msg["GPIO_READ_TITLE"] = "GPIO %1 の値"; +Blockly.Msg["GPIO_READ_TOOLTIP"] = "GPIO端子の値をデジタル値(0または1)で読み取ります。"; +Blockly.Msg["GPIO_WRITE_TITLE"] = "GPIO %1 の値を %2 にする"; +Blockly.Msg["GPIO_WRITE_TOOLTIP"] = "GPIO端子の値をデジタル値(0または1)で出力します。"; +Blockly.Msg["TX_SERVO_TITLE"] = "GPIO %1 のサーボモータの回転を %2 にする"; +Blockly.Msg["TX_SERVO_TOOLTIP"] = "サーボモータの回転をパルス幅(1000~2000μsec)までの数値で指定します。"; +Blockly.Msg["TX_PWM_TITLE"] = "PWM : GPIO %1 に、パルス周波数 %2 Hz, デューティー比 %3 %%で出力"; +Blockly.Msg["TX_PWM_TOOLTIP"] = "パルス周波数をセットして、GPIO端子がPWM出力できるようにします。レンジは100固定です。"; +Blockly.Msg["I2C_OPEN_TITLE"] = "アドレス %1 の I2C デバイスを開く"; +Blockly.Msg["I2C_OPEN_TOOLTIP"] = "I2C接続されたデバイスとの通信を開始します。一度にオープンできるI2Cデバイスはひとつだけです。"; +Blockly.Msg["SERIAL_OPEN_TITLE"] = "シリアルポート %1 を速度 %2 bpsで開く"; +Blockly.Msg["SERIAL_OPEN_TOOLTIP"] = "シリアルデバイスとの接続を開きます。"; +Blockly.Msg["SERIAL_CLOSE_TITLE"] = "シリアルポートを閉じる"; +Blockly.Msg["SERIAL_CLOSE_TOOLTIP"] = "シリアルデバイスとの接続を閉じます。"; +Blockly.Msg["SERIAL_WRITE_TITLE"] = "シリアルポートに %1 を送信する"; +Blockly.Msg["SERIAL_WRITE_TOOLTIP"] = "シリアル接続されたデバイスにデータを送信します。シリアルポートは開かれていなくてはいけません。"; +Blockly.Msg["SERIAL_READ_TITLE"] = "シリアルポートから %1 文字読み込む"; +Blockly.Msg["SERIAL_READ_TOOLTIP"] = "オープン済みシリアルポートから、指定のバイト数だけデータを読み込みます。"; +Blockly.Msg["I2C_CLOSE_TITLE"] = "I2C デバイスを閉じる"; +Blockly.Msg["I2C_CLOSE_TOOLTIP"] = "I2C接続されたデバイスと通信を切断します。"; +Blockly.Msg["I2C_WRITE_BYTE_DATA_TITLE"] = "レジスタ %1 に %2 を書き込む"; +Blockly.Msg["I2C_WRITE_BYTE_DATA_TOOLTIP"] = "デバイスの指定されたレジスタに1バイトを書き込みます。"; +Blockly.Msg["I2C_READ_BYTE_DATA_TITLE"] = "レジスタ %1 の値"; +Blockly.Msg["I2C_READ_BYTE_DATA_TOOLTIP"] = "デバイスの指定されたレジスタから1バイトを読み込みます。"; Blockly.Msg["UGJ_CANVAS_INIT_TITLE"] = "キャンバスを表示"; Blockly.Msg["UGJ_CANVAS_INIT_TOOLTIP"] = "キャンバスを表示し、使用できるようにします。";