forked from iNavFlight/inav-configurator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfeature_framework.js
91 lines (66 loc) · 1.97 KB
/
feature_framework.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
'use strict';
/*
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
});
*/
const mspHelper = require('./msp/MSPHelper');
const BitHelper = require('./bitHelper');
const FC = require('./fc');
var 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.updateUI = function ($container, values) {
$container.find('[data-bit].feature').each(function () {
let $this = $(this);
$this.prop('checked', BitHelper.bit_check(values, $this.attr("data-bit")));
});
};
publicScope.fromUI = function ($container) {
$container.find('[data-bit].feature').each(function () {
let $this = $(this);
if ($this.is(":checked")) {
publicScope.set($this.attr("data-bit"));
} else {
publicScope.unset($this.attr("data-bit"));
}
});
};
publicScope.execute = function(callback) {
exitPoint = callback;
mspHelper.loadFeatures(privateScope.setBits);
};
privateScope.setBits = function () {
for (const bit of toSet) {
FC.FEATURES = BitHelper.bit_set(FC.FEATURES, bit);
}
for (const bit of toUnset) {
FC.FEATURES = BitHelper.bit_clear(FC.FEATURES, bit);
}
mspHelper.saveFeatures(exitPoint);
}
return publicScope;
})();
module.exports = features;