diff --git a/00scratch/dualmotor2.sb2 b/00scratch/dualmotor2.sb2 new file mode 100644 index 0000000..00da816 Binary files /dev/null and b/00scratch/dualmotor2.sb2 differ diff --git a/00scratch/twin-motor.sb2 b/00scratch/motor-test.sb2 similarity index 100% rename from 00scratch/twin-motor.sb2 rename to 00scratch/motor-test.sb2 diff --git a/00scratch/s2microbit_EN_nowait.s2e b/00scratch/s2microbit_EN_nowait.s2e new file mode 100644 index 0000000..7d7d2da --- /dev/null +++ b/00scratch/s2microbit_EN_nowait.s2e @@ -0,0 +1,222 @@ +{ + "extensionName": "s2microbit-ble", + "extensionPort": 50209, + "url": "https://github.com/memakura/s2microbit-ble", + "blockSpecs": [ + [ + " ", + "Display %m.images", + "display_image", + "HAPPY" + ], + [ + " ", + "Scroll %s", + "scroll", + "Hello!" + ], + [ + " ", + "Write Pixel X %n Y %n Intensity %m.val", + "write_pixel", + "0", + "0", + "1" + ], + [ + " ", + "Display pattern %n", + "display_pattern", + "11001 01111 01110 11110 10011" + ], + [ + " ", + "Clear Display", + "display_clear" + ], + [ + " ", + "Setup Pin %m.pins as %m.admodes %m.iomodes", + "setup_pin", + "0", + "Digital", + "Output" + ], + [ + " ", + "Digital Write Pin %m.pins Value %m.val", + "digital_write", + "0", + "0" + ], + [ + " ", + "Analog Write Pin %m.pins Value %n", + "analog_write", + "0", + "0" + ], + [ + "b", + "Button A pressed?", + "button_a_pressed" + ], + [ + "b", + "Button B pressed?", + "button_b_pressed" + ], + [ + "b", + "Tilted right?", + "tilted_right" + ], + [ + "b", + "Tilted left?", + "tilted_left" + ], + [ + "b", + "Tilted up?", + "tilted_up" + ], + [ + "b", + "Tilted down?", + "tilted_down" + ], + [ + "b", + "Shaken?", + "shaken" + ], + [ + "r", + "Digital Read Pin %m.pins", + "digital_read", + "0" + ], + [ + "r", + "Analog Read Pin %m.ain_pins", + "analog_read", + "0" + ], + [ + "r", + "Temperature", + "temperature" + ], + [ + "r", + "Magnetometer Bearing", + "magBearing" + ], + [ + "r", + "Magnetometer X", + "mag_x" + ], + [ + "r", + "Magnetometer Y", + "mag_y" + ], + [ + "r", + "Magnetometer Z", + "mag_z" + ], + [ + "r", + "Accelerometer X", + "acc_x" + ], + [ + "r", + "Accelerometer Y", + "acc_y" + ], + [ + "r", + "Accelerometer Z", + "acc_z" + ] + ], + "menus": { + "images": [ + "HAPPY", + "SAD", + "ANGRY", + "SMILE", + "HEART", + "CONFUSED", + "ASLEEP", + "SURPRISED", + "SILLY", + "FABULOUS", + "MEH", + "YES", + "NO", + "TRIANGLE", + "DIAMOND", + "DIAMOND_SMALL", + "SQUARE", + "SQUARE_SMALL", + "TARGET", + "STICKFIGURE", + "RABBIT", + "COW", + "ROLLERSKATE", + "HOUSE", + "SNAKE", + "ARROW_N", + "ARROW_NE", + "ARROW_E", + "ARROW_SE", + "ARROW_S", + "ARROW_SW", + "ARROW_W", + "ARROW_NW", + "HEART_SMALL", + "TRIANGLE_LEFT", + "CHESSBOARD", + "PITCHFORK", + "XMAS", + "TSHIRT", + "SWORD", + "UMBRELLA", + "DUCK", + "TORTOISE", + "BUTTERFLY", + "GIRAFFE", + "SKULL", + "MUSIC_CROTCHET", + "MUSIC_QUAVER", + "MUSIC_QUAVERS", + "SCISSORS", + "PACMAN", + "GHOST" + ], + "pins": [ + "0", "1", "2", + "8", "13", "14", "15", "16" + ], + "ain_pins": [ + "0", "1", "2" + ], + "val": [ + "0", + "1" + ], + "iomodes": [ + "Input", + "Output" + ], + "admodes": [ + "Digital", + "Analog" + ] + } +} diff --git a/00scratch/s2microbit_JA_nowait.s2e b/00scratch/s2microbit_JA_nowait.s2e new file mode 100644 index 0000000..516c6bc --- /dev/null +++ b/00scratch/s2microbit_JA_nowait.s2e @@ -0,0 +1,222 @@ +{ + "extensionName": "s2microbit-ble", + "extensionPort": 50209, + "url": "https://github.com/memakura/s2microbit-ble", + "blockSpecs": [ + [ + " ", + "%m.images を表示", + "display_image", + "01_うれしい顔" + ], + [ + " ", + "文字列を表示 %s", + "scroll", + "Hello!" + ], + [ + " ", + "点灯 X %n Y %n 明るさ %m.val", + "write_pixel", + "0", + "0", + "1" + ], + [ + " ", + "パターン %n を表示", + "display_pattern", + "11001 01111 01110 11110 10011" + ], + [ + " ", + "表示を消す", + "display_clear" + ], + [ + " ", + "端子 %m.pins を %m.admodes %m.iomodes に使う", + "setup_pin", + "0", + "D:デジタル", + "O:出力" + ], + [ + " ", + "デジタルで出力する 端子 %m.pins 値 %m.val", + "digital_write", + "0", + "0" + ], + [ + " ", + "アナログで出力する 端子 %m.pins 値 %n", + "analog_write", + "0", + "0" + ], + [ + "b", + "ボタンAが押されている", + "button_a_pressed" + ], + [ + "b", + "ボタンBが押されている", + "button_b_pressed" + ], + [ + "b", + "右にかたむいている", + "tilted_right" + ], + [ + "b", + "左にかたむいている", + "tilted_left" + ], + [ + "b", + "おくの方が上がっている", + "tilted_up" + ], + [ + "b", + "おくの方が下がっている", + "tilted_down" + ], + [ + "b", + "ゆさぶられている", + "shaken" + ], + [ + "r", + "デジタルで読み取る 端子 %m.pins", + "digital_read", + "0" + ], + [ + "r", + "アナログ値を読み取る 端子 %m.ain_pins", + "analog_read", + "0" + ], + [ + "r", + "温度", + "temperature" + ], + [ + "r", + "磁気センサ角度", + "magBearing" + ], + [ + "r", + "磁気センサ X", + "mag_x" + ], + [ + "r", + "磁気センサ Y", + "mag_y" + ], + [ + "r", + "磁気センサ Z", + "mag_z" + ], + [ + "r", + "加速度センサ X", + "acc_x" + ], + [ + "r", + "加速度センサ Y", + "acc_y" + ], + [ + "r", + "加速度センサ Z", + "acc_z" + ] + ], + "menus": { + "images": [ + "01_うれしい顔", + "02_かなしい顔", + "03_おこり顔", + "04_スマイル", + "05_ハート", + "06_こまり顔", + "07_ねてる顔", + "08_びっくり顔", + "09_へん顔", + "10_すばらしい", + "11_ふーん", + "12_チェック", + "13_バツ", + "14_三角", + "15_ダイアモンド", + "16_小さいダイアモンド", + "17_しかく", + "18_小さいしかく", + "19_まと", + "20_棒人間", + "21_うさぎ", + "22_うし", + "23_ローラースケート", + "24_家", + "25_へび", + "26_上矢印", + "27_右上矢印", + "28_右矢印", + "29_右下矢印", + "30_下矢印", + "31_左下矢印", + "32_左矢印", + "33_左上矢印", + "34_小さいハート", + "35_左向き三角", + "36_チェスボード", + "37_くまで", + "38_クリスマス", + "39_Tシャツ", + "40_剣", + "41_かさ", + "42_あひる", + "43_かめ", + "44_ちょうちょ", + "45_きりん", + "46_がいこつ", + "47_四分音符", + "48_八分音符", + "49_二連符", + "50_はさみ", + "51_パックマン", + "52_おばけ" + ], + "pins": [ + "0", "1", "2", + "8", "13", "14", "15", "16" + ], + "ain_pins": [ + "0", "1", "2" + ], + "val": [ + "0", + "1" + ], + "iomodes": [ + "I:入力", + "O:出力" + ], + "admodes": [ + "D:デジタル", + "A:アナログ" + ] + } +} diff --git a/app/s2microbit-ble.js b/app/s2microbit-ble.js index ec5adc8..67aee5e 100644 --- a/app/s2microbit-ble.js +++ b/app/s2microbit-ble.js @@ -563,12 +563,12 @@ function writeLedBuffer(error) { //--- LED display preset image // nowait block exapp.get('/display_image/:name', function(req, res) { - logBothConsole('no command'); // if (debug) + if (debug) logBothConsole('no command'); res.send(display_image(false, req.params.name)); }); // wait block exapp.get('/display_image/:command_id/:name', function(req, res) { - logBothConsole('command_id: ' + req.params.command_id); // if (debug) + if (debug) logBothConsole('command_id: ' + req.params.command_id); res.send(display_image(req.params.command_id, req.params.name)); }); function display_image(command_id, name) { @@ -590,12 +590,12 @@ function display_image(command_id, name) { //--- LED dot // nowait block exapp.get('/write_pixel/:x/:y/:value', function(req, res){ - logBothConsole('no command'); // if (debug) + if (debug) logBothConsole('no command'); res.send(write_pixel(false, req.params.x, req.params.y, req.params.value)); }); // wait block exapp.get('/write_pixel/:command_id/:x/:y/:value', function(req, res){ - logBothConsole('command_id: ' + req.params.command_id); // if (debug) + if (debug) logBothConsole('command_id: ' + req.params.command_id); res.send(write_pixel(req.params.command_id, req.params.x, req.params.y, req.params.value)); }); function write_pixel(command_id, x, y, val) { @@ -631,19 +631,19 @@ function write_pixel(command_id, x, y, val) { //--- LED display custom pattern // nowait block exapp.get('/display_pattern/:binstr', function(req, res) { - logBothConsole('no command'); // if (debug) + if (debug) logBothConsole('no command'); res.send(display_pattern(false, req.params.binstr)); }); // wait block exapp.get('/display_pattern/:command_id/:binstr', function(req, res) { - logBothConsole('command_id: ' + req.params.command_id); // if (debug) + if (debug) logBothConsole('command_id: ' + req.params.command_id); res.send(display_pattern(req.params.command_id, req.params.binstr)); }); function display_pattern(command_id, binstr) { if (device !== null) { if (command_id) waiting_commands.add(command_id); try { - logBothConsole('microbit: [display_pattern] str= ' + binstr); + logBothConsole('[display_pattern] ' + binstr); // check if ( ! /^[01]{5} [01]{5} [01]{5} [01]{5} [01]{5}$/.test(binstr) ) { logBothConsole('error: illegal pattern'); @@ -678,12 +678,12 @@ function display_pattern(command_id, binstr) { //--- clear LED // nowait block exapp.get('/display_clear', function(req, res){ - logBothConsole('no command'); // if (debug) + if (debug) logBothConsole('no command'); res.send(display_clear(false)); }); // wait block exapp.get('/display_clear/:command_id', function(req, res){ - logBothConsole('command_id: ' + req.params.command_id); // if (debug) + if (debug) logBothConsole('command_id: ' + req.params.command_id); res.send(display_clear(req.params.command_id)); }); function display_clear(command_id) { @@ -706,12 +706,12 @@ function display_clear(command_id) { //--- Setup pin mode // nowait block exapp.get('/setup_pin/:pin/:admode/:iomode', function(req, res) { - logBothConsole('no command_id'); // if (debug) + if (debug) logBothConsole('no command_id'); res.send(setup_pin(false, req.params.pin, req.params.admode, req.params.iomode)); }); // wait block exapp.get('/setup_pin/:command_id/:pin/:admode/:iomode', function(req, res) { - logBothConsole('command_id: ' + req.params.command_id); // if (debug) + if (debug) logBothConsole('command_id: ' + req.params.command_id); res.send(setup_pin(req.params.command_id, req.params.pin, req.params.admode, req.params.iomode)); }); function setup_pin(command_id, pin, admode, iomode) { @@ -757,12 +757,12 @@ function setup_pin(command_id, pin, admode, iomode) { //--- Digital write // nowait block exapp.get('/digital_write/:pin/:value', function(req, res) { - logBothConsole('no command_id'); // if (debug) + if (debug) logBothConsole('no command_id'); res.send(digital_write(false, req.params.pin, req.params.value)); }); // wait block exapp.get('/digital_write/:command_id/:pin/:value', function(req, res) { - logBothConsole('command_id: ' + req.params.command_id); // if (debug) + if (debug) logBothConsole('command_id: ' + req.params.command_id); res.send(digital_write(req.params.command_id, req.params.pin, req.params.value)); }); function digital_write(command_id, pin, value) { @@ -806,11 +806,11 @@ function digital_write(command_id, pin, value) { //--- Analog write exapp.get('/analog_write/:pin/:value', function(req, res) { - logBothConsole('no command_id'); // if (debug) + if (debug) logBothConsole('no command_id'); res.send(analog_write(false, req.params.pin, req.params.value)); }); exapp.get('/analog_write/:command_id/:pin/:value', function(req, res) { - logBothConsole('command_id: ' + req.params.command_id); // if (debug) + if (debug) logBothConsole('command_id: ' + req.params.command_id); res.send(analog_write(req.params.command_id, req.params.pin, req.params.value)); }); function analog_write(command_id, pin, value) {