From 7c6497193810424c55f7a19bc1d712f1494843a6 Mon Sep 17 00:00:00 2001 From: "Pawel Spychalski (DzikuVx)" Date: Sun, 24 Mar 2024 16:45:43 +0100 Subject: [PATCH 1/4] Simplify --- js/serialPortHelper.js | 60 +++++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 27 deletions(-) diff --git a/js/serialPortHelper.js b/js/serialPortHelper.js index 4cb9fdb4..c6f0fce8 100644 --- a/js/serialPortHelper.js +++ b/js/serialPortHelper.js @@ -11,96 +11,102 @@ helper.serialPortHelper = (function () { // This is a list of all the rules for the serial ports as well as their names privateScope.rules = [ - { name: 'MSP', groups: ['data', 'msp'], maxPorts: 2 }, - { name: 'GPS', groups: ['sensors'], maxPorts: 1, defaultBaud: 115200 }, - { name: 'TELEMETRY_FRSKY', groups: ['telemetry'], sharableWith: ['msp'], notSharableWith: ['blackbox'], maxPorts: 1 }, - { name: 'TELEMETRY_HOTT', groups: ['telemetry'], sharableWith: ['msp'], notSharableWith: ['blackbox'], maxPorts: 1 }, - { name: 'TELEMETRY_SMARTPORT', groups: ['telemetry'], maxPorts: 1 }, - { name: 'TELEMETRY_LTM', groups: ['telemetry'], sharableWith: ['msp'], notSharableWith: ['blackbox'], maxPorts: 1 }, - { name: 'RX_SERIAL', groups: ['rx'], maxPorts: 1 }, - { name: 'BLACKBOX', groups: ['peripherals'], sharableWith: ['msp'], notSharableWith: ['telemetry'], maxPorts: 1 }, + { + name: 'MSP', + groups: ['data'] + }, + { + name: 'GPS', + groups: ['sensors'], + defaultBaud: 115200 + }, + { + name: 'TELEMETRY_FRSKY', + groups: ['telemetry'] + }, + { + name: 'TELEMETRY_HOTT', + groups: ['telemetry'] + }, + { + name: 'TELEMETRY_SMARTPORT', + groups: ['telemetry'] + }, + { + name: 'TELEMETRY_LTM', + groups: ['telemetry'] + }, + { + name: 'RX_SERIAL', + groups: ['rx'] + }, + { + name: 'BLACKBOX', + groups: ['peripherals'] + }, { name: 'TELEMETRY_MAVLINK', groups: ['telemetry'], - sharableWith: ['msp'], - notSharableWith: ['blackbox'], - maxPorts: 1 }, { name: 'TELEMETRY_IBUS', groups: ['telemetry'], - sharableWith: ['msp'], - notSharableWith: ['blackbox'], - maxPorts: 1 }, { name: 'RANGEFINDER', groups: ['sensors'], - maxPorts: 1 }, { name: 'GSM_SMS', groups: ['telemetry'], - maxPorts: 1 }, { name: 'RUNCAM_DEVICE_CONTROL', groups: ['peripherals'], - maxPorts: 1 }, { name: 'TBS_SMARTAUDIO', groups: ['peripherals'], - maxPorts: 1 }, { name: 'IRC_TRAMP', groups: ['peripherals'], - maxPorts: 1 }, { name: 'VTX_FFPV', groups: ['peripherals'], - maxPorts: 1 }, { name: 'ESC', groups: ['peripherals'], - maxPorts: 1, defaultBaud: 115200 }, { name: 'OPFLOW', groups: ['sensors'], - maxPorts: 1 }, { name: 'FRSKY_OSD', groups: ['peripherals'], - maxPorts: 1, defaultBaud: 250000 }, { name: 'DJI_FPV', groups: ['peripherals'], - maxPorts: 1, defaultBaud: 115200 }, { name: 'MSP_DISPLAYPORT', groups: ['peripherals'], - maxPorts: 1 }, { name: 'SMARTPORT_MASTER', groups: ['peripherals'], - maxPorts: 1, defaultBaud: 57600 }, { name: 'SBUS_OUTPUT', groups: ['peripherals'], - maxPorts: 1, defaultBaud: 115200 } ]; From b316704246a2a70ef04ae8b30627b32c05c4ffc2 Mon Sep 17 00:00:00 2001 From: "Pawel Spychalski (DzikuVx)" Date: Sun, 24 Mar 2024 17:15:46 +0100 Subject: [PATCH 2/4] Fix updateDefaultBaud --- js/serialPortHelper.js | 21 ++++++++++++++++----- tabs/ports.js | 11 +++-------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/js/serialPortHelper.js b/js/serialPortHelper.js index c6f0fce8..31b98d53 100644 --- a/js/serialPortHelper.js +++ b/js/serialPortHelper.js @@ -18,7 +18,8 @@ helper.serialPortHelper = (function () { { name: 'GPS', groups: ['sensors'], - defaultBaud: 115200 + defaultBaud: 115200, + isUnique: true }, { name: 'TELEMETRY_FRSKY', @@ -38,7 +39,8 @@ helper.serialPortHelper = (function () { }, { name: 'RX_SERIAL', - groups: ['rx'] + groups: ['rx'], + isUnique: true }, { name: 'BLACKBOX', @@ -55,6 +57,7 @@ helper.serialPortHelper = (function () { { name: 'RANGEFINDER', groups: ['sensors'], + isUnique: true }, { name: 'GSM_SMS', @@ -67,37 +70,45 @@ helper.serialPortHelper = (function () { { name: 'TBS_SMARTAUDIO', groups: ['peripherals'], + isUnique: true }, { name: 'IRC_TRAMP', groups: ['peripherals'], + isUnique: true }, { name: 'VTX_FFPV', groups: ['peripherals'], + isUnique: true }, { name: 'ESC', groups: ['peripherals'], - defaultBaud: 115200 + defaultBaud: 115200, + isUnique: true }, { name: 'OPFLOW', groups: ['sensors'], + isUnique: true }, { name: 'FRSKY_OSD', groups: ['peripherals'], - defaultBaud: 250000 + defaultBaud: 250000, + isUnique: true }, { name: 'DJI_FPV', groups: ['peripherals'], - defaultBaud: 115200 + defaultBaud: 115200, + isUnique: true }, { name: 'MSP_DISPLAYPORT', groups: ['peripherals'], + isUnique: true }, { name: 'SMARTPORT_MASTER', diff --git a/tabs/ports.js b/tabs/ports.js index 5b26fd26..f7f6171e 100644 --- a/tabs/ports.js +++ b/tabs/ports.js @@ -206,15 +206,10 @@ function updateDefaultBaud(baudSelect, column) { let portName = section.find('.function-' + column).val(); let baudRate = (column === 'telemetry') ? "AUTO" : 115200;; - let rules = helper.serialPortHelper.getRules(); + let rule = helper.serialPortHelper.getRuleByName(portName); - for (i = 0; i < rules.length; i++) { - if (rules[i].name === portName) { - if (typeof rules[i].defaultBaud !== 'undefined') { - baudRate = rules[i].defaultBaud; - } - break; - } + if (rule && typeof rule.defaultBaud !== 'undefined') { + baudRate = rule.defaultBaud; } section.find("." + column + "_baudrate").children('[value=' + baudRate + ']').prop('selected', true); From f42ba123373fb80a8c2527058c8f6265ffe5dbe7 Mon Sep 17 00:00:00 2001 From: "Pawel Spychalski (DzikuVx)" Date: Sun, 24 Mar 2024 17:42:22 +0100 Subject: [PATCH 3/4] Process unique functions in the ports tab --- tabs/ports.js | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/tabs/ports.js b/tabs/ports.js index f7f6171e..af82ee41 100644 --- a/tabs/ports.js +++ b/tabs/ports.js @@ -101,7 +101,7 @@ TABS.ports.initialize = function (callback) { select_e = functions_e.find(selectElementSelector); if (select_e.length == 0) { - functions_e.prepend(''); select_e = functions_e.find(selectElementSelector); var disabledText = chrome.i18n.getMessage('portsTelemetryDisabled'); select_e.append(''); @@ -118,6 +118,44 @@ TABS.ports.initialize = function (callback) { } } + + $('table.ports tbody').on('change', 'select', onSwitchChange); + $('table.ports tbody').on('change', 'input', onSwitchChange); + } + + function onSwitchChange(e) { + let $cT = $(e.currentTarget); + + let functionName = $cT.val(); + let rule = helper.serialPortHelper.getRuleByName($cT.val()); + + //if type is checkbox then process only if selected + if ($cT.is('input[type="checkbox"]') && !$cT.is(':checked')) { + return; + } + + if (rule && rule.isUnique) { + let $selects = $cT.closest('tr').find('.function-select'); + $selects.each(function (index, element) { + + let $element = $(element); + + if ($element.val() != functionName) { + $element.val(''); + } + }); + + let $checkboxes = $cT.closest('tr').find('input[type="checkbox"]'); + $checkboxes.each(function (index, element) { + let $element = $(element); + + if ($element.val() != functionName) { + $element.prop('checked', false); + $element.trigger('change'); + } + }); + } + } function on_tab_loaded_handler() { From b1a57166073ebdfd2292b2fa65930b1309e76b2b Mon Sep 17 00:00:00 2001 From: "Pawel Spychalski (DzikuVx)" Date: Sun, 24 Mar 2024 17:43:52 +0100 Subject: [PATCH 4/4] Additional case --- tabs/ports.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tabs/ports.js b/tabs/ports.js index af82ee41..b37ae88e 100644 --- a/tabs/ports.js +++ b/tabs/ports.js @@ -133,6 +133,10 @@ TABS.ports.initialize = function (callback) { if ($cT.is('input[type="checkbox"]') && !$cT.is(':checked')) { return; } + //if type select then process only if selected + if ($cT.is('select') && !functionName) { + return; + } if (rule && rule.isUnique) { let $selects = $cT.closest('tr').find('.function-select');