From 7f0951634924be70b7380bb4629042e6861a6f0e Mon Sep 17 00:00:00 2001 From: Joacim Breiler Date: Sun, 22 Dec 2024 14:24:52 +0100 Subject: [PATCH] Minor adjustments --- package-lock.json | 14 +- package.json | 2 +- src/pages/filebrowser/FileBrowser.tsx | 2 +- src/pages/wifisettings/WiFiSettings.tsx | 166 +++++++++++++----------- src/utils/serialport/SerialPort.ts | 11 ++ 5 files changed, 107 insertions(+), 88 deletions(-) diff --git a/package-lock.json b/package-lock.json index 6512778..131827b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -20,7 +20,7 @@ "@xterm/xterm": "^5.5.0", "bootstrap": "^5.3.0", "crypto-js": "^4.2.0", - "esptool-js": "^0.4.7", + "esptool-js": "^0.5.3", "firebase": "^10.6.0", "js-yaml": "^4.1.0", "react": "^18.2.0", @@ -7081,9 +7081,9 @@ } }, "node_modules/esptool-js": { - "version": "0.4.7", - "resolved": "https://registry.npmjs.org/esptool-js/-/esptool-js-0.4.7.tgz", - "integrity": "sha512-xVwtSVDRsvjXSEvNFrorgJfB71RFFkZkL+hs7O7gW5hgPrKGywZxo2U5LJddzkJ6eE31QinNVyywc0OaSntZCw==", + "version": "0.5.3", + "resolved": "https://registry.npmjs.org/esptool-js/-/esptool-js-0.5.3.tgz", + "integrity": "sha512-RAzlZ3+o2a5h+1EZ/ItNEkj4hhBuUtX/BFGiEh7OyF4pSxTIBsBu0oWE2o7THQ+oUgd+bn682SPQQr8Fl2LMDw==", "dependencies": { "atob-lite": "^2.0.0", "pako": "^2.1.0", @@ -18988,9 +18988,9 @@ "dev": true }, "esptool-js": { - "version": "0.4.7", - "resolved": "https://registry.npmjs.org/esptool-js/-/esptool-js-0.4.7.tgz", - "integrity": "sha512-xVwtSVDRsvjXSEvNFrorgJfB71RFFkZkL+hs7O7gW5hgPrKGywZxo2U5LJddzkJ6eE31QinNVyywc0OaSntZCw==", + "version": "0.5.3", + "resolved": "https://registry.npmjs.org/esptool-js/-/esptool-js-0.5.3.tgz", + "integrity": "sha512-RAzlZ3+o2a5h+1EZ/ItNEkj4hhBuUtX/BFGiEh7OyF4pSxTIBsBu0oWE2o7THQ+oUgd+bn682SPQQr8Fl2LMDw==", "requires": { "atob-lite": "^2.0.0", "pako": "^2.1.0", diff --git a/package.json b/package.json index b35e0d1..381ef16 100644 --- a/package.json +++ b/package.json @@ -65,7 +65,7 @@ "@xterm/xterm": "^5.5.0", "bootstrap": "^5.3.0", "crypto-js": "^4.2.0", - "esptool-js": "^0.4.7", + "esptool-js": "^0.5.3", "firebase": "^10.6.0", "js-yaml": "^4.1.0", "react": "^18.2.0", diff --git a/src/pages/filebrowser/FileBrowser.tsx b/src/pages/filebrowser/FileBrowser.tsx index 8c48f6f..a9240f2 100644 --- a/src/pages/filebrowser/FileBrowser.tsx +++ b/src/pages/filebrowser/FileBrowser.tsx @@ -70,8 +70,8 @@ const FileBrowser = () => { return; } - await controllerService.write(Buffer.from([0x0c])); // CTRL-L Restting echo mode setIsLoading(true); + await controllerService.write(Buffer.from([0x0c])); // CTRL-L Restting echo mode await refreshFileList(); setConfigFilename( diff --git a/src/pages/wifisettings/WiFiSettings.tsx b/src/pages/wifisettings/WiFiSettings.tsx index 872473d..a024072 100644 --- a/src/pages/wifisettings/WiFiSettings.tsx +++ b/src/pages/wifisettings/WiFiSettings.tsx @@ -134,86 +134,94 @@ const WiFiSettings = () => { }; const saveSettings = async () => { - if (hostname !== settings?.hostname) { - await controllerService?.send(new Command("$Hostname=" + hostname)); - } - - if (wifiMode !== settings?.wifiMode) { - await controllerService?.send( - new Command("$WiFi/Mode=" + wifiMode) - ); - } - - if (stationSSID !== settings?.stationSSID) { - await controllerService?.send( - new Command("$Sta/SSID=" + stationSSID) - ); - } - - if (stationIpMode !== settings?.stationIpMode) { - await controllerService?.send( - new Command("$Sta/IPMode=" + stationIpMode) - ); - } - - if (stationPassword !== settings?.stationPassword) { - await controllerService?.send( - new Command( - "$Sta/Password=" + encodePassword(stationPassword ?? "") - ) - ); - } - - if (stationMinSecurity !== settings?.stationMinSecurity) { - await controllerService?.send( - new Command("$Sta/MinSecurity=" + stationMinSecurity) - ); - } - - if (stationIP !== settings?.stationIP) { - await controllerService?.send(new Command("$Sta/IP=" + stationIP)); - } - - if (stationGateway !== settings?.stationGateway) { - await controllerService?.send( - new Command("$Sta/Gateway=" + stationGateway) - ); - } - - if (stationNetmask !== settings?.stationNetmask) { - await controllerService?.send( - new Command("$Sta/Netmask=" + stationNetmask) - ); - } - - if (apSSID !== settings?.apSSID) { - await controllerService?.send(new Command("$AP/SSID=" + apSSID)); - } - - if (apPassword !== settings?.apPassword) { - await controllerService?.send( - new Command("$AP/Password=" + encodePassword(apPassword ?? "")) - ); - } - - if (apChannel !== settings?.apChannel) { - await controllerService?.send( - new Command("$AP/Channel=" + apChannel) - ); - } - - if (apIP !== settings?.apIP) { - await controllerService?.send(new Command("$AP/IP=" + apIP)); - } - - if (apCountry !== settings?.apCountry) { - await controllerService?.send( - new Command("$AP/Country=" + apCountry) - ); - } - + setIsSaving(true); try { - setIsSaving(true); + if (hostname !== settings?.hostname) { + await controllerService?.send( + new Command("$Hostname=" + hostname) + ); + } + + if (wifiMode !== settings?.wifiMode) { + await controllerService?.send( + new Command("$WiFi/Mode=" + wifiMode) + ); + } + + if (stationSSID !== settings?.stationSSID) { + await controllerService?.send( + new Command("$Sta/SSID=" + stationSSID) + ); + } + + if (stationIpMode !== settings?.stationIpMode) { + await controllerService?.send( + new Command("$Sta/IPMode=" + stationIpMode) + ); + } + + if (stationPassword !== settings?.stationPassword) { + await controllerService?.send( + new Command( + "$Sta/Password=" + encodePassword(stationPassword ?? "") + ) + ); + } + + if (stationMinSecurity !== settings?.stationMinSecurity) { + await controllerService?.send( + new Command("$Sta/MinSecurity=" + stationMinSecurity) + ); + } + + if (stationIP !== settings?.stationIP) { + await controllerService?.send( + new Command("$Sta/IP=" + stationIP) + ); + } + + if (stationGateway !== settings?.stationGateway) { + await controllerService?.send( + new Command("$Sta/Gateway=" + stationGateway) + ); + } + + if (stationNetmask !== settings?.stationNetmask) { + await controllerService?.send( + new Command("$Sta/Netmask=" + stationNetmask) + ); + } + + if (apSSID !== settings?.apSSID) { + await controllerService?.send( + new Command("$AP/SSID=" + apSSID) + ); + } + + if (apPassword !== settings?.apPassword) { + await controllerService?.send( + new Command( + "$AP/Password=" + encodePassword(apPassword ?? "") + ) + ); + } + + if (apChannel !== settings?.apChannel) { + await controllerService?.send( + new Command("$AP/Channel=" + apChannel) + ); + } + + if (apIP !== settings?.apIP) { + await controllerService?.send(new Command("$AP/IP=" + apIP)); + } + + if (apCountry !== settings?.apCountry) { + await controllerService?.send( + new Command("$AP/Country=" + apCountry) + ); + } + await controllerService?.hardReset(); await refresh(); } finally { diff --git a/src/utils/serialport/SerialPort.ts b/src/utils/serialport/SerialPort.ts index c85bdf3..c91236b 100644 --- a/src/utils/serialport/SerialPort.ts +++ b/src/utils/serialport/SerialPort.ts @@ -98,6 +98,7 @@ export class SerialPort { private readers: SerialReader[] = []; private reader: ReadableStreamDefaultReader; private deviceInfo: DeviceInfo; + private dtrState: boolean = false; constructor(serialPort: NativeSerialPort) { this.serialPort = serialPort; @@ -155,9 +156,15 @@ export class SerialPort { }; async setDTR(enabled: boolean) { + this.dtrState = enabled; await this.serialPort.setSignals({ dataTerminalReady: enabled }); } + async setRTS(enabled: boolean) { + await this.serialPort.setSignals({ requestToSend: enabled }); + this.setDTR(this.dtrState); + } + open = async (baudRate = 115200): Promise => { if (this.state === SerialPortState.DISCONNECTING) { await new Promise((r) => setTimeout(r, 1000)); @@ -226,6 +233,10 @@ export class SerialPort { } try { + while (this.serialPort.writable.locked) { + await sleep(100); + } + const writer = this.serialPort.writable!.getWriter(); return writer.write(data).finally(() => { writer.releaseLock();