1
0
Fork 0
mirror of https://github.com/betaflight/betaflight-configurator.git synced 2025-07-23 16:25:22 +03:00

Add serial facade (#4402)

* Add serial facade

* Fix websocket connection

* Refactor

* Fix unplug

* Fix reboot / unplug reconnect issue

* The real deal (detail has no value)
This commit is contained in:
Mark Haslinghuis 2025-03-30 21:42:03 +02:00 committed by GitHub
parent 96a82d77f0
commit 4aad8c648b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
21 changed files with 839 additions and 440 deletions

View file

@ -0,0 +1,51 @@
const VIRTUAL = "virtual";
/**
* Stripped down version of previous nwjs based serial port implementation
* which is required to still have virtual serial port support in the
* browser.
*/
class VirtualSerial {
constructor() {
this.connected = false;
this.connectionId = false;
this.openCanceled = false;
this.bitrate = 0;
this.bytesReceived = 0;
this.bytesSent = 0;
this.failed = 0;
this.connectionType = VIRTUAL;
this.transmitting = false;
this.outputBuffer = [];
}
connect(callback) {
if (!this.openCanceled) {
this.connected = true;
this.connectionId = VIRTUAL;
this.bitrate = 115200;
callback();
}
}
disconnect(callback) {
this.connected = false;
this.outputBuffer = [];
this.transmitting = false;
if (this.connectionId) {
this.connectionId = false;
this.bitrate = 0;
if (callback) {
callback(true);
}
}
}
getConnectedPort() {
return this.connectionId;
}
getDevices() {
return new Promise((resolve) => {
resolve([{ path: VIRTUAL }]);
});
}
}
export default VirtualSerial;