mirror of
https://github.com/betaflight/betaflight-configurator.git
synced 2025-07-15 20:35:23 +03:00
Enable or disable features according to port configuration (#2840)
This commit is contained in:
parent
717d7f6685
commit
4df7f5b9fb
2 changed files with 81 additions and 15 deletions
|
@ -33,27 +33,27 @@ const Features = function (config) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (semver.gte(FC.CONFIG.apiVersion, "1.15.0") && !semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_36)) {
|
if (semver.gte(config.apiVersion, "1.15.0") && !semver.gte(config.apiVersion, API_VERSION_1_36)) {
|
||||||
features.push(
|
features.push(
|
||||||
{bit: 8, group: 'rxFailsafe', name: 'FAILSAFE', haveTip: true},
|
{bit: 8, group: 'rxFailsafe', name: 'FAILSAFE', haveTip: true},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (semver.gte(FC.CONFIG.apiVersion, "1.16.0")) {
|
if (semver.gte(config.apiVersion, "1.16.0")) {
|
||||||
features.push(
|
features.push(
|
||||||
{bit: 21, group: 'other', name: 'TRANSPONDER', haveTip: true},
|
{bit: 21, group: 'other', name: 'TRANSPONDER', haveTip: true},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.flightControllerVersion !== '') {
|
if (config.flightControllerVersion !== '') {
|
||||||
if (semver.gte(FC.CONFIG.apiVersion, "1.16.0")) {
|
if (semver.gte(config.apiVersion, "1.16.0")) {
|
||||||
features.push(
|
features.push(
|
||||||
{bit: 22, group: 'other', name: 'AIRMODE'},
|
{bit: 22, group: 'other', name: 'AIRMODE'},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (semver.gte(FC.CONFIG.apiVersion, "1.16.0")) {
|
if (semver.gte(config.apiVersion, "1.16.0")) {
|
||||||
if (semver.lt(FC.CONFIG.apiVersion, "1.20.0")) {
|
if (semver.lt(config.apiVersion, "1.20.0")) {
|
||||||
features.push(
|
features.push(
|
||||||
{bit: 23, group: 'superexpoRates', name: 'SUPEREXPO_RATES'},
|
{bit: 23, group: 'superexpoRates', name: 'SUPEREXPO_RATES'},
|
||||||
);
|
);
|
||||||
|
@ -64,36 +64,36 @@ const Features = function (config) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (semver.gte(FC.CONFIG.apiVersion, "1.20.0")) {
|
if (semver.gte(config.apiVersion, "1.20.0")) {
|
||||||
features.push(
|
features.push(
|
||||||
{bit: 18, group: 'other', name: 'OSD'},
|
{bit: 18, group: 'other', name: 'OSD'},
|
||||||
);
|
);
|
||||||
if (!semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_35)) {
|
if (!semver.gte(config.apiVersion, API_VERSION_1_35)) {
|
||||||
features.push(
|
features.push(
|
||||||
{bit: 24, group: 'other', name: 'VTX'},
|
{bit: 24, group: 'other', name: 'VTX'},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_31)) {
|
if (semver.gte(config.apiVersion, API_VERSION_1_31)) {
|
||||||
features.push(
|
features.push(
|
||||||
{bit: 25, group: 'rxMode', mode: 'select', name: 'RX_SPI'},
|
{bit: 25, group: 'rxMode', mode: 'select', name: 'RX_SPI'},
|
||||||
{bit: 27, group: 'escSensor', name: 'ESC_SENSOR'},
|
{bit: 27, group: 'escSensor', name: 'ESC_SENSOR'},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_36)) {
|
if (semver.gte(config.apiVersion, API_VERSION_1_36)) {
|
||||||
features.push(
|
features.push(
|
||||||
{bit: 28, group: 'antiGravity', name: 'ANTI_GRAVITY', haveTip: true, hideName: true},
|
{bit: 28, group: 'antiGravity', name: 'ANTI_GRAVITY', haveTip: true, hideName: true},
|
||||||
);
|
);
|
||||||
if (semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_44)) { // DYNAMIC_FILTER got removed from FEATURES in BF 4.3 / API 1.44
|
if (semver.lt(config.apiVersion, API_VERSION_1_44)) { // DYNAMIC_FILTER got removed from FEATURES in BF 4.3 / API 1.44
|
||||||
features.push(
|
features.push(
|
||||||
{bit: 29, group: 'other', name: 'DYNAMIC_FILTER'},
|
{bit: 29, group: 'other', name: 'DYNAMIC_FILTER'},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_36)) {
|
if (!semver.gte(config.apiVersion, API_VERSION_1_36)) {
|
||||||
features.push(
|
features.push(
|
||||||
{bit: 1, group: 'batteryVoltage', name: 'VBAT'},
|
{bit: 1, group: 'batteryVoltage', name: 'VBAT'},
|
||||||
{bit: 11, group: 'batteryCurrent', name: 'CURRENT_METER'},
|
{bit: 11, group: 'batteryCurrent', name: 'CURRENT_METER'},
|
||||||
|
@ -125,14 +125,34 @@ Features.prototype.setMask = function (featureMask) {
|
||||||
Features.prototype.isEnabled = function (featureName) {
|
Features.prototype.isEnabled = function (featureName) {
|
||||||
const self = this;
|
const self = this;
|
||||||
|
|
||||||
for (let i = 0; i < self._features.length; i++) {
|
for (const element of self._features) {
|
||||||
if (self._features[i].name === featureName && bit_check(self._featureMask, self._features[i].bit)) {
|
if (element.name === featureName && bit_check(self._featureMask, element.bit)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Features.prototype.enable = function (featureName) {
|
||||||
|
const self = this;
|
||||||
|
|
||||||
|
for (const element of self._features) {
|
||||||
|
if (element.name === featureName) {
|
||||||
|
self._featureMask = bit_set(self._featureMask, element.bit);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Features.prototype.disable = function (featureName) {
|
||||||
|
const self = this;
|
||||||
|
|
||||||
|
for (const element of self._features) {
|
||||||
|
if (element.name === featureName) {
|
||||||
|
self._featureMask = bit_clear(self._featureMask, element.bit);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
Features.prototype.generateElements = function (featuresElements) {
|
Features.prototype.generateElements = function (featuresElements) {
|
||||||
const self = this;
|
const self = this;
|
||||||
|
|
||||||
|
|
|
@ -124,6 +124,7 @@ ports.initialize = function (callback) {
|
||||||
} else {
|
} else {
|
||||||
promise = Promise.resolve();
|
promise = Promise.resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
promise.then(function() {
|
promise.then(function() {
|
||||||
mspHelper.loadSerialConfig(on_configuration_loaded_handler);
|
mspHelper.loadSerialConfig(on_configuration_loaded_handler);
|
||||||
});
|
});
|
||||||
|
@ -385,7 +386,7 @@ ports.initialize = function (callback) {
|
||||||
// update configuration based on current ui state
|
// update configuration based on current ui state
|
||||||
FC.SERIAL_CONFIG.ports = [];
|
FC.SERIAL_CONFIG.ports = [];
|
||||||
|
|
||||||
$('.tab-ports .portConfiguration').each(function (port, portConfig) {
|
$('.tab-ports .portConfiguration').each(function (_port, portConfig) {
|
||||||
|
|
||||||
const serialPort = $(portConfig).data('serialPort');
|
const serialPort = $(portConfig).data('serialPort');
|
||||||
|
|
||||||
|
@ -426,10 +427,55 @@ ports.initialize = function (callback) {
|
||||||
blackbox_baudrate: blackboxBaudrate,
|
blackbox_baudrate: blackboxBaudrate,
|
||||||
identifier: serialPort.identifier,
|
identifier: serialPort.identifier,
|
||||||
};
|
};
|
||||||
|
|
||||||
FC.SERIAL_CONFIG.ports.push(serialPortConfig);
|
FC.SERIAL_CONFIG.ports.push(serialPortConfig);
|
||||||
});
|
});
|
||||||
|
|
||||||
mspHelper.sendSerialConfig(save_to_eeprom);
|
// enable / disable features based on port configuration
|
||||||
|
const func = serialPortConfig.functions;
|
||||||
|
const featureConfig = FC.FEATURE_CONFIG.features;
|
||||||
|
|
||||||
|
const enableRxSerial = func.includes('RX_SERIAL');
|
||||||
|
const enableTelemetry = func.some(e => e.startsWith("TELEMETRY"));
|
||||||
|
const enableBlackbox = func.includes('BLACKBOX');
|
||||||
|
const enableEsc = func.includes('ESC_SENSOR');
|
||||||
|
const enableGps = func.includes('GPS');
|
||||||
|
|
||||||
|
if (enableRxSerial) {
|
||||||
|
featureConfig.enable('RX_SERIAL');
|
||||||
|
} else {
|
||||||
|
featureConfig.disable('RX_SERIAL');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (enableTelemetry) {
|
||||||
|
featureConfig.enable('TELEMETRY');
|
||||||
|
} else {
|
||||||
|
featureConfig.disable('TELEMETRY');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (enableBlackbox) {
|
||||||
|
featureConfig.enable('BLACKBOX');
|
||||||
|
} else {
|
||||||
|
featureConfig.disable('BLACKBOX');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (enableEsc) {
|
||||||
|
featureConfig.enable('ESC_SENSOR');
|
||||||
|
} else {
|
||||||
|
featureConfig.disable('ESC_SENSOR');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (enableGps) {
|
||||||
|
featureConfig.enable('GPS');
|
||||||
|
} else {
|
||||||
|
featureConfig.disable('GPS');
|
||||||
|
}
|
||||||
|
|
||||||
|
mspHelper.sendSerialConfig(save_features);
|
||||||
|
|
||||||
|
function save_features() {
|
||||||
|
MSP.send_message(MSPCodes.MSP_SET_FEATURE_CONFIG, mspHelper.crunch(MSPCodes.MSP_SET_FEATURE_CONFIG), false, save_to_eeprom);
|
||||||
|
}
|
||||||
|
|
||||||
function save_to_eeprom() {
|
function save_to_eeprom() {
|
||||||
MSP.send_message(MSPCodes.MSP_EEPROM_WRITE, false, false, on_saved_handler);
|
MSP.send_message(MSPCodes.MSP_EEPROM_WRITE, false, false, on_saved_handler);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue