diff --git a/boards/default/micropython_educore/config.json b/boards/default/micropython_educore/config.json index dc56b62e..ce578aa9 100644 --- a/boards/default/micropython_educore/config.json +++ b/boards/default/micropython_educore/config.json @@ -54,7 +54,11 @@ }, "pythonToBlockly": false, "web": { - "com": "serial", + "devices": { + "serial": true, + "hid": true, + "usb": false + }, "burn": { "erase": true, "micropython:esp32c2:mixgo_mini": { diff --git a/boards/default/micropython_esp32/config.json b/boards/default/micropython_esp32/config.json index 5000ff60..3a6e2f5c 100644 --- a/boards/default/micropython_esp32/config.json +++ b/boards/default/micropython_esp32/config.json @@ -63,7 +63,11 @@ }, "pythonToBlockly": false, "web": { - "com": "serial", + "devices": { + "serial": true, + "hid": true, + "usb": false + }, "burn": { "erase": true, "micropython:esp32:mixgo": { diff --git a/boards/default/micropython_esp32c3/config.json b/boards/default/micropython_esp32c3/config.json index 89a43cee..62dbefbf 100644 --- a/boards/default/micropython_esp32c3/config.json +++ b/boards/default/micropython_esp32c3/config.json @@ -63,7 +63,11 @@ }, "pythonToBlockly": false, "web": { - "com": "serial", + "devices": { + "serial": true, + "hid": true, + "usb": false + }, "burn": { "erase": true, "micropython:esp32c3:mixgo_cc": { diff --git a/boards/default/micropython_esp32s2/config.json b/boards/default/micropython_esp32s2/config.json index ed8068c2..5629bacc 100644 --- a/boards/default/micropython_esp32s2/config.json +++ b/boards/default/micropython_esp32s2/config.json @@ -75,7 +75,11 @@ }, "pythonToBlockly": false, "web": { - "com": "serial", + "devices": { + "serial": true, + "hid": true, + "usb": false + }, "burn": { "erase": true, "micropython:esp32s2:mixgo_ce": { diff --git a/boards/default/micropython_esp32s3/config.json b/boards/default/micropython_esp32s3/config.json index bb974afc..1ba01377 100644 --- a/boards/default/micropython_esp32s3/config.json +++ b/boards/default/micropython_esp32s3/config.json @@ -58,7 +58,11 @@ }, "pythonToBlockly": false, "web": { - "com": "serial", + "devices": { + "serial": true, + "hid": true, + "usb": false + }, "burn": { "erase": true, "micropython:esp32s3:mixgo_sant": { diff --git a/boards/default/micropython_k210_mixgoai/config.json b/boards/default/micropython_k210_mixgoai/config.json index 9dc1cb50..814d0f9e 100644 --- a/boards/default/micropython_k210_mixgoai/config.json +++ b/boards/default/micropython_k210_mixgoai/config.json @@ -45,7 +45,11 @@ }, "pythonToBlockly": false, "web": { - "com": "serial", + "devices": { + "serial": true, + "hid": false, + "usb": false + }, "upload": { "reset": [] } diff --git a/boards/default/micropython_nrf51822_microbit/config.json b/boards/default/micropython_nrf51822_microbit/config.json index 66070d04..0d97dc85 100644 --- a/boards/default/micropython_nrf51822_microbit/config.json +++ b/boards/default/micropython_nrf51822_microbit/config.json @@ -52,7 +52,11 @@ }, "pythonToBlockly": false, "web": { - "com": "usb", + "devices": { + "serial": false, + "hid": false, + "usb": true + }, "burn": { "micropython:nrf51822:v1": { "filePath": "./build/microbit-micropython-v1.hex" diff --git a/boards/default/micropython_nrf51822_mithoncc/config.json b/boards/default/micropython_nrf51822_mithoncc/config.json index 8ea112be..acd4bfe5 100644 --- a/boards/default/micropython_nrf51822_mithoncc/config.json +++ b/boards/default/micropython_nrf51822_mithoncc/config.json @@ -46,7 +46,11 @@ }, "pythonToBlockly": false, "web": { - "com": "usb", + "devices": { + "serial": false, + "hid": false, + "usb": true + }, "burn": { "filePath": "./build/microbit-micropython-v1.hex" } diff --git a/boards/default/micropython_robot/config.json b/boards/default/micropython_robot/config.json index 6d0b8750..0f99263e 100644 --- a/boards/default/micropython_robot/config.json +++ b/boards/default/micropython_robot/config.json @@ -83,7 +83,11 @@ }, "pythonToBlockly": false, "web": { - "com": "serial", + "devices": { + "serial": true, + "hid": true, + "usb": false + }, "burn": { "erase": true, "micropython:esp32c3:feiyi": { diff --git a/boards/default_src/micropython_educore/origin/config.json b/boards/default_src/micropython_educore/origin/config.json index dc56b62e..ce578aa9 100644 --- a/boards/default_src/micropython_educore/origin/config.json +++ b/boards/default_src/micropython_educore/origin/config.json @@ -54,7 +54,11 @@ }, "pythonToBlockly": false, "web": { - "com": "serial", + "devices": { + "serial": true, + "hid": true, + "usb": false + }, "burn": { "erase": true, "micropython:esp32c2:mixgo_mini": { diff --git a/boards/default_src/micropython_esp32/origin/config.json b/boards/default_src/micropython_esp32/origin/config.json index 5000ff60..3a6e2f5c 100644 --- a/boards/default_src/micropython_esp32/origin/config.json +++ b/boards/default_src/micropython_esp32/origin/config.json @@ -63,7 +63,11 @@ }, "pythonToBlockly": false, "web": { - "com": "serial", + "devices": { + "serial": true, + "hid": true, + "usb": false + }, "burn": { "erase": true, "micropython:esp32:mixgo": { diff --git a/boards/default_src/micropython_esp32c3/origin/config.json b/boards/default_src/micropython_esp32c3/origin/config.json index 89a43cee..62dbefbf 100644 --- a/boards/default_src/micropython_esp32c3/origin/config.json +++ b/boards/default_src/micropython_esp32c3/origin/config.json @@ -63,7 +63,11 @@ }, "pythonToBlockly": false, "web": { - "com": "serial", + "devices": { + "serial": true, + "hid": true, + "usb": false + }, "burn": { "erase": true, "micropython:esp32c3:mixgo_cc": { diff --git a/boards/default_src/micropython_esp32s2/origin/config.json b/boards/default_src/micropython_esp32s2/origin/config.json index ed8068c2..5629bacc 100644 --- a/boards/default_src/micropython_esp32s2/origin/config.json +++ b/boards/default_src/micropython_esp32s2/origin/config.json @@ -75,7 +75,11 @@ }, "pythonToBlockly": false, "web": { - "com": "serial", + "devices": { + "serial": true, + "hid": true, + "usb": false + }, "burn": { "erase": true, "micropython:esp32s2:mixgo_ce": { diff --git a/boards/default_src/micropython_esp32s3/origin/config.json b/boards/default_src/micropython_esp32s3/origin/config.json index bb974afc..1ba01377 100644 --- a/boards/default_src/micropython_esp32s3/origin/config.json +++ b/boards/default_src/micropython_esp32s3/origin/config.json @@ -58,7 +58,11 @@ }, "pythonToBlockly": false, "web": { - "com": "serial", + "devices": { + "serial": true, + "hid": true, + "usb": false + }, "burn": { "erase": true, "micropython:esp32s3:mixgo_sant": { diff --git a/boards/default_src/micropython_k210_mixgoai/origin/config.json b/boards/default_src/micropython_k210_mixgoai/origin/config.json index 9dc1cb50..814d0f9e 100644 --- a/boards/default_src/micropython_k210_mixgoai/origin/config.json +++ b/boards/default_src/micropython_k210_mixgoai/origin/config.json @@ -45,7 +45,11 @@ }, "pythonToBlockly": false, "web": { - "com": "serial", + "devices": { + "serial": true, + "hid": false, + "usb": false + }, "upload": { "reset": [] } diff --git a/boards/default_src/micropython_nrf51822_microbit/origin/config.json b/boards/default_src/micropython_nrf51822_microbit/origin/config.json index 66070d04..0d97dc85 100644 --- a/boards/default_src/micropython_nrf51822_microbit/origin/config.json +++ b/boards/default_src/micropython_nrf51822_microbit/origin/config.json @@ -52,7 +52,11 @@ }, "pythonToBlockly": false, "web": { - "com": "usb", + "devices": { + "serial": false, + "hid": false, + "usb": true + }, "burn": { "micropython:nrf51822:v1": { "filePath": "./build/microbit-micropython-v1.hex" diff --git a/boards/default_src/micropython_nrf51822_mithoncc/origin/config.json b/boards/default_src/micropython_nrf51822_mithoncc/origin/config.json index 8ea112be..acd4bfe5 100644 --- a/boards/default_src/micropython_nrf51822_mithoncc/origin/config.json +++ b/boards/default_src/micropython_nrf51822_mithoncc/origin/config.json @@ -46,7 +46,11 @@ }, "pythonToBlockly": false, "web": { - "com": "usb", + "devices": { + "serial": false, + "hid": false, + "usb": true + }, "burn": { "filePath": "./build/microbit-micropython-v1.hex" } diff --git a/boards/default_src/micropython_robot/origin/config.json b/boards/default_src/micropython_robot/origin/config.json index 6d0b8750..0f99263e 100644 --- a/boards/default_src/micropython_robot/origin/config.json +++ b/boards/default_src/micropython_robot/origin/config.json @@ -83,7 +83,11 @@ }, "pythonToBlockly": false, "web": { - "com": "serial", + "devices": { + "serial": true, + "hid": true, + "usb": false + }, "burn": { "erase": true, "micropython:esp32c3:feiyi": { diff --git a/common/main.js b/common/main.js index 744ec571..f1d9f334 100644 --- a/common/main.js +++ b/common/main.js @@ -23,67 +23,6 @@ LazyLoad.js([ COMMON_DIR_PATH + '/blockly-core/base.js', COMMON_DIR_PATH + '/modules/web-modules/jquery/jquery-3.7.1.min.js' ], function() { - - /** - * debounce - * @param {integer} milliseconds This param indicates the number of milliseconds - * to wait after the last call before calling the original function. - * @param {object} What "this" refers to in the returned function. - * @return {function} This returns a function that when called will wait the - * indicated number of milliseconds after the last call before - * calling the original function. - */ - Function.prototype.debounce = function (milliseconds, context) { - var baseFunction = this, - timer = null, - wait = milliseconds; - - return function () { - var self = context || this, - args = arguments; - - function complete() { - baseFunction.apply(self, args); - timer = null; - } - - if (timer) { - clearTimeout(timer); - } - - timer = setTimeout(complete, wait); - }; - }; - - /** - * throttle - * @param {integer} milliseconds This param indicates the number of milliseconds - * to wait between calls before calling the original function. - * @param {object} What "this" refers to in the returned function. - * @return {function} This returns a function that when called will wait the - * indicated number of milliseconds between calls before - * calling the original function. - */ - Function.prototype.throttle = function (milliseconds, context) { - var baseFunction = this, - lastEventTimestamp = null, - limit = milliseconds, - debounceFunc = baseFunction.debounce(milliseconds, context); - - return function () { - var self = context || this, - args = arguments, - now = Date.now(); - - if (!lastEventTimestamp || now - lastEventTimestamp >= limit) { - lastEventTimestamp = now; - baseFunction.apply(self, args); - } - - debounceFunc.apply(self, args); - }; - }; - /** * 当前视图 * @type {string} 主页面 home | 板卡页面 board @@ -143,8 +82,31 @@ LazyLoad.js([ if (userAgent.indexOf('Mac') !== -1) return 'darwin'; if (userAgent.indexOf('X11') !== -1) return 'linux'; if (userAgent.indexOf('Linux') !== -1) return 'linux'; - return 'other'; - } + return 'unknown'; + } + + goog.fullPlatform = () => { + const userAgent = navigator.userAgent; + const platform = navigator.platform.toLowerCase(); + let os = 'unknown'; + if (platform.includes('win')) { + if (userAgent.indexOf('Windows NT 10.0') != -1) os = 'win10'; + else if (userAgent.indexOf('Windows NT 6.3') != -1) os = 'win8.1'; + else if (userAgent.indexOf('Windows NT 6.2') != -1) os = 'win8'; + else if (userAgent.indexOf('Windows NT 6.1') != -1) os = 'win7'; + else if (userAgent.indexOf('Windows NT 6.0') != -1) os = 'winvista'; + else if (userAgent.indexOf('Windows NT 5.1') != -1) os = 'winxp'; + } else if (platform.includes('mac')) { + os = 'darwin'; + } else if (platform.includes('linux')) { + os = 'linux'; + } else if (platform.includes('iphone') || platform.includes('ipad')) { + os = 'ios'; + } else if (platform.includes('android')) { + os = 'android'; + } + return os; + } /** * @function 根据传入的相对路径获取文件数据 diff --git a/common/modules/mixly-modules/web/serial.js b/common/modules/mixly-modules/web/serial.js index 2302a5c1..29e72ce0 100644 --- a/common/modules/mixly-modules/web/serial.js +++ b/common/modules/mixly-modules/web/serial.js @@ -19,10 +19,24 @@ const { BOARD } = Config; let Device = SerialPort; -if (BOARD?.web?.com === 'usb') { +if (goog.platform() === 'win32' && goog.fullPlatform() !== 'win10') { + if (BOARD?.web?.devices?.hid) { + Device = HID; + } else if (BOARD?.web?.devices?.serial) { + Device = SerialPort; + } else if (BOARD?.web?.devices?.usb) { + Device = USB; + } +} else if (goog.platform() === 'android') { Device = USB; -} else if (BOARD?.web?.com === 'hid') { - Device = HID; +} else { + if (BOARD?.web?.devices?.serial) { + Device = SerialPort; + } else if (BOARD?.web?.devices?.usb) { + Device = USB; + } else if (BOARD?.web?.devices?.hid) { + Device = HID; + } }