1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-24 16:55:36 +03:00

implement channel map including validation and UI compatibility fallback

This commit is contained in:
cTn 2014-09-19 17:44:04 +02:00
parent 5d9b28c5c7
commit 6be76d855d
5 changed files with 136 additions and 6 deletions

View file

@ -443,6 +443,9 @@
"receiverRcExpo": {
"message": "RC Expo"
},
"receiverChannelMap": {
"message": "Channel Map"
},
"receiverRefreshRateTitle": {
"message": "Graph refresh rate"
},

View file

@ -47,9 +47,6 @@ TABS.configuration.initialize = function (callback) {
// translate to user-selected language
localize();
// index references
var RCMAPlLetters = ['A', 'E', 'R', 'T', '1', '2', '3', '4'];
// generate mixer
var mixerList = [
{name: 'Tricopter', image: 'tri'},

View file

@ -79,7 +79,7 @@
border-collapse: collapse;
}
.tab-receiver .tunings .throttle {
margin-bottom: 22px;
margin-bottom: 10px;
}
.tab-receiver .tunings table, .tab-receiver .tunings table th, .tab-receiver .tunings table td {
padding: 4px;
@ -101,6 +101,42 @@
line-height: 20px;
text-align: right;
}
.tab-receiver .rcmap_wrapper {
float: right;
position: relative;
width: 126px;
margin: 10px 0 0 0;
border: 1px solid #8b8b8b;
}
.tab-receiver .rcmap_wrapper .head {
height: 15px;
padding: 4px;
text-align: center;
font-weight: bold;
border-bottom: 1px solid #8b8b8b;
background-color: #ececec;
}
.tab-receiver .hybrid_element input {
position: absolute;
padding-left: 5px;
width: calc(100% - 24px);
height: 22px;
z-index: 2;
}
.tab-receiver .hybrid_element select {
width: 100%;
height: 22px;
z-index: 1;
}
.tab-receiver .curves {
float: right;
}

View file

@ -22,6 +22,16 @@
<td><input type="number" name="expo" step="0.01" min="0" max="1" /></td>
</tr>
</table>
<div class="rcmap_wrapper">
<div class="head" i18n="receiverChannelMap"></div>
<div class="hybrid_element">
<input type="text" name="rcmap" spellcheck="false" />
<select class="hybrid_helper" name="rcmap_helper">
<option value="AETR1234">AETR1234 - default</option>
<option value="TAER1234">TAER1234 - frsky</option>
</select>
</div>
</div>
</div>
<div class="curves">
<div class="throttle_curve">

View file

@ -7,7 +7,16 @@ TABS.receiver.initialize = function (callback) {
googleAnalytics.sendAppView('Receiver Page');
function get_rc_data() {
MSP.send_message(MSP_codes.MSP_RC, false, false, load_html);
MSP.send_message(MSP_codes.MSP_RC, false, false, get_rc_map);
}
function get_rc_map() {
// TODO remove this after compatibility period
if (bit_check(CONFIG.capability, 30)) {
MSP.send_message(MSP_codes.MSP_RCMAP, false, false, load_html);
} else {
load_html();
}
}
function load_html() {
@ -68,6 +77,66 @@ TABS.receiver.initialize = function (callback) {
meter_values_array.push($(this));
});
// handle rcmap
if (bit_check(CONFIG.capability, 30)) {
var RCMAPlLetters = ['A', 'E', 'R', 'T', '1', '2', '3', '4'];
var strBuffer = '';
for (var i = 0; i < RC_MAP.length; i++) {
strBuffer += RCMAPlLetters[RC_MAP[i]];
}
// set current value
$('input[name="rcmap"]').val(strBuffer);
// validation / filter
var last_valid = strBuffer;
$('input[name="rcmap"]').on('input', function () {
var val = $(this).val();
// limit length to max 8
if (val.length > 8) {
val = val.substr(0, 8);
}
$(this).val(val);
});
$('input[name="rcmap"]').focusout(function () {
var val = $(this).val();
var strBuffer = val.split('');
var duplicityBuffer = [];
if (val.length != 8) {
$(this).val(last_valid);
return false;
}
// check if characters inside are all valid, also check for duplicity
for (var i = 0; i < val.length; i++) {
if (RCMAPlLetters.indexOf(strBuffer[i]) < 0) {
$(this).val(last_valid);
return false;
}
if (duplicityBuffer.indexOf(strBuffer[i]) < 0) {
duplicityBuffer.push(strBuffer[i]);
} else {
$(this).val(last_valid);
return false;
}
}
});
// handle helper
$('select[name="rcmap_helper"]').change(function () {
$('input[name="rcmap"]').val($(this).val());
});
} else {
$('.rcmap_wrapper').hide();
}
// UI Hooks
// curves
$('.tunings .throttle input').change(function () {
@ -143,13 +212,28 @@ TABS.receiver.initialize = function (callback) {
RC_tuning.RC_RATE = parseFloat($('.tunings .rate input[name="rate"]').val());
RC_tuning.RC_EXPO = parseFloat($('.tunings .rate input[name="expo"]').val());
// catch rc map
var strBuffer = $('input[name="rcmap"]').val().split('');
for (var i = 0; i < RC_MAP.length; i++) {
RC_MAP[i] = RCMAPlLetters.indexOf(strBuffer[i]);
}
function save_rc_map() {
MSP.send_message(MSP_codes.MSP_SET_RCMAP, MSP.crunch(MSP_codes.MSP_SET_RCMAP), false, save_to_eeprom);
}
function save_to_eeprom() {
MSP.send_message(MSP_codes.MSP_EEPROM_WRITE, false, false, function () {
GUI.log(chrome.i18n.getMessage('receiverEepromSaved'));
});
}
MSP.send_message(MSP_codes.MSP_SET_RC_TUNING, MSP.crunch(MSP_codes.MSP_SET_RC_TUNING), false, save_to_eeprom);
if (bit_check(CONFIG.capability, 30)) {
MSP.send_message(MSP_codes.MSP_SET_RC_TUNING, MSP.crunch(MSP_codes.MSP_SET_RC_TUNING), false, save_rc_map);
} else {
MSP.send_message(MSP_codes.MSP_SET_RC_TUNING, MSP.crunch(MSP_codes.MSP_SET_RC_TUNING), false, save_to_eeprom);
}
});
$('select[name="rx_refresh_rate"]').change(function () {