Skip to content

Commit a4ebb3c

Browse files
Merge pull request #2412 from sensei-hacker/msp_ports_warning
Warn if too many MSP Ports
2 parents 0dbf310 + 92ee343 commit a4ebb3c

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed

locale/en/messages.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1304,6 +1304,9 @@
13041304
"portsHelp": {
13051305
"message": "<strong>Note:</strong> not all combinations are valid. When the flight controller firmware detects this the serial port configuration will be reset."
13061306
},
1307+
"portsMSPWarning": {
1308+
"message": "<strong>Caution:</strong><p>Putting MSP on more than two UART ports may interfere with USB communication. Consider removing MSP from a port where it is not needed.</p>"
1309+
},
13071310
"portsFirmwareUpgradeRequired": {
13081311
"message": "Firmware upgrade <span style=\"color: red\">required</span>."
13091312
},

tabs/ports.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,8 @@
6262
</tbody>
6363
</table>
6464
</div>
65+
66+
<div id="mspWarningContent" class="is-hidden">
67+
<p data-i18n="portsMSPWarning"></p>
68+
</div>
69+

tabs/ports.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ const { GUI, TABS } = require('./../js/gui');
99
const FC = require('./../js/fc');
1010
const i18n = require('./../js/localization');
1111
const serialPortHelper = require('./../js/serialPortHelper');
12+
const jBox = require('../js/libraries/jBox/jBox.min');
1213

1314
TABS.ports = {};
1415

1516
TABS.ports.initialize = function (callback) {
1617

1718
var columns = ['data', 'logging', 'sensors', 'telemetry', 'rx', 'peripherals'];
19+
var mspWarningModal;
1820

1921
if (GUI.active_tab != 'ports') {
2022
GUI.active_tab = 'ports';
@@ -24,6 +26,34 @@ TABS.ports.initialize = function (callback) {
2426
GUI.load(path.join(__dirname, "ports.html"), on_tab_loaded_handler)
2527
});
2628

29+
function checkMSPPortCount(excludeCheckbox) {
30+
let mspCount = 0;
31+
32+
$('.tab-ports .portConfiguration').each(function () {
33+
const $portConfig = $(this);
34+
35+
// Check each MSP checkbox in this port configuration
36+
$portConfig.find('input:checkbox[value="MSP"]').each(function() {
37+
const $checkbox = $(this);
38+
// Skip the checkbox we're currently changing (to get "before" count)
39+
if (excludeCheckbox && $checkbox.is(excludeCheckbox)) {
40+
return;
41+
}
42+
if ($checkbox.is(':checked')) {
43+
mspCount++;
44+
}
45+
});
46+
});
47+
48+
return mspCount;
49+
}
50+
51+
function showMSPWarning() {
52+
if (mspWarningModal) {
53+
mspWarningModal.open();
54+
}
55+
}
56+
2757
function update_ui() {
2858

2959
$(".tab-ports").addClass("supported");
@@ -152,6 +182,16 @@ TABS.ports.initialize = function (callback) {
152182
return;
153183
}
154184

185+
// Check if MSP checkbox was just checked
186+
if ($cT.is('input[type="checkbox"]') && $cT.val() === 'MSP' && $cT.is(':checked')) {
187+
// Count MSP ports excluding the one being changed to get "before" count
188+
const mspCountBefore = checkMSPPortCount($cT);
189+
// If we already had 2+ and are adding another, show warning
190+
if (mspCountBefore >= 2) {
191+
showMSPWarning();
192+
}
193+
}
194+
155195
if (rule && rule.isUnique) {
156196
let $selects = $cT.closest('tr').find('.function-select');
157197
$selects.each(function (index, element) {
@@ -182,6 +222,22 @@ TABS.ports.initialize = function (callback) {
182222

183223
update_ui();
184224

225+
// Initialize the MSP warning modal
226+
mspWarningModal = new jBox('Modal', {
227+
width: 480,
228+
height: 200,
229+
closeButton: 'title',
230+
animation: false,
231+
title: i18n.getMessage('portsMspWarningTitle') || 'MSP Port Warning',
232+
content: $('#mspWarningContent')
233+
});
234+
235+
// Check if more than 2 MSP ports are already configured on load
236+
const initialMspCount = checkMSPPortCount();
237+
if (initialMspCount > 2) {
238+
showMSPWarning();
239+
}
240+
185241
$('a.save').on('click', on_save_handler);
186242

187243
GUI.content_ready(callback);
@@ -268,5 +324,6 @@ function updateDefaultBaud(baudSelect, column) {
268324
}
269325

270326
TABS.ports.cleanup = function (callback) {
327+
$('.jBox-wrapper').remove();
271328
if (callback) callback();
272329
};

0 commit comments

Comments
 (0)