From d885182ce5498f393dace470124506fb690eb6da Mon Sep 17 00:00:00 2001 From: her01n Date: Tue, 3 Sep 2024 19:54:19 +0200 Subject: [PATCH] Warn when selected rx protocol is not in build configuration (#4150) * Warn when selected rx protocol is not in build configuration * Disable unavailable rx protocols * Handle TARGET_CUSTOM same way like other cases Co-authored-by: nerdCopter <56646290+nerdCopter@users.noreply.github.com> --------- Co-authored-by: Michal Herko Co-authored-by: nerdCopter <56646290+nerdCopter@users.noreply.github.com> --- locales/en/messages.json | 6 +++++ src/js/fc.js | 49 ++++++++++++++++++++++++++++++++++++++++ src/js/tabs/receiver.js | 19 +++++++++++++++- src/tabs/receiver.html | 4 ++++ 4 files changed, 77 insertions(+), 1 deletion(-) diff --git a/locales/en/messages.json b/locales/en/messages.json index 0a64e20143..e6b9710981 100755 --- a/locales/en/messages.json +++ b/locales/en/messages.json @@ -1636,6 +1636,12 @@ "configurationSerialRX": { "message": "Serial Receiver Provider" }, + "someRXTypesDisabled": { + "message": "Some Receiver Providers are not supported by current Build Configuration." + }, + "serialRXNotSupported": { + "message": "The selected Receiver Provider is not supported by the current Build Configuration. Select another Provider or Update Firmware with the correct Radio Protocol selected in Build Configuration." + }, "configurationSpiRX": { "message": "SPI Bus Receiver Provider" }, diff --git a/src/js/fc.js b/src/js/fc.js index c14636d99c..b3fba1c96a 100644 --- a/src/js/fc.js +++ b/src/js/fc.js @@ -795,6 +795,55 @@ const FC = { return serialRxTypes; }, + getSupportedSerialRxTypes: () => { + if (FC.CONFIG.buildOptions?.length) { + const options = FC.CONFIG.buildOptions; + let supportedRxTypes = ['NONE',]; + if (options.includes('USE_SERIALRX_TARGET_CUSTOM')) { + supportedRxTypes.push('TARGET_CUSTOM'); + } + if (options.includes('USE_SERIALRX_SPEKTRUM')) { + supportedRxTypes.push('SPEKTRUM1024'); + supportedRxTypes.push('SPEKTRUM2048'); + supportedRxTypes.push('SPEKTRUM2048/SRXL'); + } + if (options.includes('USE_SERIALRX_SBUS')) { + supportedRxTypes.push('SBUS'); + } + if (options.includes('USE_SERIALRX_SUMD')) { + supportedRxTypes.push('SUMD'); + } + if (options.includes('USE_SERIALRX_SUMH')) { + supportedRxTypes.push('SUMH'); + } + if (options.includes('USE_SERIALRX_XBUS')) { + supportedRxTypes.push('XBUS_MODE_B'); + supportedRxTypes.push('XBUS_MODE_B_RJ01'); + } + if (options.includes('USE_SERIALRX_IBUS')) { + supportedRxTypes.push('IBUS'); + } + if (options.includes('USE_SERIALRX_JETIEXBUS')) { + supportedRxTypes.push('JETIEXBUS'); + } + if (options.includes('USE_SERIALRX_CRSF')) { + supportedRxTypes.push('CRSF'); + } + if (options.includes('USE_SERIALRX_FPORT')) { + supportedRxTypes.push('FPORT'); + } + if (options.includes('USE_SERIALRX_SRXL2')) { + supportedRxTypes.push('SPEKTRUM SRXL2'); + } + if (options.includes('USE_SERIALRX_GHST')) { + supportedRxTypes.push('IRC GHOST'); + } + return supportedRxTypes; + } else { + return this.getSerialRxTypes(); + } + }, + calculateHardwareName() { let name; if (this.CONFIG.targetName) { diff --git a/src/js/tabs/receiver.js b/src/js/tabs/receiver.js index dbf603a6da..e8380a7359 100644 --- a/src/js/tabs/receiver.js +++ b/src/js/tabs/receiver.js @@ -251,11 +251,24 @@ receiver.initialize = function (callback) { $('select[name="rssi_channel"]').val(FC.RSSI_CONFIG.channel); + const supportedRxTypes = FC.getSupportedSerialRxTypes(); const serialRxSelectElement = $('select.serialRX'); + let allRxTypesEnabled = true; FC.getSerialRxTypes().forEach((serialRxType, index) => { - serialRxSelectElement.append(``); + const enabled = supportedRxTypes.includes(serialRxType); + if (!enabled) allRxTypesEnabled = false; + const disable = enabled ? "" : "disabled"; + serialRxSelectElement.append(``); }); + const warnRxProtocolNotInBuildOptions = function () { + const serialRxValue = parseInt($('select.serialRX').val()); + const serialRxType = FC.getSerialRxTypes()[serialRxValue]; + const supported = supportedRxTypes.includes(serialRxType); + $('.someRXTypesDisabled').toggle(supported && (! allRxTypesEnabled)); + $('.serialRXNotSupported').toggle(! supported); + }; + serialRxSelectElement.change(function () { const serialRxValue = parseInt($(this).val()); @@ -267,11 +280,15 @@ receiver.initialize = function (callback) { tab.analyticsChanges['SerialRx'] = newValue; FC.RX_CONFIG.serialrx_provider = serialRxValue; + + warnRxProtocolNotInBuildOptions(); }); // select current serial RX type serialRxSelectElement.val(FC.RX_CONFIG.serialrx_provider); + warnRxProtocolNotInBuildOptions(); + if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_46)) { serialRxSelectElement.sortSelect("NONE").select2(); } else { diff --git a/src/tabs/receiver.html b/src/tabs/receiver.html index c772a437c0..b689f212aa 100644 --- a/src/tabs/receiver.html +++ b/src/tabs/receiver.html @@ -42,6 +42,10 @@ +
+
+
+