Centralised feature handler in BF_CONFIG. Switched all access to features to use the handler.

10.3.x-maintenance
mikeller 2016-07-24 23:09:51 +12:00
parent 7e7361dafd
commit 9594cbded5
12 changed files with 104 additions and 116 deletions

View File

@ -538,7 +538,13 @@
"message": "Configure via the Race Transponder tab after enabling."
},
"featureAIRMODE": {
"message": "Airmode always enabled!"
"message": "Permanently enable Airmode"
},
"featureSUPEREXPO_RATES": {
"message": "Super Expo Rates"
},
"featureOSD": {
"message": "On Screen Display"
},
"configurationFeatureEnabled": {
"message": "Enabled"
@ -1610,12 +1616,6 @@
"pidTuningYaw": {
"message": "Yaw (Hz)"
},
"pidTuningSuperExpo": {
"message": "Enable SuperExpo Rates"
},
"pidTuningRatesSuperExpoHelp": {
"message": "This setting controls the feature 'SUPEREXPO_RATES'"
},
"pidTuningVbatPidCompensation": {
"message": "Vbat PID Compensation"
},

View File

@ -35,7 +35,7 @@ var Features = function (config) {
);
}
if (semver.gte(config.flightControllerVersion, "2.8.0")) {
if (config.flightControllerVersion !== '' && semver.gte(config.flightControllerVersion, "2.8.0")) {
features.push(
{bit: 22, group: 'other', name: 'AIRMODE'},
{bit: 23, group: 'pidTuning', name: 'SUPEREXPO_RATES'},
@ -44,20 +44,34 @@ var Features = function (config) {
}
this._features = features;
this._featureMask = 0;
}
Features.prototype.isFeatureEnabled = function (featureSet, featureName) {
Features.prototype.getMask = function () {
return this._featureMask;
}
Features.prototype.setMask = function (featureMask) {
this._featureMask = featureMask;
}
Features.prototype.isEnabled = function (featureName) {
var features = this._features;
var featureMask = this._featureMask;
for (var i = 0; i < features.length; i++) {
if (features[i].name === featureName && bit_check(featureSet, features[i].bit)) {
if (features[i].name === featureName && bit_check(featureMask, features[i].bit)) {
return true;
}
}
return false;
}
Features.prototype.generateElements = function (featuresElements, radioGroups) {
Features.prototype.generateElements = function (featuresElements) {
var features = this._features;
var featureMask = this._featureMask;
var radioGroups = [];
for (var i = 0; i < features.length; i++) {
var row_e;
@ -83,7 +97,7 @@ Features.prototype.generateElements = function (featuresElements, radioGroups) {
+ feature_tip_html + '</td></tr>');
radioGroups.push(features[i].group);
} else {
row_e = $('<tr><td><input class="feature toggle"'
row_e = $('<tr><td><input class="feature toggle" id="feature-'
+ i
+ '" name="'
+ features[i].name
@ -98,7 +112,7 @@ Features.prototype.generateElements = function (featuresElements, radioGroups) {
var feature_e = row_e.find('input.feature');
feature_e.prop('checked', bit_check(BF_CONFIG.features, features[i].bit));
feature_e.prop('checked', bit_check(featureMask, features[i].bit));
feature_e.data('bit', features[i].bit);
}
@ -108,17 +122,29 @@ Features.prototype.generateElements = function (featuresElements, radioGroups) {
}
});
}
for (var i = 0; i < radioGroups.length; i++) {
var group = radioGroups[i];
var controlElements = $('input[name="' + group + '"].feature');
controlElements.each(function() {
var bit = parseInt($(this).attr('value'));
var state = bit_check(featureMask, bit);
$(this).prop('checked', state);
});
}
}
Features.prototype.updateData = function (featureSet, featureElement) {
Features.prototype.updateData = function (featureElement) {
switch (featureElement.attr('type')) {
case 'checkbox':
var bit = featureElement.data('bit');
if (featureElement.is(':checked')) {
featureSet = bit_set(featureSet, bit);
this._featureMask = bit_set(this._featureMask, bit);
} else {
featureSet = bit_clear(featureSet, bit);
this._featureMask = bit_clear(this._featureMask, bit);
}
break;
@ -130,15 +156,13 @@ Features.prototype.updateData = function (featureSet, featureElement) {
controlElements.each(function() {
var bit = $(this).val();
if (selectedBit === bit) {
featureSet = bit_set(BF_CONFIG.featureSet, bit);
this._featureMask = bit_set(BF_CONFIG.this._featureMask, bit);
} else {
featureSet = bit_clear(featureSet, bit);
this._featureMask = bit_clear(this._featureMask, bit);
}
});
break;
}
return featureSet;
}

View File

@ -67,7 +67,7 @@ var FC = {
BF_CONFIG = {
mixerConfiguration: 0,
features: 0,
features: new Features(CONFIG),
serialrx_type: 0,
board_align_roll: 0,
board_align_pitch: 0,

View File

@ -700,7 +700,7 @@ var MSP = {
break;
case MSP_codes.MSP_BF_CONFIG:
BF_CONFIG.mixerConfiguration = data.getUint8(0);
BF_CONFIG.features = data.getUint32(1, 1);
BF_CONFIG.features.setMask(data.getUint32(1, 1));
BF_CONFIG.serialrx_type = data.getUint8(5);
BF_CONFIG.board_align_roll = data.getInt16(6, 1); // -180 - 360
BF_CONFIG.board_align_pitch = data.getInt16(8, 1); // -180 - 360
@ -708,9 +708,7 @@ var MSP = {
BF_CONFIG.currentscale = data.getInt16(12, 1);
BF_CONFIG.currentoffset = data.getUint16(14, 1);
if (this.features) {
updateTabList(BF_CONFIG.features, this.features);
}
updateTabList(BF_CONFIG.features);
break;
case MSP_codes.MSP_SET_BF_CONFIG:
@ -730,11 +728,6 @@ var MSP = {
CONFIG.mspProtocolVersion = data.getUint8(offset++);
CONFIG.apiVersion = data.getUint8(offset++) + '.' + data.getUint8(offset++) + '.0';
if ((!this.features || CONFIG.apiVersion !== apiVersion)
&& CONFIG.flightControllerVersion !== '') {
this.features = new Features(CONFIG);
}
break;
case MSP_codes.MSP_FC_VARIANT:
@ -752,12 +745,6 @@ var MSP = {
CONFIG.flightControllerVersion = data.getUint8(offset++) + '.' + data.getUint8(offset++) + '.' + data.getUint8(offset++);
if ((!this.features
|| CONFIG.flightControllerVersion !== flightControllerVersion)
&& CONFIG.apiVersion !== '') {
this.features = new Features(CONFIG);
}
break;
case MSP_codes.MSP_BUILD_INFO:
@ -1380,11 +1367,12 @@ MSP.crunch = function (code) {
switch (code) {
case MSP_codes.MSP_SET_BF_CONFIG:
var featureMask = BF_CONFIG.features.getMask();
buffer.push(BF_CONFIG.mixerConfiguration);
buffer.push(specificByte(BF_CONFIG.features, 0));
buffer.push(specificByte(BF_CONFIG.features, 1));
buffer.push(specificByte(BF_CONFIG.features, 2));
buffer.push(specificByte(BF_CONFIG.features, 3));
buffer.push(specificByte(featureMask, 0));
buffer.push(specificByte(featureMask, 1));
buffer.push(specificByte(featureMask, 2));
buffer.push(specificByte(featureMask, 3));
buffer.push(BF_CONFIG.serialrx_type);
buffer.push(specificByte(BF_CONFIG.board_align_roll, 0));
buffer.push(specificByte(BF_CONFIG.board_align_roll, 1));

View File

@ -265,6 +265,8 @@ function onConnect() {
$('#tabs ul.mode-connected-cli').show();
if (CONFIG.flightControllerVersion !== '') {
BF_CONFIG.features = new Features(CONFIG);
$('#tabs ul.mode-connected').show();
if (semver.gte(CONFIG.flightControllerVersion, "3.0.0")) {

12
main.js
View File

@ -399,32 +399,32 @@ function updateActivatedTab() {
$('a', activeTab).trigger('click');
}
function updateTabList(featureSet, features) {
if (features.isFeatureEnabled(featureSet, 'GPS')) {
function updateTabList(features) {
if (features.isEnabled('GPS')) {
$('#tabs ul.mode-connected li.tab_gps').show();
} else {
$('#tabs ul.mode-connected li.tab_gps').hide();
}
if (features.isFeatureEnabled(featureSet, 'LED_STRIP')) {
if (features.isEnabled('LED_STRIP')) {
$('#tabs ul.mode-connected li.tab_led_strip').show();
} else {
$('#tabs ul.mode-connected li.tab_led_strip').hide();
}
if (features.isFeatureEnabled(featureSet, 'BLACKBOX')) {
if (features.isEnabled('BLACKBOX')) {
$('#tabs ul.mode-connected li.tab_onboard_logging').show();
} else {
$('#tabs ul.mode-connected li.tab_onboard_logging').hide();
}
if (features.isFeatureEnabled(featureSet, 'TRANSPONDER')) {
if (features.isEnabled('TRANSPONDER')) {
$('#tabs ul.mode-connected li.tab_transponder').show();
} else {
$('#tabs ul.mode-connected li.tab_transponder').hide();
}
if (features.isFeatureEnabled(featureSet, 'OSD')) {
if (features.isEnabled('OSD')) {
$('#tabs ul.mode-connected li.tab_osd').show();
} else {
$('#tabs ul.mode-connected li.tab_osd').hide();

View File

@ -129,30 +129,14 @@ TABS.configuration.initialize = function (callback, scrollPosition) {
// select current mixer configuration
mixer_list_e.val(BF_CONFIG.mixerConfiguration).change();
var features = new Features(CONFIG);
var radioGroups = [];
var features_e = $('.features');
features.generateElements(features_e, radioGroups);
BF_CONFIG.features.generateElements(features_e);
// translate to user-selected language
localize();
for (var i = 0; i < radioGroups.length; i++) {
var group = radioGroups[i];
var controls_e = $('input[name="' + group + '"].feature');
controls_e.each(function() {
var bit = parseInt($(this).attr('value'));
var state = bit_check(BF_CONFIG.features, bit);
$(this).prop('checked', state);
});
}
var alignments = [
'CW 0°',
'CW 90°',
@ -413,7 +397,7 @@ TABS.configuration.initialize = function (callback, scrollPosition) {
$('input[name="autodisarmdelay"]').val(ARMING_CONFIG.auto_disarm_delay);
$('input[name="disarmkillswitch"]').prop('checked', ARMING_CONFIG.disarm_kill_switch);
$('div.disarm').show();
if (features.isFeatureEnabled(BF_CONFIG.features, 'MOTOR_STOP')) {
if (BF_CONFIG.features.isEnabled('MOTOR_STOP')) {
$('div.disarmdelay').show();
} else {
$('div.disarmdelay').hide();
@ -457,11 +441,11 @@ TABS.configuration.initialize = function (callback, scrollPosition) {
$('input.feature', features_e).change(function () {
var element = $(this);
BF_CONFIG.features = features.updateData(BF_CONFIG.features, element);
updateTabList(BF_CONFIG.features, features);
BF_CONFIG.features.updateData(element);
updateTabList(BF_CONFIG.features);
if (element.attr('name') === 'MOTOR_STOP') {
if (features.isFeatureEnabled(BF_CONFIG.features, 'MOTOR_STOP')) {
if (BF_CONFIG.features.isEnabled('MOTOR_STOP')) {
$('div.disarmdelay').show();
} else {
$('div.disarmdelay').hide();

View File

@ -176,7 +176,7 @@ TABS.motors.initialize = function (callback) {
// translate to user-selected language
localize();
self.feature3DEnabled = bit_check(BF_CONFIG.features, 12);
self.feature3DEnabled = BF_CONFIG.features.isEnabled('3D');
if (self.feature3DEnabled && !self.feature3DSupported) {
self.allowTestMode = false;

View File

@ -94,7 +94,7 @@ TABS.onboard_logging.initialize = function (callback) {
* The best we can do on those targets is check the BLACKBOX feature bit to identify support for Blackbox instead.
*/
if (BLACKBOX.supported || DATAFLASH.supported
|| semver.gte(CONFIG.flightControllerVersion, "1.5.0") && semver.lte(CONFIG.flightControllerVersion, "1.10.0") && bit_check(BF_CONFIG.features, 19)) {
|| semver.gte(CONFIG.flightControllerVersion, "1.5.0") && semver.lte(CONFIG.flightControllerVersion, "1.10.0") && BF_CONFIG.features.isEnabled('BLACKBOX')) {
blackboxSupport = 'yes';
} else if (semver.gte(CONFIG.flightControllerVersion, "1.5.0") && semver.lte(CONFIG.flightControllerVersion, "1.10.0")) {
blackboxSupport = 'maybe';

View File

@ -41,6 +41,27 @@
<form name="pid-tuning" id="pid-tuning">
<div class="clear-both"></div>
<div class="cf_column twothird">
<div class="gui_box grey">
<table class="new_rates">
<tbody class="features pidTuning">
<!-- table generated here -->
</tbody>
<tr>
<td>
<input type="checkbox" name="vbatpidcompensation" class="toggle" />
</td>
<td></td>
<td>
<div>
<label for="vbatpidcompensation">
<span i18n="pidTuningVbatPidCompensation"></span>
</label>
<div class="helpicon cf_tip" i18n_title="pidTuningVbatPidCompensationHelp"></div>
</div>
</td>
</tr>
</table>
</div>
<div class="gui_box grey">
<table class="pid_titlebar">
<tr>
@ -62,30 +83,6 @@
</div>
</th>
</tr>
<tr class="new_rates">
<td colspan=3>
<div class="checkbox super_expo_checkbox" style="margin-top: 10px;">
<div style="float: left; margin-right: 5px; margin-left: 3px; margin-bottom: 5px;">
<input type="checkbox" name="show_superexpo_rates" class="toggle" />
</div>
<label for="showSuperExpoRates">
<span i18n="pidTuningSuperExpo"></span>
</label>
<div class="helpicon cf_tip" i18n_title="pidTuningRatesSuperExpoHelp"></div>
</div>
</td>
<td colspan=4>
<div class="checkbox vbat_compensation_checkbox" style="margin-top: 10px;">
<div style="float: left; margin-right: 5px; margin-left: 3px; margin-bottom: 5px;">
<input type="checkbox" name="vbatpidcompensation" class="toggle" />
</div>
<label for="vbatpidcompensation">
<span i18n="pidTuningVbatPidCompensation"></span>
</label>
<div class="helpicon cf_tip" i18n_title="pidTuningVbatPidCompensationHelp"></div>
</div>
</td>
</tr>
<tr class="ROLL">
<!-- 0 -->
<td bgcolor="#FF8080"></td>

View File

@ -4,8 +4,6 @@ TABS.pid_tuning = {
controllerChanged: false
};
var SUPEREXPO_FEATURE_BIT = 23;
TABS.pid_tuning.initialize = function (callback) {
var self = this;
if (GUI.active_tab != 'pid_tuning') {
@ -42,13 +40,7 @@ TABS.pid_tuning.initialize = function (callback) {
});
function pid_and_rc_to_form() {
if (semver.gte(CONFIG.flightControllerVersion, "2.8.0")) {
//This will need to be reworked to remove BF_CONFIG reference eventually
$('.pid_tuning input[name="show_superexpo_rates"]').prop(
'checked', bit_check(BF_CONFIG.features, SUPEREXPO_FEATURE_BIT));
}
if (semver.gte(CONFIG.flightControllerVersion, "2.8.0")) {
if (semver.gte(CONFIG.flightControllerVersion, "2.8.1")) {
$('input[name="vbatpidcompensation"]').prop('checked', ADVANCED_TUNING.vbatPidCompensation !== 0);
}
@ -220,12 +212,7 @@ TABS.pid_tuning.initialize = function (callback) {
function form_to_pid_and_rc() {
if (semver.gte(CONFIG.flightControllerVersion, "2.8.0")) {
//This will need to be reworked to remove BF_CONFIG reference eventually
if ($('.pid_tuning input[name="show_superexpo_rates"]').is(':checked')) {
BF_CONFIG.features = bit_set(BF_CONFIG.features, SUPEREXPO_FEATURE_BIT);
} else {
BF_CONFIG.features = bit_clear(BF_CONFIG.features, SUPEREXPO_FEATURE_BIT);
}
BF_CONFIG.features.updateData($('.pid_tuning input[name="SUPEREXPO_RATES"]'));
}
if (semver.gte(CONFIG.flightControllerVersion, "2.8.1")) {
@ -335,7 +322,7 @@ TABS.pid_tuning.initialize = function (callback) {
$('#pid_mag').show();
showTitle = true;
}
if (bit_check(BF_CONFIG.features, 7)) { //This will need to be reworked to remove BF_CONFIG reference eventually
if (BF_CONFIG.features.isEnabled('GPS')) {
$('#pid_gps').show();
showTitle = true;
}
@ -410,6 +397,12 @@ TABS.pid_tuning.initialize = function (callback) {
}
function process_html() {
if (semver.gte(CONFIG.flightControllerVersion, "2.8.0")) {
var features_e = $('.features');
BF_CONFIG.features.generateElements(features_e);
}
// translate to user-selected language
localize();
@ -422,7 +415,7 @@ TABS.pid_tuning.initialize = function (callback) {
rc_rate_yaw: SPECIAL_PARAMETERS.RC_RATE_YAW,
rc_expo: RC_tuning.RC_EXPO,
rc_yaw_expo: RC_tuning.RC_YAW_EXPO,
superexpo: bit_check(BF_CONFIG.features, SUPEREXPO_FEATURE_BIT)
superexpo: BF_CONFIG.features.isEnabled('SUPEREXPO_RATES')
};
if (CONFIG.flightControllerIdentifier !== "BTFL" || semver.lt(CONFIG.flightControllerVersion, "2.8.1")) {
@ -559,13 +552,13 @@ TABS.pid_tuning.initialize = function (callback) {
self.currentRates.pitch_rate = targetValue;
updateNeeded = true;
}
}
if (targetElement.attr('name') === 'show_superexpo_rates') {
if (targetElement.attr('name') === 'SUPEREXPO_RATES') {
self.currentRates.superexpo = targetElement.is(':checked');
updateNeeded = true;
}
}
if (updateNeeded) {
var curveHeight = rcCurveElement.height;
@ -598,7 +591,7 @@ TABS.pid_tuning.initialize = function (callback) {
// UI Hooks
// curves
$('.pid_tuning').on('input change', updateRates);
$('.super_expo_checkbox').on('input change', updateRates).trigger('input');
$('input.feature').on('input change', updateRates).trigger('input');
$('.throttle input').on('input change', function () {
setTimeout(function () { // let global validation trigger and adjust the values first

View File

@ -273,7 +273,7 @@ TABS.receiver.initialize = function (callback) {
});
// Only show the MSP control sticks if the MSP Rx feature is enabled
$(".sticks_btn").toggle(bit_check(BF_CONFIG.features, 14 /* RX_MSP */));
$(".sticks_btn").toggle(BF_CONFIG.features.isEnabled('RX_MSP'));
$('select[name="rx_refresh_rate"]').change(function () {
var plot_update_rate = parseInt($(this).val(), 10);
@ -405,7 +405,7 @@ TABS.receiver.initModelPreview = function () {
this.useSuperExpo = false;
if (CONFIG.flightControllerIdentifier === 'BTFL' && semver.gte(CONFIG.flightControllerVersion, '2.8.0')) {
this.useSuperExpo = bit_check(BF_CONFIG.features, SUPEREXPO_FEATURE_BIT);
this.useSuperExpo = BF_CONFIG.features.isEnabled('SUPEREXPO_RATES');
}
this.rateCurve = new RateCurve(CONFIG.flightControllerIdentifier !== 'BTFL' || semver.lt(CONFIG.flightControllerVersion, '2.8.0'));