diff --git a/js/configurator_main.js b/js/configurator_main.js index ce2e56345..4ca94c2d6 100644 --- a/js/configurator_main.js +++ b/js/configurator_main.js @@ -24,6 +24,7 @@ const update = require('./globalUpdates'); const appUpdater = require('./appUpdater'); const CliAutoComplete = require('./CliAutoComplete'); const { SITLProcess } = require('./sitl'); +const settingsCache = require('./settingsCache'); process.on('uncaughtException', function (error) { if (process.env.NODE_ENV !== 'development') { @@ -385,6 +386,9 @@ $(function() { $('#demoModeReset').on('click', function () { SITLProcess.deleteEepromFile('demo.bin'); }); + $('#maintenanceFlushSettingsCache').on('click', function () { + settingsCache.flush(); + }); function close_and_cleanup(e) { if (e.type == 'click' && !$.contains($('div#options-window')[0], e.target) || e.type == 'keyup' && e.keyCode == 27) { $(document).unbind('click keyup', close_and_cleanup); diff --git a/js/fc.js b/js/fc.js index 9f56d5a31..0d5d4861b 100644 --- a/js/fc.js +++ b/js/fc.js @@ -78,7 +78,6 @@ var FC = { MIXER_CONFIG: null, BATTERY_CONFIG: null, OUTPUT_MAPPING: null, - SETTINGS: null, BRAKING_CONFIG: null, SAFEHOMES: null, BOARD_ALIGNMENT: null, @@ -570,8 +569,6 @@ var FC = { this.OUTPUT_MAPPING = new OutputMappingCollection(); - this.SETTINGS = {}; - this.SAFEHOMES = new SafehomeCollection(); this.RATE_DYNAMICS = { diff --git a/js/msp/MSPHelper.js b/js/msp/MSPHelper.js index 3e0c66067..0c672b25b 100644 --- a/js/msp/MSPHelper.js +++ b/js/msp/MSPHelper.js @@ -20,6 +20,7 @@ const { FwApproach } = require('./../fwApproach'); const Waypoint = require('./../waypoint'); const mspDeduplicationQueue = require('./mspDeduplicationQueue'); const mspStatistics = require('./mspStatistics'); +const settingsCache = require('./../settingsCache'); var mspHelper = (function () { var self = {}; @@ -3060,9 +3061,12 @@ var mspHelper = (function () { }; self._getSetting = function (name) { - if (FC.SETTINGS[name]) { - return Promise.resolve(FC.SETTINGS[name]); + + const storedSetting = settingsCache.get(name); + if (typeof storedSetting !== 'undefined') { + return Promise.resolve(storedSetting); } + var data = []; self._encodeSettingReference(name, null, data); return MSP.promise(MSPCodes.MSP2_COMMON_SETTING_INFO, data).then(function (result) { @@ -3109,7 +3113,7 @@ var mspHelper = (function () { } setting.table = { values: values }; } - FC.SETTINGS[name] = setting; + settingsCache.set(name, setting); return setting; }); } diff --git a/js/settingsCache.js b/js/settingsCache.js new file mode 100644 index 000000000..6698cea7e --- /dev/null +++ b/js/settingsCache.js @@ -0,0 +1,47 @@ +'use strict'; + +const Store = require('electron-store'); +const store = new Store(); +const FC = require('./fc'); + +var settingsCache = (function() { + + let publicScope = {}; + let privateScope = {}; + + const SETTINGS_KEY = 'settings'; + + privateScope.getSetingKey = function(settingName) { + return FC.CONFIG.target + '_' + FC.CONFIG.flightControllerVersion + '_' + settingName; + } + + publicScope.flush = function() { + store.delete(SETTINGS_KEY); + console.log('Settings cache flushed'); + }; + + publicScope.get = function(settingName) { + let settings = store.get(SETTINGS_KEY, null); + + if (settings === null) { + return undefined; + } + let setting = settings[privateScope.getSetingKey(settingName)]; + return setting; + }; + + publicScope.set = function(settingName, value) { + let settings = store.get(SETTINGS_KEY, null); + + if (settings === null) { + settings = {}; + } + + settings[privateScope.getSetingKey(settingName)] = value; + store.set(SETTINGS_KEY, settings); + }; + + return publicScope; +}()); + +module.exports = settingsCache; \ No newline at end of file diff --git a/locale/en/messages.json b/locale/en/messages.json index 3af2e7f3e..bd3ff5756 100644 --- a/locale/en/messages.json +++ b/locale/en/messages.json @@ -5812,5 +5812,11 @@ }, "gsTelemetrySpeed": { "message": "Speed" + }, + "maintenance": { + "message": "Maintenance" + }, + "maintenanceFlushSettingsCache": { + "message": "Flush settings cache" } } diff --git a/tabs/options.html b/tabs/options.html index 303aa0103..7c21b29d2 100644 --- a/tabs/options.html +++ b/tabs/options.html @@ -87,5 +87,15 @@ +
+
+
+
+
+
+ +
+
+
\ No newline at end of file