From 5dad0499325a37c9ab2505a94d43cc32057f28ec Mon Sep 17 00:00:00 2001 From: "Pawel Spychalski (DzikuVx)" Date: Sat, 2 Jul 2022 13:54:34 +0200 Subject: [PATCH 1/2] Basic Preset Framework --- gulpfile.js | 1 + js/presets.js | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 js/presets.js diff --git a/gulpfile.js b/gulpfile.js index 992ca9713..9b710e30d 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -77,6 +77,7 @@ sources.js = [ './js/helpers.js', './node_modules/inflection/inflection.min.js', './node_modules/bluebird/js/browser/bluebird.min.js', + './js/presets.js', './js/injected_methods.js', './js/intervals.js', './js/timeouts.js', diff --git a/js/presets.js b/js/presets.js new file mode 100644 index 000000000..4a217eaf1 --- /dev/null +++ b/js/presets.js @@ -0,0 +1,55 @@ +'use strict'; + +var helper = helper || {}; + +helper.presets = (function () { + + let publicScope = {}, + privateScope = {}; + + let data = [ + { + id: 1, + type: "filter", + name: "5\" Default", + settings: { + "gyro_hardware_lpf": "256HZ", + "gyro_anti_aliasing_lpf_hz": 250, + "gyro_anti_aliasing_lpf_type": "PT1", + "gyro_main_lpf_hz": 110, + "gyro_main_lpf_type": "PT1", + "dterm_lpf_hz": 110, + "dterm_lpf_type": "PT3", + "dterm_lpf2_hz": 0, + "dterm_lpf2_type": "PT1", + "dynamic_gyro_notch_enabled": "ON", + "dynamic_gyro_notch_q": 250, + "dynamic_gyro_notch_min_hz": 120, + "setpoint_kalman_enabled": "ON", + "setpoint_kalman_q": 200, + "smith_predictor_delay": 1.5 + } + } + ]; + + //Returns all presets by type + publicScope.getByType = function (type) { + return data.filter(function (preset) { + return preset.type === type; + }); + }; + + //Returns all presets + publicScope.getAll = function () { + return data; + }; + + //returns preset by id + publicScope.getById = function (id) { + return data.find(function (preset) { + return preset.id === id; + }); + }; + + return publicScope; +})(); \ No newline at end of file From 30fc01d79526cad0685a67ccb1005ddb07f70b5f Mon Sep 17 00:00:00 2001 From: "Pawel Spychalski (DzikuVx)" Date: Thu, 7 Jul 2022 14:56:24 +0200 Subject: [PATCH 2/2] some work --- _locales/en/messages.json | 3 ++ js/presets.js | 58 ++++++++++++++++++++++++++++++++++++++- tabs/pid_tuning.html | 24 +++++++++++++++- tabs/pid_tuning.js | 38 +++++++++++++++++++++++++ 4 files changed, 121 insertions(+), 2 deletions(-) diff --git a/_locales/en/messages.json b/_locales/en/messages.json index a0663a96e..e7d04b5f5 100755 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -4298,5 +4298,8 @@ }, "showAdvancedPIDs": { "message": "Show advanced PID controllers" + }, + "filterPresets": { + "message": "Filter presets" } } diff --git a/js/presets.js b/js/presets.js index 4a217eaf1..4792c1a81 100644 --- a/js/presets.js +++ b/js/presets.js @@ -11,7 +11,9 @@ helper.presets = (function () { { id: 1, type: "filter", - name: "5\" Default", + name: "Multirotor 5\" Default", + description: "INAV default filter preset. Works great with 5\" multirotors and similar. Might be suboptimal for light builds and bigger quaads.", + author: "DzikuVx", settings: { "gyro_hardware_lpf": "256HZ", "gyro_anti_aliasing_lpf_hz": 250, @@ -29,6 +31,30 @@ helper.presets = (function () { "setpoint_kalman_q": 200, "smith_predictor_delay": 1.5 } + }, + { + id: 2, + type: "filter", + name: "Multirotor 7\" Freestyle", + description: "Works great on 7\" multirotors and similar. Might be suboptimal for light builds and smaller quaads.", + author: "DzikuVx", + settings: { + "gyro_hardware_lpf": "256HZ", + "gyro_anti_aliasing_lpf_hz": 500, + "gyro_anti_aliasing_lpf_type": "PT1", + "gyro_main_lpf_hz": 90, + "gyro_main_lpf_type": "PT1", + "dterm_lpf_hz": 85, + "dterm_lpf_type": "PT3", + "dterm_lpf2_hz": 0, + "dterm_lpf2_type": "PT1", + "dynamic_gyro_notch_enabled": "ON", + "dynamic_gyro_notch_q": 250, + "dynamic_gyro_notch_min_hz": 70, + "setpoint_kalman_enabled": "ON", + "setpoint_kalman_q": 200, + "smith_predictor_delay": 1.5 + } } ]; @@ -51,5 +77,35 @@ helper.presets = (function () { }); }; + publicScope.apply = function (id, callback) { + let preset = publicScope.getById(id); + + if (preset) { + + let settings = Object.keys(preset.settings) + .map(function(s) { + return { + key: s, + value: preset.settings[s] + } + }); + + Promise.mapSeries(settings, function (input, ii) { + return mspHelper.getSetting(input.key); + }).then(function () { + + Promise.mapSeries(settings, function (input, ii) { + return mspHelper.setSetting(input.key, input.value); + }).then(function () { + if (callback && typeof callback === "function") { + callback(); + } + }); + + }); + } + + } + return publicScope; })(); \ No newline at end of file diff --git a/tabs/pid_tuning.html b/tabs/pid_tuning.html index eb2dd329a..be618f23f 100644 --- a/tabs/pid_tuning.html +++ b/tabs/pid_tuning.html @@ -342,7 +342,13 @@

-
+
+ +
+ +
+ +
@@ -562,6 +568,22 @@

+ + +
diff --git a/tabs/pid_tuning.js b/tabs/pid_tuning.js index 486090eb3..b5fcf6487 100644 --- a/tabs/pid_tuning.js +++ b/tabs/pid_tuning.js @@ -9,6 +9,8 @@ TABS.pid_tuning.initialize = function (callback) { var loadChainer = new MSPChainerClass(); + let filterPresetWizard; + var loadChain = [ mspHelper.loadPidNames, mspHelper.loadPidData, @@ -239,6 +241,40 @@ TABS.pid_tuning.initialize = function (callback) { $('.rpy_d').prop('disabled', 'disabled'); } + let $wizardButton = $('#filter-presets'); + + /* + * generate all the presets in the wizard + */ + let $presetContent = $('#filterPresetContent .filterPresetContent_wrapper'); + let presets = helper.presets.getByType('filter'); + + for (let i = 0; i < presets.length; i++) { + let preset = presets[i]; + + let html = "
" + + "
" + preset.name + "
" + + "
" + preset.description + "
" + + "
"; + + $presetContent.append(html); + // console.log(preset); + } + + filterPresetWizard = new jBox('Modal', { + width: 480, + height: 410, + closeButton: 'title', + animation: false, + attach: $wizardButton, + title: chrome.i18n.getMessage("mixerWizardModalTitle"), + content: $('#filterPresetContent') + }); + + $('#filter-presets').on('click', function (event) { + event.preventDefault(); + }); + GUI.simpleBind(); // UI Hooks @@ -295,6 +331,8 @@ TABS.pid_tuning.initialize = function (callback) { }; TABS.pid_tuning.cleanup = function (callback) { + delete filterPresetWizard; + $('.jBox-wrapper').remove(); if (callback) { callback(); }