feat(core): 支持通过web usb烧录固件

This commit is contained in:
王立帮
2025-10-24 16:07:57 +08:00
parent 42acf014f0
commit ed9a91afdc
10 changed files with 307 additions and 438 deletions

View File

@@ -21,6 +21,7 @@ goog.require('Mixly.LayerFirmware');
goog.require('Mixly.LayerProgress');
goog.require('Mixly.Web.Serial');
goog.require('Mixly.Web.Ampy');
goog.require('Mixly.Web.SerialTransport');
goog.provide('Mixly.Web.BU');
const {
@@ -42,11 +43,13 @@ const {
const {
Serial,
BU,
Ampy
Ampy,
SerialTransport
} = Web;
const { BOARD, SELECTED_BOARD } = Config;
const { ESPLoader, Transport } = esptooljs;
const { ESPLoader } = esptooljs;
BU.uploading = false;
BU.burning = false;
@@ -246,7 +249,7 @@ BU.burnWithEsptool = async (binFile, erase) => {
}
}
const port = Serial.getPort(portName);
if (['HIDDevice', 'USBDevice'].includes(port.constructor.name)) {
if (['HIDDevice'].includes(port.constructor.name)) {
layer.msg(Msg.Lang['burn.notSupport'], { time: 1000 });
return;
}
@@ -264,13 +267,14 @@ BU.burnWithEsptool = async (binFile, erase) => {
let transport = null;
try {
const baudrate = Boards.getSelectedBoardConfigParam('BurnSpeed') ?? '460800';
transport = new Transport(port, false);
const serial = new Serial(portName);
transport = new SerialTransport(serial, false);
esploader = new ESPLoader({
transport,
baudrate,
terminal: {
clean() {
statusBarTerminal.setValue('');
statusBarTerminal.setValue(Msg.Lang['shell.burning'] + '...\n');
},
writeLine(data) {
statusBarTerminal.addValue(data + '\n');
@@ -290,6 +294,7 @@ BU.burnWithEsptool = async (binFile, erase) => {
Debug.error(error);
}
BU.progressLayer.hide();
statusBarTerminal.addValue(`==${Msg.Lang['shell.burnFailed']}==\n`);
return;
}
@@ -299,8 +304,6 @@ BU.burnWithEsptool = async (binFile, erase) => {
for (let i of binFile) {
if (i.path && i.offset) {
let absolutePath = path.join(Env.boardDirPath, i.path);
// statusBarTerminal.addValue(`${Msg.Lang['读取固件'] + ' '
// + Msg.Lang['路径']}:${absolutePath}, ${Msg.Lang['偏移']}:${i.offset}\n`);
firmwarePromise.push(readBinFile(absolutePath, i.offset));
}
}
@@ -316,6 +319,7 @@ BU.burnWithEsptool = async (binFile, erase) => {
Debug.error(error);
}
BU.progressLayer.hide();
statusBarTerminal.addValue(`==${Msg.Lang['shell.burnFailed']}==\n`);
return;
}
statusBarTerminal.addValue("Done!\n");