Skip to content

Commit

Permalink
Add ELRS SPI Model Match ID (#4104)
Browse files Browse the repository at this point in the history
* Add ELRS SPI Model Match ID

* Fixes per review

* Also gate saving
  • Loading branch information
haslinghuis authored Jul 26, 2024
1 parent 295e088 commit 1cef965
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
6 changes: 6 additions & 0 deletions locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -2191,6 +2191,12 @@
"pidTuningSliderModeHelp": {
"message": "<strong>Pid Tuning Slider Mode</strong><br><br>Pidtuning slider mode can be:<br><br>&bull; OFF - no sliders, enter values manually<br>&bull; RP - sliders control Roll and Pitch only, enter Yaw values manually<br>&bull; RPY - sliders control all PID values<br><br><span class=\"message-negative\"><b>Warning:</b></span>Going from RP to RPY mode will overwrite Yaw settings with firmware settings."
},
"receiverHelpModelId": {
"message": "If you set the Model Match below to a number other than 255, you can specify the receiver number in OpenTX/EdgeTX model setup page and turn on the Model Match in the ELRS LUA script for that model. Model match is between 0 and 63 inclusive.<br />See ELRS Documentation for more information."
},
"receiverModelId": {
"message": "Model Match ID"
},
"receiverHelp": {
"message": "&#8226; <b><strong><a href=\"https://betaflight.com/docs/wiki/guides/current/Failsafe#testing-failsafe\" target=\"_blank\" rel=\"noopener noreferrer\">Always check that your Failsafe is working properly!</a></strong></b> The settings are in the Failsafe tab, which requires Expert Mode.<br> &#8226; <b>Use the latest Tx firmware!</b><br> &#8226; <strong><a href=\"https://betaflight.com/docs/development/Rx#disabling-the-opentxedgetx-adc-filter\" target=\"_blank\" rel=\"noopener noreferrer\">Disable the hardware ADC filter</a></strong> in the Transmitter if using OpenTx or EdgeTx.<br>Basic Setup: Configure the 'Receiver' settings correctly. Choose the correct ‘Channel Map’ for your radio. Check that the Roll, Pitch and other bar graphs move correctly. Adjust the channel endpoint or range values in the transmitter to ~1000 to ~2000, and set the midpoint to 1500. For more information, read the <strong><a href=\"https://betaflight.com/docs/development/Rx\" target=\"_blank\" rel=\"noopener noreferrer\">documentation</a></strong>."
},
Expand Down
11 changes: 10 additions & 1 deletion src/js/msp/MSPHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import semver from 'semver';
import vtxDeviceStatusFactory from "../utils/VtxDeviceStatus/VtxDeviceStatusFactory";
import MSP from "../msp";
import MSPCodes from "./MSPCodes";
import { API_VERSION_1_45, API_VERSION_1_46 } from '../data_storage';
import { API_VERSION_1_45, API_VERSION_1_46, API_VERSION_1_47 } from '../data_storage';
import EscProtocols from "../utils/EscProtocols";
import huffmanDecodeBuf from "../huffman";
import { defaultHuffmanTree, defaultHuffmanLenIndex } from "../default_huffman_tree";
Expand Down Expand Up @@ -1014,6 +1014,10 @@ MspHelper.prototype.process_data = function(dataHandler) {
}
}

if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_47)) {
FC.RX_CONFIG.elrsModelId = data.readU8();
}

break;

case MSPCodes.MSP_FAILSAFE_CONFIG:
Expand Down Expand Up @@ -1906,6 +1910,11 @@ MspHelper.prototype.crunch = function(code, modifierCode = undefined) {
FC.RX_CONFIG.elrsUid.forEach(b => buffer.push8(b));
}

// Introduced in 1.47
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_47)) {
buffer.push8(FC.RX_CONFIG.elrsModelId);
}

break;

case MSPCodes.MSP_SET_FAILSAFE_CONFIG:
Expand Down
13 changes: 12 additions & 1 deletion src/js/tabs/receiver.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Model from "../model";
import RateCurve from "../RateCurve";
import MSPCodes from "../msp/MSPCodes";
import windowWatcherUtil from "../utils/window_watchers";
import CONFIGURATOR, { API_VERSION_1_45, API_VERSION_1_46 } from "../data_storage";
import CONFIGURATOR, { API_VERSION_1_45, API_VERSION_1_46, API_VERSION_1_47 } from "../data_storage";
import DarkTheme from "../DarkTheme";
import { gui_log } from "../gui_log";
import { degToRad } from "../utils/common";
Expand Down Expand Up @@ -370,6 +370,13 @@ receiver.initialize = function (callback) {
tab.elrsBindingPhraseEnabled = false;
}

if (tab.elrsBindingPhraseEnabled && semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_47)) {
$('input[name="elrsModelId-number"]').val(FC.RX_CONFIG.elrsModelId);
} else {
$('input[name="elrsModelId-number"]').parent().hide();
}


// UI Hooks

function updateSaveButton(reboot=false) {
Expand Down Expand Up @@ -471,6 +478,10 @@ receiver.initialize = function (callback) {
} else {
FC.RX_CONFIG.elrsUid = [0, 0, 0, 0, 0, 0];
}

if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_47)) {
FC.RX_CONFIG.elrsModelId = parseInt($('input[name="elrsModelId-number"]').val());
}
}

function save_rssi_config() {
Expand Down
5 changes: 5 additions & 0 deletions src/tabs/receiver.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@
<div>
<span class="elrsUid"></span>
</div>
<div class="number">
<input type="number" name="elrsModelId-number" min="0" max="255"/>
<span i18n="receiverModelId"></span>
<div class="helpicon cf_tip" i18n_title="receiverHelpModelId"></div>
</div>
</div>
</div>
</div>
Expand Down

0 comments on commit 1cef965

Please sign in to comment.