Skip to content

Commit dd628c7

Browse files
authored
🆕 Add CLI Only Mode as development option (#4559)
* Add CLI Only Mode as development option * Fix reboot condition * Boolean checks should not be inverted * No constraints * Prevent auto-connect (loop) in cli only mode
1 parent ba0ffe0 commit dd628c7

File tree

4 files changed

+63
-15
lines changed

4 files changed

+63
-15
lines changed

locales/en/messages.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,18 @@
153153
"message": "Set connection timeout to allow longer initialisation on device plugin or reboot",
154154
"description": "Change timeout on auto-connect and reboot so the bus has more time to initialize after being detected by the system"
155155
},
156+
"developmentSettings": {
157+
"message": "Development Settings",
158+
"description": "Title for the development settings section"
159+
},
156160
"showAllSerialDevices": {
157161
"message": "Show all serial devices (for manufacturers or development)",
158162
"description": "Do not filter serial devices using VID/PID values (for manufacturers or development)"
159163
},
164+
"cliOnlyMode": {
165+
"message": "Enable CLI only mode",
166+
"description": "Text for the option to enable or disable CLI only mode"
167+
},
160168
"showManualMode": {
161169
"message": "Enable manual connection mode",
162170
"description": "Text for the option to enable or disable manual connection mode"

src/js/serial_backend.js

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ const REBOOT_CONNECT_MAX_TIME_MS = 10000;
3939
const REBOOT_GRACE_PERIOD_MS = 2000;
4040
let rebootTimestamp = 0;
4141

42+
function isCliOnlyMode() {
43+
return getConfig("cliOnlyMode")?.cliOnlyMode === true;
44+
}
45+
4246
const toggleStatus = function () {
4347
isConnected = !isConnected;
4448
};
@@ -59,8 +63,10 @@ export function initializeSerialBackend() {
5963
if (
6064
!GUI.connected_to &&
6165
!GUI.connecting_to &&
62-
GUI.active_tab !== "firmware_flasher" &&
63-
(PortHandler.portPicker.autoConnect || Date.now() - rebootTimestamp < REBOOT_CONNECT_MAX_TIME_MS)
66+
!["cli", "firmware_flasher"].includes(GUI.active_tab) &&
67+
PortHandler.portPicker.autoConnect &&
68+
!isCliOnlyMode() &&
69+
Date.now() - rebootTimestamp <= REBOOT_CONNECT_MAX_TIME_MS
6470
) {
6571
connectDisconnect();
6672
}
@@ -587,6 +593,11 @@ function setRtc() {
587593
function finishOpen() {
588594
CONFIGURATOR.connectionValid = true;
589595

596+
if (isCliOnlyMode()) {
597+
connectCli();
598+
return;
599+
}
600+
590601
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45) && FC.CONFIG.buildOptions.length) {
591602
GUI.allowedTabs = Array.from(GUI.defaultAllowedTabs);
592603

@@ -652,7 +663,7 @@ function onConnect() {
652663
})
653664
.show();
654665

655-
if (FC.CONFIG.flightControllerVersion !== "") {
666+
if (FC.CONFIG.flightControllerVersion !== "" && !isCliOnlyMode()) {
656667
FC.FEATURE_CONFIG.features = new Features(FC.CONFIG);
657668
FC.BEEPER_CONFIG.beepers = new Beepers(FC.CONFIG);
658669
FC.BEEPER_CONFIG.dshotBeaconConditions = new Beepers(FC.CONFIG, ["RX_LOST", "RX_SET"]);
@@ -668,12 +679,12 @@ function onConnect() {
668679
if (FC.CONFIG.boardType === 0 || FC.CONFIG.boardType === 2) {
669680
startLiveDataRefreshTimer();
670681
}
682+
683+
$("#sensor-status").show();
684+
$("#dataflash_wrapper_global").show();
671685
}
672686

673-
// header bar
674-
$("#sensor-status").show();
675687
$("#portsinput").hide();
676-
$("#dataflash_wrapper_global").show();
677688
}
678689

679690
function onClosed(result) {
@@ -798,9 +809,9 @@ export function reinitializeConnection() {
798809
}
799810
}
800811

801-
// Show reboot progress modal except for presets tab
802-
if (GUI.active_tab === "presets") {
803-
console.log("Rebooting in presets tab, skipping reboot dialog", GUI.active_tab);
812+
// Show reboot progress modal except for cli and presets tab
813+
if (["cli", "presets"].includes(GUI.active_tab)) {
814+
console.log(`${logHead} Rebooting in ${GUI.active_tab} tab, skipping reboot dialog`);
804815
gui_log(i18n.getMessage("deviceRebooting"));
805816
gui_log(i18n.getMessage("deviceReady"));
806817

src/js/tabs/options.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ options.initialize = function (callback) {
3232
TABS.options.initShowWarnings();
3333
TABS.options.initMeteredConnection();
3434
TABS.options.initBackupOnFlash();
35+
TABS.options.initCLiOnlyMode();
3536

3637
GUI.content_ready(callback);
3738
});
@@ -261,6 +262,17 @@ options.initUserLanguage = function () {
261262
.trigger("change");
262263
};
263264

265+
options.initCLiOnlyMode = function () {
266+
const cliOnlyModeElement = $("div.cliOnlyMode input");
267+
const result = getConfig("cliOnlyMode", false);
268+
cliOnlyModeElement.prop("checked", !!result.cliOnlyMode).on("change", () => {
269+
const checked = cliOnlyModeElement.is(":checked");
270+
setConfig({ cliOnlyMode: checked });
271+
});
272+
// Trigger change to ensure the initial state is set correctly
273+
cliOnlyModeElement.trigger("change");
274+
};
275+
264276
// TODO: remove when modules are in place
265277
TABS.options = options;
266278
export { options };

src/tabs/options.html

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,6 @@
2929
</div>
3030
<span class="freelabel" i18n="cliAutoComplete"></span>
3131
</div>
32-
<div class="showAllSerialDevices margin-bottom">
33-
<div>
34-
<input type="checkbox" class="toggle" />
35-
</div>
36-
<span class="freelabel" i18n="showAllSerialDevices"></span>
37-
</div>
3832
<div class="showManualMode margin-bottom">
3933
<div>
4034
<input type="checkbox" class="toggle" />
@@ -94,6 +88,29 @@
9488
</div>
9589
</div>
9690

91+
<div class="gui_box">
92+
<div class="gui_box_titlebar">
93+
<div class="spacer_box_title" i18n="developmentSettings"></div>
94+
</div>
95+
<div class="spacer">
96+
<div class="showAllSerialDevices margin-bottom">
97+
<div>
98+
<input type="checkbox" class="toggle" />
99+
</div>
100+
<span class="freelabel" i18n="showAllSerialDevices"></span>
101+
</div>
102+
103+
<div class="developmentSettings margin-bottom">
104+
<div class="cliOnlyMode margin-bottom">
105+
<div>
106+
<input type="checkbox" class="toggle" />
107+
</div>
108+
<span class="freelabel" i18n="cliOnlyMode"></span>
109+
</div>
110+
</div>
111+
</div>
112+
</div>
113+
97114
<div class="gui_box">
98115
<div class="gui_box_titlebar">
99116
<div class="spacer_box_title" i18n="warningSettings"></div>

0 commit comments

Comments
 (0)