Skip to content

Commit

Permalink
Warn when selected rx protocol is not in build configuration (#4150)
Browse files Browse the repository at this point in the history
* 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 <michal@herko.it>
Co-authored-by: nerdCopter <56646290+nerdCopter@users.noreply.github.com>
  • Loading branch information
3 people authored Sep 3, 2024
1 parent 297efbe commit d885182
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 1 deletion.
6 changes: 6 additions & 0 deletions locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
49 changes: 49 additions & 0 deletions src/js/fc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
19 changes: 18 additions & 1 deletion src/js/tabs/receiver.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(`<option value="${index}">${serialRxType}</option>`);
const enabled = supportedRxTypes.includes(serialRxType);
if (!enabled) allRxTypesEnabled = false;
const disable = enabled ? "" : "disabled";
serialRxSelectElement.append(`<option value="${index}" ${disable} >${serialRxType}</option>`);
});

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());

Expand All @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions src/tabs/receiver.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@
<!-- list generated here -->
</select>
<span i18n="configurationSerialRX"></span>
<div class="note someRXTypesDisabled" i18n="someRXTypesDisabled">
</div>
<div class="note serialRXNotSupported" i18n="serialRXNotSupported">
</div>
</div>
<div class="spiRxBox spacer_box">
<div class="note">
Expand Down

0 comments on commit d885182

Please sign in to comment.