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

Merge pull request #2460 from haslinghuis/filter_cli_output

Filter MSP Output while opening CLI
This commit is contained in:
Ivan Efimov 2021-06-10 21:10:44 -05:00 committed by GitHub
commit 57666a9d7a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -5,6 +5,7 @@ TABS.cli = {
profileSwitchDelayMs: 100, profileSwitchDelayMs: 100,
outputHistory: "", outputHistory: "",
cliBuffer: "", cliBuffer: "",
startProcessing: false,
GUI: { GUI: {
snippetPreviewWindow: null, snippetPreviewWindow: null,
copyButton: null, copyButton: null,
@ -83,6 +84,7 @@ TABS.cli.initialize = function (callback) {
self.outputHistory = ""; self.outputHistory = "";
self.cliBuffer = ""; self.cliBuffer = "";
self.startProcessing = false;
const enterKeyCode = 13; const enterKeyCode = 13;
@ -108,7 +110,7 @@ TABS.cli.initialize = function (callback) {
}, delay); }, delay);
}); });
}, 0); }, 0);
} }
$('#content').load("./tabs/cli.html", function () { $('#content').load("./tabs/cli.html", function () {
// translate to user-selected language // translate to user-selected language
@ -400,9 +402,11 @@ TABS.cli.read = function (readInfo) {
for (let i = 0; i < data.length; i++) { for (let i = 0; i < data.length; i++) {
const currentChar = String.fromCharCode(data[i]); const currentChar = String.fromCharCode(data[i]);
const isCRLF = currentChar.charCodeAt() === lineFeedCode || currentChar.charCodeAt() === carriageReturnCode;
if (!CONFIGURATOR.cliValid) { if (!CONFIGURATOR.cliValid && (isCRLF || this.startProcessing)) {
// try to catch part of valid CLI enter message // try to catch part of valid CLI enter message (firmware message starts with CRLF)
this.startProcessing = true;
validateText += currentChar; validateText += currentChar;
writeToOutput(currentChar); writeToOutput(currentChar);
continue; continue;
@ -419,32 +423,34 @@ TABS.cli.read = function (readInfo) {
continue; continue;
} }
switch (data[i]) { if (CONFIGURATOR.cliValid) {
case lineFeedCode: switch (data[i]) {
if (GUI.operating_system === "Windows") { case lineFeedCode:
writeLineToOutput(this.cliBuffer); if (GUI.operating_system === "Windows") {
this.cliBuffer = ""; writeLineToOutput(this.cliBuffer);
} this.cliBuffer = "";
break; }
case carriageReturnCode: break;
if (GUI.operating_system !== "Windows") { case carriageReturnCode:
writeLineToOutput(this.cliBuffer); if (GUI.operating_system !== "Windows") {
this.cliBuffer = ""; writeLineToOutput(this.cliBuffer);
} this.cliBuffer = "";
break; }
case 60: break;
this.cliBuffer += '&lt'; case 60:
break; this.cliBuffer += '&lt';
case 62: break;
this.cliBuffer += '&gt'; case 62:
break; this.cliBuffer += '&gt';
case backspaceCode: break;
this.cliBuffer = this.cliBuffer.slice(0, -1); case backspaceCode:
this.outputHistory = this.outputHistory.slice(0, -1); this.cliBuffer = this.cliBuffer.slice(0, -1);
continue; this.outputHistory = this.outputHistory.slice(0, -1);
continue;
default: default:
this.cliBuffer += currentChar; this.cliBuffer += currentChar;
}
} }
if (!CliAutoComplete.isBuilding()) { if (!CliAutoComplete.isBuilding()) {