forked from iNavFlight/inav-configurator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwizard_save_framework.js
81 lines (65 loc) · 2.39 KB
/
wizard_save_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
'use strict';
const mspHelper = require('./msp/MSPHelper');
const serialPortHelper = require('./serialPortHelper');
const FC = require('./fc');
const features = require('./feature_framework');
var wizardSaveFramework = (function () {
let self = {};
self.saveSetting = function (config, callback) {
switch (config.name) {
case 'receiverPort':
serialPortHelper.set(config.value, 'RX_SERIAL', null);
mspHelper.saveSerialPorts(callback);
break;
case 'receiverProtocol':
mspHelper.setSetting('serialrx_provider', config.value, callback);
break;
case 'gpsPort':
let gpsBit = FC.getFeatures().find( feature => feature.name === 'GPS' ).bit;
if (config.value.port == '-1') {
features.unset(gpsBit);
} else {
features.set(gpsBit);
}
serialPortHelper.set(config.value.port, 'GPS', config.value.baud);
mspHelper.saveSerialPorts(function () {
features.execute(self.enableVirtulaPitot(config, callback));
});
break;
case 'gpsProtocol':
mspHelper.setSetting('gps_provider', config.value, callback);
break;
default:
callback();
break;
}
};
self.enableVirtulaPitot = function (config, callback) {
if (config.value.port != '-1') {
mspHelper.setSetting('pitot_hardware', "VIRTUAL", callback);
} else {
callback();
}
};
self.handleSetting = function (configs, finalCallback) {
if (configs.length > 0) {
let setting = configs.shift();
self.saveSetting(setting, function () {
self.handleSetting(configs, finalCallback);
});
} else {
console.log('Nothing to save');
finalCallback();
}
};
self.persist = function (config, finalCallback) {
if (config === null || config === undefined || config.length === 0) {
finalCallback();
return;
}
let configCopy = Array.from(config);
self.handleSetting(configCopy, finalCallback);
}
return self;
})();
module.exports = wizardSaveFramework;