close existing rnode connections before opening another

This commit is contained in:
liamcottle
2025-01-06 03:42:42 +13:00
parent 74e02504b4
commit d44338bc76

View File

@@ -334,6 +334,8 @@
data() { data() {
return { return {
rnode: null,
isFlashing: false, isFlashing: false,
flashingProgress: 0, flashingProgress: 0,
@@ -874,11 +876,37 @@
return null; return null;
} }
// close any existing rnode connection
if(this.rnode){
await this.rnode.close();
this.rnode = null;
}
// ask user to select device // ask user to select device
return await navigator.serial.requestPort({ return await navigator.serial.requestPort({
filters: [], filters: [],
}); });
},
async askForRNode() {
// ask for serial port
const serialPort = await this.askForSerialPort();
if(!serialPort){
return false;
}
// check if device is an rnode
this.rnode = await RNode.fromSerialPort(serialPort);
const isRNode = await this.rnode.detect();
if(!isRNode){
await this.rnode.close();
alert("Selected device is not an RNode!");
return false;
}
return this.rnode;
}, },
async enterDfuMode() { async enterDfuMode() {
@@ -1085,17 +1113,9 @@
}, },
async detect() { async detect() {
// ask for serial port // ask for rnode
const serialPort = await this.askForSerialPort(); const rnode = await this.askForRNode();
if(!serialPort){ if(!rnode){
return;
}
// check if device is an rnode
const rnode = await RNode.fromSerialPort(serialPort);
const isRNode = await rnode.detect();
if(!isRNode){
alert("Selected device is not an RNode!");
return; return;
} }
@@ -1138,17 +1158,9 @@
}, },
async reboot() { async reboot() {
// ask for serial port // ask for rnode
const serialPort = await this.askForSerialPort(); const rnode = await this.askForRNode();
if(!serialPort){ if(!rnode){
return;
}
// check if device is an rnode
const rnode = await RNode.fromSerialPort(serialPort);
const isRNode = await rnode.detect();
if(!isRNode){
alert("Selected device is not an RNode!");
return; return;
} }
@@ -1226,17 +1238,9 @@
}, },
async readDisplay() { async readDisplay() {
// ask for serial port // ask for rnode
const serialPort = await this.askForSerialPort(); const rnode = await this.askForRNode();
if(!serialPort){ if(!rnode){
return;
}
// check if device is an rnode
const rnode = await RNode.fromSerialPort(serialPort);
const isRNode = await rnode.detect();
if(!isRNode){
alert("Selected device is not an RNode!");
return; return;
} }
@@ -1252,17 +1256,9 @@
}, },
async dumpEeprom() { async dumpEeprom() {
// ask for serial port // ask for rnode
const serialPort = await this.askForSerialPort(); const rnode = await this.askForRNode();
if(!serialPort){ if(!rnode){
return;
}
// check if device is an rnode
const rnode = await RNode.fromSerialPort(serialPort);
const isRNode = await rnode.detect();
if(!isRNode){
alert("Selected device is not an RNode!");
return; return;
} }
@@ -1280,22 +1276,15 @@
}, },
async wipeEeprom() { async wipeEeprom() {
// ask for serial port // ask for rnode
const serialPort = await this.askForSerialPort(); const rnode = await this.askForRNode();
if(!serialPort){ if(!rnode){
return; return;
} }
// ask user to confirm // ask user to confirm
if(!confirm("Are you sure you want to wipe the eeprom on this device? This will take about 30 seconds. An alert will show when the eeprom wipe has finished.")){ if(!confirm("Are you sure you want to wipe the eeprom on this device? This will take about 30 seconds. An alert will show when the eeprom wipe has finished.")){
return; await rnode.close();
}
// check if device is an rnode
const rnode = await RNode.fromSerialPort(serialPort);
const isRNode = await rnode.detect();
if(!isRNode){
alert("Selected device is not an RNode!");
return; return;
} }
@@ -1314,18 +1303,9 @@
}, },
async provision() { async provision() {
// ask for serial port // ask for rnode
const serialPort = await this.askForSerialPort(); const rnode = await this.askForRNode();
if(!serialPort){ if(!rnode){
return;
}
// check if device is an rnode
const rnode = await RNode.fromSerialPort(serialPort);
const isRNode = await rnode.detect();
if(!isRNode){
alert("Selected device is not an RNode!");
await rnode.close();
return; return;
} }
@@ -1505,17 +1485,9 @@
}, },
async setFirmwareHash() { async setFirmwareHash() {
// ask for serial port // ask for rnode
const serialPort = await this.askForSerialPort(); const rnode = await this.askForRNode();
if(!serialPort){ if(!rnode){
return;
}
// check if device is an rnode
const rnode = await RNode.fromSerialPort(serialPort);
const isRNode = await rnode.detect();
if(!isRNode){
alert("Selected device is not an RNode!");
return; return;
} }
@@ -1562,17 +1534,9 @@
}, },
async enableTncMode() { async enableTncMode() {
// ask for serial port // ask for rnode
const serialPort = await this.askForSerialPort(); const rnode = await this.askForRNode();
if(!serialPort){ if(!rnode){
return;
}
// check if device is an rnode
const rnode = await RNode.fromSerialPort(serialPort);
const isRNode = await rnode.detect();
if(!isRNode){
alert("Selected device is not an RNode!");
return; return;
} }
@@ -1618,17 +1582,9 @@
}, },
async disableTncMode() { async disableTncMode() {
// ask for serial port // ask for rnode
const serialPort = await this.askForSerialPort(); const rnode = await this.askForRNode();
if(!serialPort){ if(!rnode){
return;
}
// check if device is an rnode
const rnode = await RNode.fromSerialPort(serialPort);
const isRNode = await rnode.detect();
if(!isRNode){
alert("Selected device is not an RNode!");
return; return;
} }
@@ -1659,17 +1615,9 @@
}, },
async enableBluetooth() { async enableBluetooth() {
// ask for serial port // ask for rnode
const serialPort = await this.askForSerialPort(); const rnode = await this.askForRNode();
if(!serialPort){ if(!rnode){
return;
}
// check if device is an rnode
const rnode = await RNode.fromSerialPort(serialPort);
const isRNode = await rnode.detect();
if(!isRNode){
alert("Selected device is not an RNode!");
return; return;
} }
@@ -1696,17 +1644,9 @@
}, },
async disableBluetooth() { async disableBluetooth() {
// ask for serial port // ask for rnode
const serialPort = await this.askForSerialPort(); const rnode = await this.askForRNode();
if(!serialPort){ if(!rnode){
return;
}
// check if device is an rnode
const rnode = await RNode.fromSerialPort(serialPort);
const isRNode = await rnode.detect();
if(!isRNode){
alert("Selected device is not an RNode!");
return; return;
} }
@@ -1733,17 +1673,9 @@
}, },
async startBluetoothPairing() { async startBluetoothPairing() {
// ask for serial port // ask for rnode
const serialPort = await this.askForSerialPort(); const rnode = await this.askForRNode();
if(!serialPort){ if(!rnode){
return;
}
// check if device is an rnode
const rnode = await RNode.fromSerialPort(serialPort);
const isRNode = await rnode.detect();
if(!isRNode){
alert("Selected device is not an RNode!");
return; return;
} }