diff --git a/app/index.html b/app/index.html index cf9750f..488e4bb 100644 --- a/app/index.html +++ b/app/index.html @@ -1,55 +1,65 @@ - + - + s2microbit-ble -
-
- - - -
-
s2microbit-ble
-
-
- Scratch 2 Offline Extension for BBC micro:bit -
- 使い方 - プロジェクトページ - しくみ -
- - -
-

Scratch2プロジェクトとブロック拡張

- 豆猫 - 飛ぶ - いろいろ - ブロック (s2e) - -

Scratch2 projects and block extension

- cat - fly - small tests - block (s2e) - -

micro:bitへ転送しておくHEXファイル

- hex -
-

+
+
+
+
+ + + +
+
s2microbit-ble
+
+
+ Scratch 2 Offline Extension for BBC micro:bit +
+ + + +
+

Scratch2プロジェクトとブロック拡張

+ + +

Scratch2 projects and block extension

+ + +

micro:bitへ転送しておくHEXファイル

+ +
+

+
+
+
+
+
diff --git a/app/package.json b/app/package.json index 1fae926..e9aa68e 100644 --- a/app/package.json +++ b/app/package.json @@ -1,6 +1,6 @@ { "name": "s2microbit-ble", - "version": "2.2.2", + "version": "2.3.0", "description": "BBC micro:bit (bluetooth)", "main": "s2microbit-ble.js", "scripts": { diff --git a/app/renderer.css b/app/renderer.css index 960e69c..3e920a1 100644 --- a/app/renderer.css +++ b/app/renderer.css @@ -1,3 +1,40 @@ +#container { + display: grid; + grid-template-columns: 390px 1fr; +} +#main_pane { + grid-row: 1 / 2; + grid-column: 1 / 2; +} +#log_pane { + grid-row: 1 / 2; + grid-column: 2 / 3; +} + +#console_log { + height: 90vh; /* should be viewport height to use overflow, not '%' */ + padding: 0.2em 0.5em; + margin: 10px 15px 10px 0px; + color: #666; + background: #d6ebff; + box-shadow: 0px 0px 0px 10px #d6ebff; + border: dashed 2px white; + overflow: auto; /* scroll */ + border-radius: 130px 10px 110px 10px / 10px 130px 10px 110px; +} +::-webkit-scrollbar { + width: 10px; +} +::-webkit-scrollbar-track { + border-radius: 10px; + box-shadow: inset 0 0 6px rgba(0, 0, 0, .1); +} +::-webkit-scrollbar-thumb { + background-color: rgba(0, 0, 50, .5); + border-radius: 10px; + box-shadow:0 0 0 1px rgba(255, 255, 255, .3); +} + .basefont-ja { font-size: 16px; color: #666; @@ -38,20 +75,25 @@ transform: translateX(-50%); } .title-icon { - margin: 0 0 0 0; + margin: 0px 0px 0px 0px; } .abstract { - text-align: center; - margin: 0 0 24px 0; + /* text-align: center; */ + margin: 0px 0px 24px 30px; +} +.help-links { + /* text-align: center; */ + margin: 0px 0px 0px 30px; } - .projects p { - margin: 30px 0px 10px 0px; - background: linear-gradient(transparent 70%, #ffe798 70%); - width: 90%; + margin: 30px 0px 10px 5px; + background: linear-gradient(transparent 60%, #ffdb98 70%); + width: 80%; } - -.square_btn{ +.project-links { + margin: 0px 0px 0px 20px; +} +.square-btn{ position: relative; display: inline-block; font-weight: bold; @@ -62,7 +104,7 @@ transition: .4s; } -.square_btn:hover { +.square-btn:hover { background: #00bcd4; /* #008a9c; */ /* #668ad8; */ color: white; } diff --git a/app/renderer.js b/app/renderer.js index 4e08750..3d7311d 100644 --- a/app/renderer.js +++ b/app/renderer.js @@ -1,9 +1,16 @@ "use strict"; -const { shell } = require('electron'); +const { ipcRenderer, shell } = require('electron'); const $ = require('jquery'); //const open = require('open'); +ipcRenderer.on('mainmsg', function (event, msg) { + //console.log("[main] " + msg); + var divLogElem = document.getElementById('console_log'); + divLogElem.innerHTML += msg + "
"; + divLogElem.scrollTop = divLogElem.scrollHeight; +}); + // left button $(document).on('click', 'a[href^="http"]', function (event) { event.preventDefault(); @@ -14,6 +21,6 @@ $(document).on('click', 'a[href^="http"]', function (event) { $(document).on('mousedown', 'a[href^="http"]', function (event) { if(event.which==2) { event.preventDefault(); - shell.openExternal(this.href); + shell.openExternal(this.href); } }); diff --git a/app/s2microbit-ble.js b/app/s2microbit-ble.js index 91e690e..1192d7b 100644 --- a/app/s2microbit-ble.js +++ b/app/s2microbit-ble.js @@ -7,16 +7,21 @@ const { app, ipcMain, BrowserWindow } = require('electron'); const path = require('path'); const url = require('url'); +const BBCMicrobit = require('bbc-microbit'); +let device = null; +let microbitConnected = false; + // Keep a global reference of the window object, if you don't, the window will // be closed automatically when the JavaScript object is garbage collected. let mainWindow; + function createWindow () { // Create the browser window. mainWindow = new BrowserWindow({ - width: 960, - height: 600 + width: 820, + height: 730 }); // and load the index.html of the app. @@ -27,10 +32,12 @@ function createWindow () { })); // Open the DevTools. - mainWindow.webContents.openDevTools(); + //mainWindow.webContents.openDevTools(); mainWindow.webContents.on('did-finish-load', function() { // Find microbits - microbitScanner(); + if (device === null) { + microbitScanner(); + } }); // Emitted when the window is closed. @@ -70,10 +77,6 @@ app.on('activate', function () { // https://github.com/sandeepmistry/node-bbc-microbit/blob/master/API.md -const BBCMicrobit = require('bbc-microbit'); -let device = null; -let microbitConnected = false; - const BUTTON_VALUE_MAPPER = ['Not Pressed', 'Pressed', 'Long Press']; let debug = false; @@ -194,11 +197,11 @@ function initValues () { initValues(); - console.log("=== BBC micro:bit Scratch 2.0 offline extension ==="); // createWindow (mainWindow.webContents.on('did-finish-load') ) // -> microbitScanner -> microbitFound -> connectAndSetup -> startHTTPServer + // Output log to both terminal and renderer's console (in the developer tool) function logBothConsole (msg) { console.log(msg); @@ -208,14 +211,20 @@ function logBothConsole (msg) { //var id = 'dd628ee75dfe'; var id = 'd5a250cd6035'; +//let scanning_all = false; + // Discover microbit function microbitScanner() { logBothConsole("microbit: scanning..."); - - BBCMicrobit.discoverAll( function (microbit) { - logBothConsole(" found microbit : " + microbit); - }); // find all microbits - + /* + if (!scanning_all) { + BBCMicrobit.discoverAll( function (microbit) { // keep scanning until stop is called + //logBothConsole(" found microbit : " + microbit); + logBothConsole(" found microbit : " + microbit.id); + scanning_all = true; + }); // find all microbits + } + */ //BBCMicrobit.discoverById(id, microbitFound); BBCMicrobit.discover(microbitFound); } @@ -240,7 +249,7 @@ function initializePinSetting(microbit) { // Setting up pin mode (analog/digital and input/output) function setupPinMode(data) { if (device) { - logBothConsole('setupPinMode: pin ' + data.pin + ' is originally configured as: ' + pinMode[data.pin]); + if (debug) { logBothConsole('setupPinMode: pin ' + data.pin + ' is originally configured as: ' + pinMode[data.pin]); } function log(data) { logBothConsole('microbit: setup pin ' + data.pin + ' as ' + data.ADmode + ' ' + data.IOmode); } @@ -248,13 +257,13 @@ function setupPinMode(data) { function subscribe(device, data) { log(data); device.readPin(data.pin, function(error, value) { // trigger a pinDataChange - showPinSetting(device); + if (debug) { showPinSetting(device); } }); } // UnsubscribeData function unsubscribe(device) { log(data); - showPinSetting(device); + if (debug) { showPinSetting(device); } } pinMode[data.pin] = PINMODE_OUTPUT_DIGITAL; @@ -299,6 +308,7 @@ function microbitFound(microbit) { microbitConnected = false; device = null; logBothConsole('microbit: disconnected. microbitConnected= ' + microbitConnected); + initValues(); microbitScanner(); }); @@ -440,7 +450,7 @@ exapp.get('/reset_all', function(req, res){ // LED matrix (image pattern) function writeLedBuffer(error) { device.writeLedMatrixState(ledBuffer, function(error) { - logBothConsole("microbit: writeLedBuffer: buf= " + ledBuffer.toString('hex')); + if (debug) { logBothConsole("microbit: writeLedBuffer: buf= " + ledBuffer.toString('hex')); } }); } // LED display preset image