Update: 在线版添加devices配置项

This commit is contained in:
王立帮
2025-01-16 10:33:08 +08:00
parent 3a3fc5c8bf
commit fa78011344
20 changed files with 132 additions and 84 deletions

View File

@@ -54,7 +54,11 @@
},
"pythonToBlockly": false,
"web": {
"com": "serial",
"devices": {
"serial": true,
"hid": true,
"usb": false
},
"burn": {
"erase": true,
"micropython:esp32c2:mixgo_mini": {

View File

@@ -63,7 +63,11 @@
},
"pythonToBlockly": false,
"web": {
"com": "serial",
"devices": {
"serial": true,
"hid": true,
"usb": false
},
"burn": {
"erase": true,
"micropython:esp32:mixgo": {

View File

@@ -63,7 +63,11 @@
},
"pythonToBlockly": false,
"web": {
"com": "serial",
"devices": {
"serial": true,
"hid": true,
"usb": false
},
"burn": {
"erase": true,
"micropython:esp32c3:mixgo_cc": {

View File

@@ -75,7 +75,11 @@
},
"pythonToBlockly": false,
"web": {
"com": "serial",
"devices": {
"serial": true,
"hid": true,
"usb": false
},
"burn": {
"erase": true,
"micropython:esp32s2:mixgo_ce": {

View File

@@ -58,7 +58,11 @@
},
"pythonToBlockly": false,
"web": {
"com": "serial",
"devices": {
"serial": true,
"hid": true,
"usb": false
},
"burn": {
"erase": true,
"micropython:esp32s3:mixgo_sant": {

View File

@@ -45,7 +45,11 @@
},
"pythonToBlockly": false,
"web": {
"com": "serial",
"devices": {
"serial": true,
"hid": false,
"usb": false
},
"upload": {
"reset": []
}

View File

@@ -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"

View File

@@ -46,7 +46,11 @@
},
"pythonToBlockly": false,
"web": {
"com": "usb",
"devices": {
"serial": false,
"hid": false,
"usb": true
},
"burn": {
"filePath": "./build/microbit-micropython-v1.hex"
}

View File

@@ -83,7 +83,11 @@
},
"pythonToBlockly": false,
"web": {
"com": "serial",
"devices": {
"serial": true,
"hid": true,
"usb": false
},
"burn": {
"erase": true,
"micropython:esp32c3:feiyi": {

View File

@@ -54,7 +54,11 @@
},
"pythonToBlockly": false,
"web": {
"com": "serial",
"devices": {
"serial": true,
"hid": true,
"usb": false
},
"burn": {
"erase": true,
"micropython:esp32c2:mixgo_mini": {

View File

@@ -63,7 +63,11 @@
},
"pythonToBlockly": false,
"web": {
"com": "serial",
"devices": {
"serial": true,
"hid": true,
"usb": false
},
"burn": {
"erase": true,
"micropython:esp32:mixgo": {

View File

@@ -63,7 +63,11 @@
},
"pythonToBlockly": false,
"web": {
"com": "serial",
"devices": {
"serial": true,
"hid": true,
"usb": false
},
"burn": {
"erase": true,
"micropython:esp32c3:mixgo_cc": {

View File

@@ -75,7 +75,11 @@
},
"pythonToBlockly": false,
"web": {
"com": "serial",
"devices": {
"serial": true,
"hid": true,
"usb": false
},
"burn": {
"erase": true,
"micropython:esp32s2:mixgo_ce": {

View File

@@ -58,7 +58,11 @@
},
"pythonToBlockly": false,
"web": {
"com": "serial",
"devices": {
"serial": true,
"hid": true,
"usb": false
},
"burn": {
"erase": true,
"micropython:esp32s3:mixgo_sant": {

View File

@@ -45,7 +45,11 @@
},
"pythonToBlockly": false,
"web": {
"com": "serial",
"devices": {
"serial": true,
"hid": false,
"usb": false
},
"upload": {
"reset": []
}

View File

@@ -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"

View File

@@ -46,7 +46,11 @@
},
"pythonToBlockly": false,
"web": {
"com": "usb",
"devices": {
"serial": false,
"hid": false,
"usb": true
},
"burn": {
"filePath": "./build/microbit-micropython-v1.hex"
}

View File

@@ -83,7 +83,11 @@
},
"pythonToBlockly": false,
"web": {
"com": "serial",
"devices": {
"serial": true,
"hid": true,
"usb": false
},
"burn": {
"erase": true,
"micropython:esp32c3:feiyi": {

View File

@@ -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 根据传入的相对路径获取文件数据

View File

@@ -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;
}
}