mirror of
https://github.com/iNavFlight/inav-configurator.git
synced 2025-07-13 11:29:53 +03:00
Basic framework to work with features
This commit is contained in:
parent
0fbdc439ce
commit
78fbb84f9e
3 changed files with 76 additions and 10 deletions
|
@ -114,6 +114,7 @@ sources.js = [
|
||||||
'./tabs/advanced_tuning.js',
|
'./tabs/advanced_tuning.js',
|
||||||
'./js/peripherals.js',
|
'./js/peripherals.js',
|
||||||
'./js/appUpdater.js',
|
'./js/appUpdater.js',
|
||||||
|
'./js/feature_framework.js',
|
||||||
'./js/defaults_dialog.js',
|
'./js/defaults_dialog.js',
|
||||||
'./node_modules/openlayers/dist/ol.js'
|
'./node_modules/openlayers/dist/ol.js'
|
||||||
];
|
];
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
/*global mspHelper,$,GUI,MSP,BF_CONFIG,chrome*/
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var helper = helper || {};
|
var helper = helper || {};
|
||||||
|
@ -192,20 +193,17 @@ helper.defaultsDialog = (function() {
|
||||||
privateScope.setFeaturesBits = function (selectedDefaultPreset) {
|
privateScope.setFeaturesBits = function (selectedDefaultPreset) {
|
||||||
|
|
||||||
if (selectedDefaultPreset.features && selectedDefaultPreset.features.length > 0) {
|
if (selectedDefaultPreset.features && selectedDefaultPreset.features.length > 0) {
|
||||||
|
helper.features.reset();
|
||||||
|
|
||||||
for (let i in selectedDefaultPreset.features) {
|
for (const feature of selectedDefaultPreset.features) {
|
||||||
if (selectedDefaultPreset.features.hasOwnProperty(i)) {
|
if (feature.state) {
|
||||||
let feature = selectedDefaultPreset.features[i];
|
helper.features.set(feature.bit);
|
||||||
|
} else {
|
||||||
if (feature.state) {
|
helper.features.unset(feature.bit);
|
||||||
BF_CONFIG.features = bit_set(BF_CONFIG.features, feature.bit);
|
|
||||||
} else {
|
|
||||||
BF_CONFIG.features = bit_clear(BF_CONFIG.features, feature.bit);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mspHelper.saveBfConfig(function () {
|
helper.features.execute(function () {
|
||||||
privateScope.setSettings(selectedDefaultPreset);
|
privateScope.setSettings(selectedDefaultPreset);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|
67
js/feature_framework.js
Normal file
67
js/feature_framework.js
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
/*global mspHelper,BF_CONFIG*/
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
var helper = helper || {};
|
||||||
|
|
||||||
|
/*
|
||||||
|
Helper to work with FEATURES via MSP
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
|
||||||
|
1. Reset everything
|
||||||
|
helper.features.reset();
|
||||||
|
|
||||||
|
2. Push feature bits you want to set
|
||||||
|
helper.features.set(5);
|
||||||
|
|
||||||
|
3. Push feature bits you want to unset
|
||||||
|
helper.features.set(8);
|
||||||
|
|
||||||
|
4. Execute and provide a callback that will be executed after MSP is done
|
||||||
|
helper.features.execute(function () {
|
||||||
|
//Do things crap over here
|
||||||
|
});
|
||||||
|
|
||||||
|
*/
|
||||||
|
helper.features = (function() {
|
||||||
|
|
||||||
|
let publicScope = {},
|
||||||
|
privateScope = {};
|
||||||
|
|
||||||
|
let toSet = [],
|
||||||
|
toUnset = [],
|
||||||
|
exitPoint;
|
||||||
|
|
||||||
|
publicScope.reset = function () {
|
||||||
|
toSet = [];
|
||||||
|
toUnset = [];
|
||||||
|
};
|
||||||
|
|
||||||
|
publicScope.set = function (bit) {
|
||||||
|
toSet.push(bit);
|
||||||
|
};
|
||||||
|
|
||||||
|
publicScope.unset = function (bit) {
|
||||||
|
toUnset.push(bit);
|
||||||
|
};
|
||||||
|
|
||||||
|
publicScope.execute = function(callback) {
|
||||||
|
exitPoint = callback;
|
||||||
|
mspHelper.loadBfConfig(privateScope.setBits);
|
||||||
|
};
|
||||||
|
|
||||||
|
privateScope.setBits = function () {
|
||||||
|
|
||||||
|
for (const bit of toSet) {
|
||||||
|
BF_CONFIG.features = bit_set(BF_CONFIG.features, bit);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const bit of toUnset) {
|
||||||
|
BF_CONFIG.features = bit_clear(BF_CONFIG.features, bit);
|
||||||
|
}
|
||||||
|
|
||||||
|
mspHelper.saveBfConfig(exitPoint);
|
||||||
|
}
|
||||||
|
|
||||||
|
return publicScope;
|
||||||
|
})();
|
Loading…
Add table
Add a link
Reference in a new issue