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:
parent
96a82d77f0
commit
4aad8c648b
21 changed files with 839 additions and 440 deletions
51
src/js/protocols/VirtualSerial.js
Normal file
51
src/js/protocols/VirtualSerial.js
Normal 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;
|
Loading…
Add table
Add a link
Reference in a new issue