Improve CLI mode entry/exit detection. Fixes #285.

Disconnects and reconnects for VCP boards.  After manually saving or
exiting on non VCP boards the setup tab will be shown.

See
https://github.com/cleanflight/cleanflight-configurator/issues/285#issuecomment-165096715
10.3.x-maintenance
Dominic Clifton 2015-12-16 13:55:35 +01:00
parent 18fd5d01ec
commit 7618363449
2 changed files with 46 additions and 16 deletions

View File

@ -984,6 +984,12 @@
"cliInputPlaceholder": { "cliInputPlaceholder": {
"message": "Write your command here" "message": "Write your command here"
}, },
"cliEnter": {
"message": "CLI mode detected"
},
"cliReboot": {
"message": "CLI reboot detected"
},
"loggingNote": { "loggingNote": {
"message": "Data will be logged in this tab <span style=\"color: red\">only</span>, leaving the tab will <span style=\"color: red\">cancel</span> logging and application will return to its normal <strong>\"configurator\"</strong> state.<br /> You are free to select the global update period, data will be written into the log file every <strong>1</strong> second for performance reasons." "message": "Data will be logged in this tab <span style=\"color: red\">only</span>, leaving the tab will <span style=\"color: red\">cancel</span> logging and application will return to its normal <strong>\"configurator\"</strong> state.<br /> You are free to select the global update period, data will be written into the log file every <strong>1</strong> second for performance reasons."

View File

@ -2,6 +2,7 @@
TABS.cli = { TABS.cli = {
'validateText': "", 'validateText': "",
'currentLine': "",
'sequenceElements': 0 'sequenceElements': 0
}; };
@ -12,21 +13,13 @@ TABS.cli.initialize = function (callback) {
GUI.active_tab = 'cli'; GUI.active_tab = 'cli';
googleAnalytics.sendAppView('CLI'); googleAnalytics.sendAppView('CLI');
} }
$('#content').load("./tabs/cli.html", function () { $('#content').load("./tabs/cli.html", function () {
// translate to user-selected language // translate to user-selected language
localize(); localize();
CONFIGURATOR.cliActive = true; CONFIGURATOR.cliActive = true;
// Enter CLI mode
var bufferOut = new ArrayBuffer(1);
var bufView = new Uint8Array(bufferOut);
bufView[0] = 0x23; // #
serial.send(bufferOut);
var textarea = $('.tab-cli textarea'); var textarea = $('.tab-cli textarea');
textarea.keypress(function (event) { textarea.keypress(function (event) {
@ -62,6 +55,16 @@ TABS.cli.initialize = function (callback) {
// give input element user focus // give input element user focus
textarea.focus(); textarea.focus();
GUI.timeout_add('enter_cli', function enter_cli() {
// Enter CLI mode
var bufferOut = new ArrayBuffer(1);
var bufView = new Uint8Array(bufferOut);
bufView[0] = 0x23; // #
serial.send(bufferOut);
}, 250);
GUI.content_ready(callback); GUI.content_ready(callback);
}); });
}; };
@ -135,11 +138,13 @@ TABS.cli.read = function (readInfo) {
if (GUI.operating_system != "MacOS") { if (GUI.operating_system != "MacOS") {
text += "<br />"; text += "<br />";
} }
this.currentLine = "";
break; break;
case 13: // carriage return case 13: // carriage return
if (GUI.operating_system == "MacOS") { if (GUI.operating_system == "MacOS") {
text += "<br />"; text += "<br />";
} }
this.currentLine = "";
break; break;
case 60: case 60:
text += '&lt'; text += '&lt';
@ -150,19 +155,41 @@ TABS.cli.read = function (readInfo) {
default: default:
text += String.fromCharCode(data[i]); text += String.fromCharCode(data[i]);
this.currentLine += String.fromCharCode(data[i]);
}
}
if (this.currentLine == 'Rebooting') {
CONFIGURATOR.cliActive = false;
CONFIGURATOR.cliValid = false;
GUI.log(chrome.i18n.getMessage('cliReboot'));
GUI.log(chrome.i18n.getMessage('deviceRebooting'));
if (BOARD.find_board_definition(CONFIG.boardIdentifier).vcp) { // VCP-based flight controls may crash old drivers, we catch and reconnect
$('a.connect').click();
GUI.timeout_add('start_connection',function start_connection() {
$('a.connect').click();
},2000);
} else {
GUI.timeout_add('waiting_for_bootup', function waiting_for_bootup() {
MSP.send_message(MSP_codes.MSP_IDENT, false, false, function () {
GUI.log(chrome.i18n.getMessage('deviceReady'));
$('#tabs ul.mode-connected .tab_setup a').click();
});
},1500); // 1500 ms seems to be just the right amount of delay to prevent data request timeouts
} }
} }
} else { } else {
// try to catch part of valid CLI enter message // try to catch part of valid CLI enter message
this.validateText += String.fromCharCode(data[i]); this.validateText += String.fromCharCode(data[i]);
text += String.fromCharCode(data[i]);
} }
} }
if (!CONFIGURATOR.cliValid && this.validateText.indexOf('CLI') != -1) { if (!CONFIGURATOR.cliValid && this.validateText.indexOf('CLI') != -1) {
GUI.log(chrome.i18n.getMessage('cliEnter'));
CONFIGURATOR.cliValid = true; CONFIGURATOR.cliValid = true;
this.validateText = ""; this.validateText = "";
text = "Entering CLI Mode, type 'exit' to return, or 'help'<br /><br /># ";
} }
$('.tab-cli .window .wrapper').append(text); $('.tab-cli .window .wrapper').append(text);
@ -170,7 +197,7 @@ TABS.cli.read = function (readInfo) {
}; };
TABS.cli.cleanup = function (callback) { TABS.cli.cleanup = function (callback) {
if (!CONFIGURATOR.connectionValid) { if (!CONFIGURATOR.connectionValid || !CONFIGURATOR.cliValid) {
if (callback) callback(); if (callback) callback();
return; return;
} }
@ -190,10 +217,7 @@ TABS.cli.cleanup = function (callback) {
// we can setup an interval asking for data lets say every 200ms, when data arrives, callback will be triggered and tab switched // we can setup an interval asking for data lets say every 200ms, when data arrives, callback will be triggered and tab switched
// we could probably implement this someday // we could probably implement this someday
GUI.timeout_add('waiting_for_bootup', function waiting_for_bootup() { GUI.timeout_add('waiting_for_bootup', function waiting_for_bootup() {
CONFIGURATOR.cliActive = false;
CONFIGURATOR.cliValid = false;
if (callback) callback(); if (callback) callback();
}, 5000); // if we dont allow enough time to reboot, CRC of "first" command sent will fail, keep an eye for this one }, 1000); // if we dont allow enough time to reboot, CRC of "first" command sent will fail, keep an eye for this one
}); });
}; };