Commit e1c3024 1 parent b1f5f32 commit e1c3024 Copy full SHA for e1c3024
File tree 3 files changed +53
-6
lines changed
3 files changed +53
-6
lines changed Original file line number Diff line number Diff line change @@ -78,7 +78,6 @@ var FC = {
78
78
MIXER_CONFIG : null ,
79
79
BATTERY_CONFIG : null ,
80
80
OUTPUT_MAPPING : null ,
81
- SETTINGS : null ,
82
81
BRAKING_CONFIG : null ,
83
82
SAFEHOMES : null ,
84
83
BOARD_ALIGNMENT : null ,
@@ -570,8 +569,6 @@ var FC = {
570
569
571
570
this . OUTPUT_MAPPING = new OutputMappingCollection ( ) ;
572
571
573
- this . SETTINGS = { } ;
574
-
575
572
this . SAFEHOMES = new SafehomeCollection ( ) ;
576
573
577
574
this . RATE_DYNAMICS = {
Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ const { FwApproach } = require('./../fwApproach');
20
20
const Waypoint = require ( './../waypoint' ) ;
21
21
const mspDeduplicationQueue = require ( './mspDeduplicationQueue' ) ;
22
22
const mspStatistics = require ( './mspStatistics' ) ;
23
+ const settingsCache = require ( './../settingsCache' ) ;
23
24
24
25
var mspHelper = ( function ( ) {
25
26
var self = { } ;
@@ -3060,9 +3061,12 @@ var mspHelper = (function () {
3060
3061
} ;
3061
3062
3062
3063
self . _getSetting = function ( name ) {
3063
- if ( FC . SETTINGS [ name ] ) {
3064
- return Promise . resolve ( FC . SETTINGS [ name ] ) ;
3064
+
3065
+ const storedSetting = settingsCache . get ( name ) ;
3066
+ if ( typeof storedSetting !== 'undefined' ) {
3067
+ return Promise . resolve ( storedSetting ) ;
3065
3068
}
3069
+
3066
3070
var data = [ ] ;
3067
3071
self . _encodeSettingReference ( name , null , data ) ;
3068
3072
return MSP . promise ( MSPCodes . MSP2_COMMON_SETTING_INFO , data ) . then ( function ( result ) {
@@ -3109,7 +3113,7 @@ var mspHelper = (function () {
3109
3113
}
3110
3114
setting . table = { values : values } ;
3111
3115
}
3112
- FC . SETTINGS [ name ] = setting ;
3116
+ settingsCache . set ( name , setting ) ;
3113
3117
return setting ;
3114
3118
} ) ;
3115
3119
}
Original file line number Diff line number Diff line change
1
+ 'use strict' ;
2
+
3
+ const Store = require ( 'electron-store' ) ;
4
+ const store = new Store ( ) ;
5
+ const FC = require ( './fc' ) ;
6
+
7
+ var settingsCache = ( function ( ) {
8
+
9
+ let publicScope = { } ;
10
+ let privateScope = { } ;
11
+
12
+ const SETTINGS_KEY = 'settings' ;
13
+
14
+ privateScope . getSetingKey = function ( settingName ) {
15
+ return FC . CONFIG . target + '_' + FC . CONFIG . flightControllerVersion + '_' + settingName ;
16
+ }
17
+
18
+ publicScope . flush = function ( ) {
19
+ store . delete ( SETTINGS_KEY ) ;
20
+ } ;
21
+
22
+ publicScope . get = function ( settingName ) {
23
+ let settings = store . get ( SETTINGS_KEY , null ) ;
24
+
25
+ if ( settings === null ) {
26
+ return undefined ;
27
+ }
28
+ let setting = settings [ privateScope . getSetingKey ( settingName ) ] ;
29
+ return setting ;
30
+ } ;
31
+
32
+ publicScope . set = function ( settingName , value ) {
33
+ let settings = store . get ( SETTINGS_KEY , null ) ;
34
+
35
+ if ( settings === null ) {
36
+ settings = { } ;
37
+ }
38
+
39
+ settings [ privateScope . getSetingKey ( settingName ) ] = value ;
40
+ store . set ( SETTINGS_KEY , settings ) ;
41
+ } ;
42
+
43
+ return publicScope ;
44
+ } ( ) ) ;
45
+
46
+ module . exports = settingsCache ;
You can’t perform that action at this time.
0 commit comments